This commit is contained in:
Timothy Jaeryang Baek 2025-01-05 00:44:38 -08:00
parent 2444327a47
commit fe59b7f39c
4 changed files with 41 additions and 34 deletions

View File

@ -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]) @router.post("/{id}/clone/shared", response_model=Optional[ChatResponse])
async def clone_chat_by_share_id(share_id: str, user=Depends(get_verified_user)): async def clone_shared_chat_by_id(id: str, user=Depends(get_verified_user)):
chat = Chats.get_chat_by_share_id(share_id) chat = Chats.get_chat_by_share_id(id)
if chat: if chat:
updated_chat = { updated_chat = {
**chat.chat, **chat.chat,
@ -487,7 +487,6 @@ async def clone_chat_by_share_id(share_id: str, user=Depends(get_verified_user))
) )
############################ ############################
# ArchiveChat # ArchiveChat
############################ ############################

View File

@ -618,10 +618,10 @@ export const cloneChatById = async (token: string, id: string) => {
return res; return res;
}; };
export const cloneChatByShareId = async (token: string, share_id: string) => { export const cloneSharedChatById = async (token: string, id: string) => {
let error = null; 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', method: 'POST',
headers: { headers: {
Accept: 'application/json', Accept: 'application/json',

View File

@ -16,6 +16,8 @@
const i18n = getContext('i18n'); const i18n = getContext('i18n');
export let className = 'h-full flex pt-8';
export let chatId = ''; export let chatId = '';
export let user = $_user; export let user = $_user;
@ -333,7 +335,7 @@
}; };
</script> </script>
<div class="h-full flex pt-8"> <div class={className}>
{#if Object.keys(history?.messages ?? {}).length == 0} {#if Object.keys(history?.messages ?? {}).length == 0}
<ChatPlaceholder <ChatPlaceholder
modelIds={selectedModels} modelIds={selectedModels}

View File

@ -8,12 +8,12 @@
import { settings, chatId, WEBUI_NAME, models } from '$lib/stores'; import { settings, chatId, WEBUI_NAME, models } from '$lib/stores';
import { convertMessagesToHistory, createMessagesList } from '$lib/utils'; import { convertMessagesToHistory, createMessagesList } from '$lib/utils';
import { getChatByShareId, cloneChatByShareId } from '$lib/apis/chats'; import { getChatByShareId, cloneSharedChatById } from '$lib/apis/chats';
import Messages from '$lib/components/chat/Messages.svelte'; import Messages from '$lib/components/chat/Messages.svelte';
import Navbar from '$lib/components/layout/Navbar.svelte'; import Navbar from '$lib/components/layout/Navbar.svelte';
import { getUserById } from '$lib/apis/users'; import { getUserById } from '$lib/apis/users';
import { error } from '@sveltejs/kit';
import { getModels } from '$lib/apis'; import { getModels } from '$lib/apis';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
@ -104,8 +104,8 @@
const cloneSharedChat = async () => { const cloneSharedChat = async () => {
if (!chat) return; 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); toast.error(error);
return null; return null;
}); });
@ -128,33 +128,26 @@
<div <div
class="min-h-screen max-h-screen w-full flex flex-col text-gray-700 dark:text-gray-100 bg-white dark:bg-gray-900" class="min-h-screen max-h-screen w-full flex flex-col text-gray-700 dark:text-gray-100 bg-white dark:bg-gray-900"
> >
<div class="flex flex-col flex-auto justify-center py-8"> <div class="flex flex-col flex-auto justify-center relative">
<div class="px-3 w-full max-w-5xl mx-auto"> <div class=" flex flex-col w-full flex-auto overflow-auto h-0" id="messages-container">
<div> <div class="pt-5 px-2 w-full max-w-5xl mx-auto">
<div class=" text-3xl font-semibold line-clamp-1"> <div class="px-3">
{title} <div class=" text-2xl font-semibold line-clamp-1">
</div> {title}
</div>
<div class="flex justify-between items-center mt-1">
<div class="text-gray-400"> <div class="flex text-sm justify-between items-center mt-1">
{dayjs(chat.chat.timestamp).format($i18n.t('MMMM DD, YYYY'))} <div class="text-gray-400">
{dayjs(chat.chat.timestamp).format($i18n.t('MMMM DD, YYYY'))}
</div>
</div> </div>
<button
class="px-4 py-2 text-sm font-medium bg-emerald-600 hover:bg-emerald-500 text-white rounded-xl transition"
on:click={cloneSharedChat}
>
{$i18n.t('Clone in OpenWebUI')}
</button>
</div> </div>
</div> </div>
<hr class="border-gray-50 dark:border-gray-850 mt-6 mb-2" /> <div class=" h-full w-full flex flex-col py-2">
</div> <div class="">
<div class=" flex flex-col w-full flex-auto overflow-auto h-0" id="messages-container">
<div class=" h-full w-full flex flex-col py-4">
<div class="py-2">
<Messages <Messages
className="h-full flex pt-4 pb-8"
{user} {user}
chatId={$chatId} chatId={$chatId}
readOnly={true} readOnly={true}
@ -171,6 +164,19 @@
</div> </div>
</div> </div>
</div> </div>
<div
class="absolute bottom-0 right-0 left-0 flex justify-center w-full bg-gradient-to-b from-transparent to-gray-900"
>
<div class="pb-5">
<button
class="px-4 py-2 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
on:click={cloneSharedChat}
>
{$i18n.t('Clone Chat')}
</button>
</div>
</div>
</div> </div>
</div> </div>
{/if} {/if}