diff --git a/backend/open_webui/apps/webui/models/models.py b/backend/open_webui/apps/webui/models/models.py index 52ed8fe43..99e33efbf 100644 --- a/backend/open_webui/apps/webui/models/models.py +++ b/backend/open_webui/apps/webui/models/models.py @@ -257,5 +257,15 @@ class ModelsTable: except Exception: return False + def delete_all_models(self) -> bool: + try: + with get_db() as db: + db.query(Model).delete() + db.commit() + + return True + except Exception: + return False + Models = ModelsTable() diff --git a/backend/open_webui/apps/webui/routers/models.py b/backend/open_webui/apps/webui/routers/models.py index ad5221cf8..576df8d94 100644 --- a/backend/open_webui/apps/webui/routers/models.py +++ b/backend/open_webui/apps/webui/routers/models.py @@ -180,3 +180,9 @@ async def delete_model_by_id(id: str, user=Depends(get_verified_user)): result = Models.delete_model_by_id(id) return result + + +@router.delete("/delete/all", response_model=bool) +async def delete_all_models(user=Depends(get_admin_user)): + result = Models.delete_all_models() + return result diff --git a/src/lib/apis/models/index.ts b/src/lib/apis/models/index.ts index 4aaf651c6..bfd3903fe 100644 --- a/src/lib/apis/models/index.ts +++ b/src/lib/apis/models/index.ts @@ -231,3 +231,36 @@ export const deleteModelById = async (token: string, id: string) => { return res; }; + + +export const deleteAllModels = async (token: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/models/delete/all`, { + method: 'DELETE', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + 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; +}; \ No newline at end of file diff --git a/src/lib/components/admin/Settings/Models.svelte b/src/lib/components/admin/Settings/Models.svelte index 1b6b9b9d0..18acc1967 100644 --- a/src/lib/components/admin/Settings/Models.svelte +++ b/src/lib/components/admin/Settings/Models.svelte @@ -9,6 +9,7 @@ import { WEBUI_NAME, config, mobile, models as _models, settings, user } from '$lib/stores'; import { createNewModel, + deleteAllModels, getBaseModels, toggleModelById, updateModelById @@ -22,6 +23,7 @@ import ModelEditor from '$lib/components/workspace/Models/ModelEditor.svelte'; import { toast } from 'svelte-sonner'; + import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte'; let importFiles; let modelsImportInputElement: HTMLInputElement; @@ -32,8 +34,8 @@ let baseModels = null; let filteredModels = []; - let selectedModelId = null; + let showResetModal = false; $: if (models) { filteredModels = models.filter( @@ -126,6 +128,19 @@ }); + { + const res = deleteAllModels(localStorage.token); + if (res) { + toast.success($i18n.t('All models deleted successfully')); + init(); + } + }} +/> + {#if models !== null} {#if selectedModelId === null}
@@ -137,6 +152,22 @@ >{filteredModels.length}
+ +
+ + + +
diff --git a/src/lib/components/common/ConfirmDialog.svelte b/src/lib/components/common/ConfirmDialog.svelte index af4dbd3e8..658174c05 100644 --- a/src/lib/components/common/ConfirmDialog.svelte +++ b/src/lib/components/common/ConfirmDialog.svelte @@ -12,6 +12,8 @@ export let cancelLabel = $i18n.t('Cancel'); export let confirmLabel = $i18n.t('Confirm'); + export let onConfirm = () => {}; + export let input = false; export let inputPlaceholder = ''; export let inputValue = ''; @@ -29,11 +31,17 @@ if (event.key === 'Enter') { console.log('Enter'); - show = false; - dispatch('confirm', inputValue); + confirmHandler(); } }; + const confirmHandler = async () => { + show = false; + + await onConfirm(); + dispatch('confirm', inputValue); + }; + onMount(() => { mounted = true; }); @@ -110,8 +118,7 @@