From 86999157ded7bd9a22bb416398b0c5e2026760a2 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 19 Oct 2024 21:04:56 -0700 Subject: [PATCH] refac: disable 'none' tag --- backend/open_webui/apps/webui/routers/chats.py | 6 ++++++ src/lib/apis/chats/index.ts | 3 +-- src/lib/components/chat/Tags.svelte | 10 +++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/apps/webui/routers/chats.py b/backend/open_webui/apps/webui/routers/chats.py index 515afdc51..2f81b55bd 100644 --- a/backend/open_webui/apps/webui/routers/chats.py +++ b/backend/open_webui/apps/webui/routers/chats.py @@ -586,6 +586,12 @@ async def add_tag_by_id_and_tag_name( tags = chat.meta.get("tags", []) tag_id = form_data.name.replace(" ", "_").lower() + if tag_id == "none": + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail=ERROR_MESSAGES.DEFAULT("Tag name cannot be 'None'"), + ) + print(tags, tag_id) if tag_id not in tags: Chats.add_chat_tag_by_id_and_user_id_and_tag_name( diff --git a/src/lib/apis/chats/index.ts b/src/lib/apis/chats/index.ts index a99ac67e7..ca3915e50 100644 --- a/src/lib/apis/chats/index.ts +++ b/src/lib/apis/chats/index.ts @@ -868,8 +868,7 @@ export const addTagById = async (token: string, id: string, tagName: string) => return json; }) .catch((err) => { - error = err; - + error = err.detail; console.log(err); return null; }); diff --git a/src/lib/components/chat/Tags.svelte b/src/lib/components/chat/Tags.svelte index f71ff0af9..2f716d5ff 100644 --- a/src/lib/components/chat/Tags.svelte +++ b/src/lib/components/chat/Tags.svelte @@ -20,6 +20,7 @@ const dispatch = createEventDispatcher(); import Tags from '../common/Tags.svelte'; + import { toast } from 'svelte-sonner'; export let chatId = ''; let tags = []; @@ -31,7 +32,14 @@ }; const addTag = async (tagName) => { - const res = await addTagById(localStorage.token, chatId, tagName); + const res = await addTagById(localStorage.token, chatId, tagName).catch(async (error) => { + toast.error(error); + return null; + }); + if (!res) { + return; + } + tags = await getTags(); await updateChatById(localStorage.token, chatId, { tags: tags