From fe59b7f39cc07ea002f4d63dd476243fc1211edf Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 5 Jan 2025 00:44:38 -0800 Subject: [PATCH] refac --- backend/open_webui/routers/chats.py | 9 ++-- src/lib/apis/chats/index.ts | 4 +- src/lib/components/chat/Messages.svelte | 4 +- src/routes/s/[id]/+page.svelte | 58 ++++++++++++++----------- 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/backend/open_webui/routers/chats.py b/backend/open_webui/routers/chats.py index 67d7fbb3a..a001dd01f 100644 --- a/backend/open_webui/routers/chats.py +++ b/backend/open_webui/routers/chats.py @@ -464,13 +464,13 @@ async def clone_chat_by_id(id: str, user=Depends(get_verified_user)): ############################ -# CloneChatByShareId +# CloneSharedChatById ############################ -@router.post("/{share_id}/clone_shared", response_model=Optional[ChatResponse]) -async def clone_chat_by_share_id(share_id: str, user=Depends(get_verified_user)): - chat = Chats.get_chat_by_share_id(share_id) +@router.post("/{id}/clone/shared", response_model=Optional[ChatResponse]) +async def clone_shared_chat_by_id(id: str, user=Depends(get_verified_user)): + chat = Chats.get_chat_by_share_id(id) if chat: updated_chat = { **chat.chat, @@ -487,7 +487,6 @@ async def clone_chat_by_share_id(share_id: str, user=Depends(get_verified_user)) ) - ############################ # ArchiveChat ############################ diff --git a/src/lib/apis/chats/index.ts b/src/lib/apis/chats/index.ts index d2d7e64ac..1772529d3 100644 --- a/src/lib/apis/chats/index.ts +++ b/src/lib/apis/chats/index.ts @@ -618,10 +618,10 @@ export const cloneChatById = async (token: string, id: string) => { return res; }; -export const cloneChatByShareId = async (token: string, share_id: string) => { +export const cloneSharedChatById = async (token: string, id: string) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${share_id}/clone_shared`, { + const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/clone/shared`, { method: 'POST', headers: { Accept: 'application/json', diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 2b0748dc7..7f18f3a35 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -16,6 +16,8 @@ const i18n = getContext('i18n'); + export let className = 'h-full flex pt-8'; + export let chatId = ''; export let user = $_user; @@ -333,7 +335,7 @@ }; -
+
{#if Object.keys(history?.messages ?? {}).length == 0} { if (!chat) return; - - const res = await cloneChatByShareId(localStorage.token, chat.id).catch((error) => { + + const res = await cloneSharedChatById(localStorage.token, chat.id).catch((error) => { toast.error(error); return null; }); @@ -128,33 +128,26 @@
-
-
-
-
- {title} -
- -
-
- {dayjs(chat.chat.timestamp).format($i18n.t('MMMM DD, YYYY'))} +
+ - -