From fc6dc43a19a50012984e9e564e3b612ce000588d Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 21 Oct 2024 01:30:22 -0700 Subject: [PATCH] refac: tagging behaviour --- backend/open_webui/apps/webui/routers/chats.py | 8 +++----- src/lib/components/chat/Chat.svelte | 11 ++++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/apps/webui/routers/chats.py b/backend/open_webui/apps/webui/routers/chats.py index a768cd2e2..b149b2eb4 100644 --- a/backend/open_webui/apps/webui/routers/chats.py +++ b/backend/open_webui/apps/webui/routers/chats.py @@ -644,12 +644,12 @@ async def delete_tag_by_id_and_tag_name( ############################ -# DeleteAllChatTagsById +# DeleteAllTagsById ############################ @router.delete("/{id}/tags/all", response_model=Optional[bool]) -async def delete_all_chat_tags_by_id(id: str, user=Depends(get_verified_user)): +async def delete_all_tags_by_id(id: str, user=Depends(get_verified_user)): chat = Chats.get_chat_by_id_and_user_id(id, user.id) if chat: Chats.delete_all_tags_by_id_and_user_id(id, user.id) @@ -658,9 +658,7 @@ async def delete_all_chat_tags_by_id(id: str, user=Depends(get_verified_user)): if Chats.count_chats_by_tag_name_and_user_id(tag, user.id) == 0: Tags.delete_tag_by_name_and_user_id(tag, user.id) - chat = Chats.get_chat_by_id_and_user_id(id, user.id) - tags = chat.meta.get("tags", []) - return Tags.get_tags_by_ids_and_user_id(tags, user.id) + return True else: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.NOT_FOUND diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 9a4b8d450..f6ddf2beb 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -49,6 +49,8 @@ import { addTagById, createNewChat, + deleteTagById, + deleteTagsById, getAllTags, getChatById, getChatList, @@ -1912,6 +1914,14 @@ const setChatTags = async (messages) => { if (!$temporaryChatEnabled) { + const currentTags = await getTagsById(localStorage.token, $chatId); + if (currentTags.length > 0) { + const res = await deleteTagsById(localStorage.token, $chatId); + if (res) { + allTags.set(await getAllTags(localStorage.token)); + } + } + let generatedTags = await generateTags( localStorage.token, selectedModels[0], @@ -1922,7 +1932,6 @@ return []; }); - const currentTags = await getTagsById(localStorage.token, $chatId); generatedTags = generatedTags.filter( (tag) => !currentTags.find((t) => t.id === tag.replaceAll(' ', '_').toLowerCase()) );