diff --git a/backend/apps/webui/routers/utils.py b/backend/apps/webui/routers/utils.py index b95fe8834..18491130a 100644 --- a/backend/apps/webui/routers/utils.py +++ b/backend/apps/webui/routers/utils.py @@ -107,3 +107,12 @@ async def download_db(user=Depends(get_admin_user)): media_type="application/octet-stream", filename="webui.db", ) + + +@router.get("/litellm/config") +async def download_litellm_config_yaml(user=Depends(get_admin_user)): + return FileResponse( + f"{DATA_DIR}/litellm/config.yaml", + media_type="application/octet-stream", + filename="config.yaml", + ) diff --git a/src/lib/apis/utils/index.ts b/src/lib/apis/utils/index.ts index 3f28d9444..acb4a04aa 100644 --- a/src/lib/apis/utils/index.ts +++ b/src/lib/apis/utils/index.ts @@ -108,3 +108,39 @@ export const downloadDatabase = async (token: string) => { throw error; } }; + +export const downloadLiteLLMConfig = async (token: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/utils/litellm/config`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } + }) + .then(async (response) => { + if (!response.ok) { + throw await response.json(); + } + return response.blob(); + }) + .then((blob) => { + const url = window.URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = 'config.yaml'; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + }) + .catch((err) => { + console.log(err); + error = err.detail; + return null; + }); + + if (error) { + throw error; + } +}; diff --git a/src/lib/components/admin/Settings/Database.svelte b/src/lib/components/admin/Settings/Database.svelte index 3ae01a668..9ce8e9d8d 100644 --- a/src/lib/components/admin/Settings/Database.svelte +++ b/src/lib/components/admin/Settings/Database.svelte @@ -2,7 +2,7 @@ import fileSaver from 'file-saver'; const { saveAs } = fileSaver; - import { downloadDatabase } from '$lib/apis/utils'; + import { downloadDatabase, downloadLiteLLMConfig } from '$lib/apis/utils'; import { onMount, getContext } from 'svelte'; import { config, user } from '$lib/stores'; import { toast } from 'svelte-sonner'; @@ -68,10 +68,8 @@ -