Merge pull request #675 from HenryHolloway/ollama-webui-full-search

feat: full-context search
This commit is contained in:
Timothy Jaeryang Baek 2024-02-07 17:06:58 -08:00 committed by GitHub
commit 9fccf72bfc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,6 +11,7 @@
import { import {
deleteChatById, deleteChatById,
getChatList, getChatList,
getChatById,
getChatListByTagName, getChatListByTagName,
updateChatById updateChatById
} from '$lib/apis/chats'; } from '$lib/apis/chats';
@ -31,15 +32,23 @@
if (window.innerWidth > 1280) { if (window.innerWidth > 1280) {
show = true; show = true;
} }
await chats.set(await getChatList(localStorage.token)); await chats.set(await getChatList(localStorage.token));
});
tags.subscribe(async (value) => { // Helper function to fetch and add chat content to each chat
if (value.length === 0) { const enrichChatsWithContent = async (chatList) => {
await chats.set(await getChatList(localStorage.token)); const enrichedChats = await Promise.all(
chatList.map(async (chat) => {
const chatDetails = await getChatById(localStorage.token, chat.id).catch((error) => null); // Handle error or non-existent chat gracefully
if (chatDetails) {
chat.chat = chatDetails.chat; // Assuming chatDetails.chat contains the chat content
} }
}); return chat;
}); })
);
await chats.set(enrichedChats);
};
const loadChat = async (id) => { const loadChat = async (id) => {
goto(`/c/${id}`); goto(`/c/${id}`);
@ -271,6 +280,9 @@
class="w-full rounded-r py-1.5 pl-2.5 pr-4 text-sm text-gray-300 bg-gray-950 outline-none" class="w-full rounded-r py-1.5 pl-2.5 pr-4 text-sm text-gray-300 bg-gray-950 outline-none"
placeholder="Search" placeholder="Search"
bind:value={search} bind:value={search}
on:focus={() => {
enrichChatsWithContent($chats);
}}
/> />
<!-- <div class="self-center pr-3 py-2 bg-gray-900"> <!-- <div class="self-center pr-3 py-2 bg-gray-900">
@ -323,11 +335,16 @@
let title = chat.title.toLowerCase(); let title = chat.title.toLowerCase();
const query = search.toLowerCase(); const query = search.toLowerCase();
if (title.includes(query)) { let contentMatches = false;
return true; // Access the messages within chat.chat.messages
} else { if (chat.chat && chat.chat.messages && Array.isArray(chat.chat.messages)) {
return false; contentMatches = chat.chat.messages.some((message) => {
// Check if message.content exists and includes the search query
return message.content && message.content.toLowerCase().includes(query);
});
} }
return title.includes(query) || contentMatches;
} }
}) as chat, i} }) as chat, i}
<div class=" w-full pr-2 relative"> <div class=" w-full pr-2 relative">