feat: convo tagging full integration

This commit is contained in:
Timothy J. Baek 2024-01-18 02:10:07 -08:00
parent d5ed119687
commit 987685dbf9
5 changed files with 185 additions and 119 deletions

View file

@ -10,7 +10,15 @@
import { copyToClipboard, splitStream, convertMessagesToHistory } from '$lib/utils';
import { generateChatCompletion, generateTitle } from '$lib/apis/ollama';
import { createNewChat, getChatById, getChatList, updateChatById } from '$lib/apis/chats';
import {
addTagById,
createNewChat,
deleteTagById,
getChatById,
getChatList,
getTagsById,
updateChatById
} from '$lib/apis/chats';
import { queryVectorDB } from '$lib/apis/rag';
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
@ -49,6 +57,7 @@
}, {});
let chat = null;
let tags = [];
let title = '';
let prompt = '';
@ -97,6 +106,7 @@
});
if (chat) {
tags = await getTags();
const chatContent = chat.chat;
if (chatContent) {
@ -688,6 +698,22 @@
await chats.set(await getChatList(localStorage.token));
};
const getTags = async () => {
return await getTagsById(localStorage.token, $chatId).catch(async (error) => {
return [];
});
};
const addTag = async (tagName) => {
const res = await addTagById(localStorage.token, $chatId, tagName);
tags = await getTags();
};
const deleteTag = async (tagName) => {
const res = await deleteTagById(localStorage.token, $chatId, tagName);
tags = await getTags();
};
onMount(async () => {
if (!($settings.saveChatHistory ?? true)) {
await goto('/');
@ -713,6 +739,9 @@
goto('/');
}}
{tags}
{addTag}
{deleteTag}
/>
<div class="min-h-screen w-full flex justify-center">
<div class=" py-2.5 flex flex-col justify-between w-full">