diff --git a/backend/apps/rag/main.py b/backend/apps/rag/main.py index 1c84241e..e55ee8ed 100644 --- a/backend/apps/rag/main.py +++ b/backend/apps/rag/main.py @@ -190,7 +190,7 @@ def reset_vector_db(user=Depends(get_current_user)): @app.get("/reset") -def reset(user=Depends(get_current_user)): +def reset(user=Depends(get_current_user)) -> bool: if user.role == "admin": folder = f"{UPLOAD_DIR}" for filename in os.listdir(folder): @@ -208,7 +208,7 @@ def reset(user=Depends(get_current_user)): except Exception as e: print(e) - return {"status": True} + return True else: raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, diff --git a/src/lib/apis/rag/index.ts b/src/lib/apis/rag/index.ts index bafd0360..8a2b8cb4 100644 --- a/src/lib/apis/rag/index.ts +++ b/src/lib/apis/rag/index.ts @@ -103,3 +103,29 @@ export const queryVectorDB = async ( return res; }; + +export const resetVectorDB = async (token: string) => { + let error = null; + + const res = await fetch(`${RAG_API_BASE_URL}/reset`, { + method: 'GET', + headers: { + Accept: 'application/json', + authorization: `Bearer ${token}` + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .catch((err) => { + error = err.detail; + 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 976b6115..03a02532 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -31,6 +31,7 @@ updateOpenAIKey, updateOpenAIUrl } from '$lib/apis/openai'; + import { resetVectorDB } from '$lib/apis/rag'; export let show = false; @@ -1829,6 +1830,40 @@
Delete All Chats
{/if} + + {#if $user?.role === 'admin'} +
+ + + {/if} {:else if selectedTab === 'auth'}