feat: reset vectordb storage support

This commit is contained in:
Timothy J. Baek 2024-01-07 09:15:45 -08:00
parent d4b2578f6e
commit b37b157638
3 changed files with 63 additions and 2 deletions

View file

@ -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,

View file

@ -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;
};

View file

@ -31,6 +31,7 @@
updateOpenAIKey,
updateOpenAIUrl
} from '$lib/apis/openai';
import { resetVectorDB } from '$lib/apis/rag';
export let show = false;
@ -1829,6 +1830,40 @@
<div class=" self-center text-sm font-medium">Delete All Chats</div>
</button>
{/if}
{#if $user?.role === 'admin'}
<hr class=" dark:border-gray-700" />
<button
class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
on:click={() => {
const res = resetVectorDB(localStorage.token).catch((error) => {
toast.error(error);
return null;
});
if (res) {
toast.success('Success');
}
}}
>
<div class=" self-center mr-3">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M3.5 2A1.5 1.5 0 0 0 2 3.5v9A1.5 1.5 0 0 0 3.5 14h9a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 12.5 4H9.621a1.5 1.5 0 0 1-1.06-.44L7.439 2.44A1.5 1.5 0 0 0 6.38 2H3.5Zm6.75 7.75a.75.75 0 0 0 0-1.5h-4.5a.75.75 0 0 0 0 1.5h4.5Z"
clip-rule="evenodd"
/>
</svg>
</div>
<div class=" self-center text-sm font-medium">Reset Vector Storage</div>
</button>
{/if}
</div>
</div>
{:else if selectedTab === 'auth'}