diff --git a/backend/apps/web/routers/chats.py b/backend/apps/web/routers/chats.py index 798972e7c..d5e63c0f1 100644 --- a/backend/apps/web/routers/chats.py +++ b/backend/apps/web/routers/chats.py @@ -159,3 +159,23 @@ async def delete_chat_by_id(id: str, cred=Depends(bearer_scheme)): status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.INVALID_TOKEN, ) + + +############################ +# DeleteAllChats +############################ + + +@router.delete("/", response_model=bool) +async def delete_all_user_chats(cred=Depends(bearer_scheme)): + token = cred.credentials + user = Users.get_user_by_token(token) + + if user: + result = Chats.delete_chats_by_user_id(user.id) + return result + else: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail=ERROR_MESSAGES.INVALID_TOKEN, + ) diff --git a/src/lib/apis/chats/index.ts b/src/lib/apis/chats/index.ts index 354e4f74d..0eddf5b4a 100644 --- a/src/lib/apis/chats/index.ts +++ b/src/lib/apis/chats/index.ts @@ -191,3 +191,35 @@ export const deleteChatById = async (token: string, id: string) => { return res; }; + +export const deleteAllChats = async (token: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/chats/`, { + method: 'DELETE', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .then((json) => { + return json; + }) + .catch((err) => { + error = err; + + console.log(err); + return null; + }); + + if (error) { + throw error; + } + + return res; +}; diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 5dd57c781..1a9c3314e 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -8,7 +8,7 @@ import { splitStream, getGravatarURL } from '$lib/utils'; import { getOllamaVersion } from '$lib/apis/ollama'; - import { createNewChat, getAllChats, getChatList } from '$lib/apis/chats'; + import { createNewChat, deleteAllChats, getAllChats, getChatList } from '$lib/apis/chats'; import { WEB_UI_VERSION, OLLAMA_API_BASE_URL, @@ -19,6 +19,7 @@ import Advanced from './Settings/Advanced.svelte'; import Modal from '../common/Modal.svelte'; import { updateUserPassword } from '$lib/apis/auths'; + import { goto } from '$app/navigation'; export let show = false; @@ -83,7 +84,7 @@ // Chats let importFiles; - let showDeleteHistoryConfirm = false; + let showDeleteConfirm = false; const importChats = async (_chats) => { for (const chat of _chats) { @@ -114,6 +115,12 @@ reader.readAsText(importFiles[0]); } + const deleteChats = async () => { + await goto('/'); + await deleteAllChats(localStorage.token); + await chats.set(await getChatList(localStorage.token)); + }; + // Auth let authEnabled = false; let authType = 'Basic'; @@ -1618,147 +1625,154 @@ {:else if selectedTab === 'chats'}
-
- - - -
- + {:else} + + {/if} +
{:else if selectedTab === 'auth'}