Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
b37b1576
Commit
b37b1576
authored
Jan 07, 2024
by
Timothy J. Baek
Browse files
feat: reset vectordb storage support
parent
d4b2578f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
2 deletions
+63
-2
backend/apps/rag/main.py
backend/apps/rag/main.py
+2
-2
src/lib/apis/rag/index.ts
src/lib/apis/rag/index.ts
+26
-0
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+35
-0
No files found.
backend/apps/rag/main.py
View file @
b37b1576
...
@@ -190,7 +190,7 @@ def reset_vector_db(user=Depends(get_current_user)):
...
@@ -190,7 +190,7 @@ def reset_vector_db(user=Depends(get_current_user)):
@
app
.
get
(
"/reset"
)
@
app
.
get
(
"/reset"
)
def
reset
(
user
=
Depends
(
get_current_user
)):
def
reset
(
user
=
Depends
(
get_current_user
))
->
bool
:
if
user
.
role
==
"admin"
:
if
user
.
role
==
"admin"
:
folder
=
f
"
{
UPLOAD_DIR
}
"
folder
=
f
"
{
UPLOAD_DIR
}
"
for
filename
in
os
.
listdir
(
folder
):
for
filename
in
os
.
listdir
(
folder
):
...
@@ -208,7 +208,7 @@ def reset(user=Depends(get_current_user)):
...
@@ -208,7 +208,7 @@ def reset(user=Depends(get_current_user)):
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
print
(
e
)
return
{
"status"
:
True
}
return
True
else
:
else
:
raise
HTTPException
(
raise
HTTPException
(
status_code
=
status
.
HTTP_403_FORBIDDEN
,
status_code
=
status
.
HTTP_403_FORBIDDEN
,
...
...
src/lib/apis/rag/index.ts
View file @
b37b1576
...
@@ -103,3 +103,29 @@ export const queryVectorDB = async (
...
@@ -103,3 +103,29 @@ export const queryVectorDB = async (
return
res
;
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
;
};
src/lib/components/chat/SettingsModal.svelte
View file @
b37b1576
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
updateOpenAIKey,
updateOpenAIKey,
updateOpenAIUrl
updateOpenAIUrl
} from '$lib/apis/openai';
} from '$lib/apis/openai';
import { resetVectorDB } from '$lib/apis/rag';
export let show = false;
export let show = false;
...
@@ -1829,6 +1830,40 @@
...
@@ -1829,6 +1830,40 @@
<div class=" self-center text-sm font-medium">Delete All Chats</div>
<div class=" self-center text-sm font-medium">Delete All Chats</div>
</button>
</button>
{/if}
{/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>
</div>
</div>
{:else if selectedTab === 'auth'}
{:else if selectedTab === 'auth'}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment