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
0495f01a
Commit
0495f01a
authored
Jun 03, 2024
by
Timothy J. Baek
Browse files
feat: reset upload dir
parent
b673ae7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
229 additions
and
73 deletions
+229
-73
backend/apps/rag/main.py
backend/apps/rag/main.py
+24
-0
src/lib/apis/rag/index.ts
src/lib/apis/rag/index.ts
+26
-0
src/lib/components/documents/Settings/General.svelte
src/lib/components/documents/Settings/General.svelte
+179
-73
No files found.
backend/apps/rag/main.py
View file @
0495f01a
...
@@ -1164,6 +1164,30 @@ def reset_vector_db(user=Depends(get_admin_user)):
...
@@ -1164,6 +1164,30 @@ def reset_vector_db(user=Depends(get_admin_user)):
CHROMA_CLIENT
.
reset
()
CHROMA_CLIENT
.
reset
()
@
app
.
get
(
"/reset/uploads"
)
def
reset_upload_dir
(
user
=
Depends
(
get_admin_user
))
->
bool
:
folder
=
f
"
{
UPLOAD_DIR
}
"
try
:
# Check if the directory exists
if
os
.
path
.
exists
(
folder
):
# Iterate over all the files and directories in the specified directory
for
filename
in
os
.
listdir
(
folder
):
file_path
=
os
.
path
.
join
(
folder
,
filename
)
try
:
if
os
.
path
.
isfile
(
file_path
)
or
os
.
path
.
islink
(
file_path
):
os
.
unlink
(
file_path
)
# Remove the file or link
elif
os
.
path
.
isdir
(
file_path
):
shutil
.
rmtree
(
file_path
)
# Remove the directory
except
Exception
as
e
:
print
(
f
"Failed to delete
{
file_path
}
. Reason:
{
e
}
"
)
else
:
print
(
f
"The directory
{
folder
}
does not exist"
)
except
Exception
as
e
:
print
(
f
"Failed to process the directory
{
folder
}
. Reason:
{
e
}
"
)
return
True
@
app
.
get
(
"/reset"
)
@
app
.
get
(
"/reset"
)
def
reset
(
user
=
Depends
(
get_admin_user
))
->
bool
:
def
reset
(
user
=
Depends
(
get_admin_user
))
->
bool
:
folder
=
f
"
{
UPLOAD_DIR
}
"
folder
=
f
"
{
UPLOAD_DIR
}
"
...
...
src/lib/apis/rag/index.ts
View file @
0495f01a
...
@@ -359,6 +359,32 @@ export const scanDocs = async (token: string) => {
...
@@ -359,6 +359,32 @@ export const scanDocs = async (token: string) => {
return
res
;
return
res
;
};
};
export
const
resetUploadDir
=
async
(
token
:
string
)
=>
{
let
error
=
null
;
const
res
=
await
fetch
(
`
${
RAG_API_BASE_URL
}
/reset/uploads`
,
{
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
;
};
export
const
resetVectorDB
=
async
(
token
:
string
)
=>
{
export
const
resetVectorDB
=
async
(
token
:
string
)
=>
{
let
error
=
null
;
let
error
=
null
;
...
...
src/lib/components/documents/Settings/General.svelte
View file @
0495f01a
...
@@ -8,7 +8,8 @@
...
@@ -8,7 +8,8 @@
getEmbeddingConfig,
getEmbeddingConfig,
updateEmbeddingConfig,
updateEmbeddingConfig,
getRerankingConfig,
getRerankingConfig,
updateRerankingConfig
updateRerankingConfig,
resetUploadDir
} from '$lib/apis/rag';
} from '$lib/apis/rag';
import { documents, models } from '$lib/stores';
import { documents, models } from '$lib/stores';
...
@@ -24,6 +25,7 @@
...
@@ -24,6 +25,7 @@
let updateRerankingModelLoading = false;
let updateRerankingModelLoading = false;
let showResetConfirm = false;
let showResetConfirm = false;
let showResetUploadDirConfirm = false;
let embeddingEngine = '';
let embeddingEngine = '';
let embeddingModel = '';
let embeddingModel = '';
...
@@ -496,99 +498,203 @@
...
@@ -496,99 +498,203 @@
{/if}
{/if}
</div>
</div>
<hr class=" dark:border-gray-
70
0" />
<hr class=" dark:border-gray-
85
0" />
{#if showResetConfirm}
<div>
<div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
{#if showResetUploadDirConfirm}
<div class="flex items-center space-x-3">
<div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
<svg
<div class="flex items-center space-x-3">
xmlns="http://www.w3.org/2000/svg"
<svg
viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
viewBox="0 0 24 24"
class="w-4 h-4"
fill="currentColor"
>
class="size-4"
<path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
>
<path
<path
fill-rule="evenodd"
fill-rule="evenodd"
d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM5.72 7.47a.75.75 0 0 1 1.06 0L8 8.69l1.22-1.22a.75.75 0 1 1 1.06 1.06L9.06 9.75l1.22 1.22a.75.75 0 1 1-1.06 1.06L8 10.81l-1.22 1.22a.75.75 0 0 1-1.06-1.06l1.22-1.22-1.22-1.22a.75.75 0 0 1 0-1.06Z"
d="M5.625 1.5H9a3.75 3.75 0 0 1 3.75 3.75v1.875c0 1.036.84 1.875 1.875 1.875H16.5a3.75 3.75 0 0 1 3.75 3.75v7.875c0 1.035-.84 1.875-1.875 1.875H5.625a1.875 1.875 0 0 1-1.875-1.875V3.375c0-1.036.84-1.875 1.875-1.875ZM9.75 14.25a.75.75 0 0 0 0 1.5H15a.75.75 0 0 0 0-1.5H9.75Z"
clip-rule="evenodd"
clip-rule="evenodd"
/>
/>
</svg>
<path
<span>{$i18n.t('Are you sure?')}</span>
d="M14.25 5.25a5.23 5.23 0 0 0-1.279-3.434 9.768 9.768 0 0 1 6.963 6.963A5.23 5.23 0 0 0 16.5 7.5h-1.875a.375.375 0 0 1-.375-.375V5.25Z"
</div>
/>
</svg>
<span>{$i18n.t('Are you sure?')}</span>
</div>
<div class="flex space-x-1.5 items-center">
<div class="flex space-x-1.5 items-center">
<button
<button
class="hover:text-white transition"
class="hover:text-white transition"
on:click={() => {
on:click={() => {
const res = resetVectorDB(localStorage.token).catch((error) => {
const res = resetUploadDir(localStorage.token).catch((error) => {
toast.error(error);
toast.error(error);
return null;
return null;
});
});
if (res) {
toast.success($i18n.t('Success'));
}
showResetConfirm = false;
if (res) {
}}
toast.success($i18n.t('Success'));
>
}
showResetUploadDirConfirm = false;
}}
type="button"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
clip-rule="evenodd"
/>
</svg>
</button>
<button
class="hover:text-white transition"
type="button"
on:click={() => {
showResetUploadDirConfirm = false;
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
/>
</svg>
</button>
</div>
</div>
{:else}
<button
class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
on:click={() => {
showResetUploadDirConfirm = true;
}}
type="button"
>
<div class=" self-center mr-3">
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 2
0
2
0
"
viewBox="0 0 2
4
2
4
"
fill="currentColor"
fill="currentColor"
class="
w-4 h
-4"
class="
size
-4"
>
>
<path
<path
fill-rule="evenodd"
fill-rule="evenodd"
d="M
16.704 4.153a
.75.75 0 0
1.143 1.052l-8 10
.5a.75.75 0 0
1-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z
"
d="M
5.625 1.5H9a3
.75
3
.75 0 0
1 3.75 3.75v1.875c0 1.036.84 1.875 1.875 1.875H16
.5a
3
.75
3
.75 0 0
1 3.75 3.75v7.875c0 1.035-.84 1.875-1.875 1.875H5.625a1.875 1.875 0 0 1-1.875-1.875V3.375c0-1.036.84-1.875 1.875-1.875ZM9.75 14.25a.75.75 0 0 0 0 1.5H15a.75.75 0 0 0 0-1.5H9.75Z
"
clip-rule="evenodd"
clip-rule="evenodd"
/>
/>
<path
d="M14.25 5.25a5.23 5.23 0 0 0-1.279-3.434 9.768 9.768 0 0 1 6.963 6.963A5.23 5.23 0 0 0 16.5 7.5h-1.875a.375.375 0 0 1-.375-.375V5.25Z"
/>
</svg>
</svg>
</button>
</div>
<button
<div class=" self-center text-sm font-medium">{$i18n.t('Reset Upload Directory')}</div>
class="hover:text-white transition"
</button>
on:click={() => {
{/if}
showResetConfirm = false;
}}
{#if showResetConfirm}
>
<div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
<div class="flex items-center space-x-3">
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0
20 20
"
viewBox="0 0
16 16
"
fill="currentColor"
fill="currentColor"
class="w-4 h-4"
class="w-4 h-4"
>
>
<path
<path
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
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>
</svg>
</button>
<span>{$i18n.t('Are you sure?')}</span>
</div>
</div>
</div>
{:else}
<div class="flex space-x-1.5 items-center">
<button
<button
class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
class="hover:text-white transition"
on:click={() => {
on:click={() => {
showResetConfirm = true;
const res = resetVectorDB(localStorage.token).catch((error) => {
}}
toast.error(error);
>
return null;
<div class=" self-center mr-3">
});
<svg
xmlns="http://www.w3.org/2000/svg"
if (res) {
viewBox="0 0 16 16"
toast.success($i18n.t('Success'));
fill="currentColor"
}
class="w-4 h-4"
>
showResetConfirm = false;
<path
}}
fill-rule="evenodd"
type="button"
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
/>
xmlns="http://www.w3.org/2000/svg"
</svg>
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
clip-rule="evenodd"
/>
</svg>
</button>
<button
class="hover:text-white transition"
on:click={() => {
showResetConfirm = false;
}}
type="button"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
/>
</svg>
</button>
</div>
</div>
</div>
<div class=" self-center text-sm font-medium">{$i18n.t('Reset Vector Storage')}</div>
{:else}
</button>
<button
{/if}
class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
on:click={() => {
showResetConfirm = true;
}}
type="button"
>
<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">{$i18n.t('Reset Vector Storage')}</div>
</button>
{/if}
</div>
</div>
</div>
<div class="flex justify-end pt-3 text-sm font-medium">
<div class="flex justify-end pt-3 text-sm font-medium">
<button
<button
...
...
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