From afcab78cabebaeeb59524c10fbd6cec7ded56cd1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 25 May 2024 13:48:45 -0700 Subject: [PATCH] fix: models --- backend/apps/web/routers/models.py | 6 +++--- src/lib/apis/models/index.ts | 15 ++++++++++++--- src/lib/components/chat/Settings/General.svelte | 2 +- .../(app)/workspace/models/create/+page.svelte | 2 +- .../(app)/workspace/models/edit/+page.svelte | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/backend/apps/web/routers/models.py b/backend/apps/web/routers/models.py index 654d0d2fb..81140c861 100644 --- a/backend/apps/web/routers/models.py +++ b/backend/apps/web/routers/models.py @@ -53,7 +53,7 @@ async def add_new_model( ############################ -@router.get("/{id}", response_model=Optional[ModelModel]) +@router.get("/", response_model=Optional[ModelModel]) async def get_model_by_id(id: str, user=Depends(get_verified_user)): model = Models.get_model_by_id(id) @@ -71,7 +71,7 @@ async def get_model_by_id(id: str, user=Depends(get_verified_user)): ############################ -@router.post("/{id}/update", response_model=Optional[ModelModel]) +@router.post("/update", response_model=Optional[ModelModel]) async def update_model_by_id( request: Request, id: str, form_data: ModelForm, user=Depends(get_admin_user) ): @@ -102,7 +102,7 @@ async def update_model_by_id( ############################ -@router.delete("/{id}/delete", response_model=bool) +@router.delete("/delete", response_model=bool) async def delete_model_by_id(id: str, user=Depends(get_admin_user)): result = Models.delete_model_by_id(id) return result diff --git a/src/lib/apis/models/index.ts b/src/lib/apis/models/index.ts index 092926583..73b9d619a 100644 --- a/src/lib/apis/models/index.ts +++ b/src/lib/apis/models/index.ts @@ -63,7 +63,10 @@ export const getModelInfos = async (token: string = '') => { export const getModelById = async (token: string, id: string) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/models/${id}`, { + const url = new URL(`${WEBUI_API_BASE_URL}/models`); + url.searchParams.append('id', id); + + const res = await fetch(url.toString(), { method: 'GET', headers: { Accept: 'application/json', @@ -95,7 +98,10 @@ export const getModelById = async (token: string, id: string) => { export const updateModelById = async (token: string, id: string, model: object) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/models/${id}/update`, { + const url = new URL(`${WEBUI_API_BASE_URL}/models/update`); + url.searchParams.append('id', id); + + const res = await fetch(url.toString(), { method: 'POST', headers: { Accept: 'application/json', @@ -128,7 +134,10 @@ export const updateModelById = async (token: string, id: string, model: object) export const deleteModelById = async (token: string, id: string) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/models/${id}/delete`, { + const url = new URL(`${WEBUI_API_BASE_URL}/models/delete`); + url.searchParams.append('id', id); + + const res = await fetch(url.toString(), { method: 'DELETE', headers: { Accept: 'application/json', diff --git a/src/lib/components/chat/Settings/General.svelte b/src/lib/components/chat/Settings/General.svelte index ae08e5234..c20c9465b 100644 --- a/src/lib/components/chat/Settings/General.svelte +++ b/src/lib/components/chat/Settings/General.svelte @@ -302,7 +302,7 @@ system: system !== '' ? system : undefined, params: { seed: (params.seed !== 0 ? params.seed : undefined) ?? undefined, - stop: params.stop !== null ? params.stop.split(',').filter((e) => e) : undefined, + stop: params.stop ? params.stop.split(',').filter((e) => e) : undefined, temperature: params.temperature !== '' ? params.temperature : undefined, frequency_penalty: params.frequency_penalty !== '' ? params.frequency_penalty : undefined, diff --git a/src/routes/(app)/workspace/models/create/+page.svelte b/src/routes/(app)/workspace/models/create/+page.svelte index 95bb5d5b3..1db35f4e8 100644 --- a/src/routes/(app)/workspace/models/create/+page.svelte +++ b/src/routes/(app)/workspace/models/create/+page.svelte @@ -62,7 +62,7 @@ info.id = id; info.name = name; info.meta.capabilities = capabilities; - info.params.stop = params.stop !== null ? params.stop.split(',').filter((s) => s.trim()) : null; + info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null; if ($models.find((m) => m.id === info.id)) { toast.error( diff --git a/src/routes/(app)/workspace/models/edit/+page.svelte b/src/routes/(app)/workspace/models/edit/+page.svelte index bd751bdcb..21e0f6e41 100644 --- a/src/routes/(app)/workspace/models/edit/+page.svelte +++ b/src/routes/(app)/workspace/models/edit/+page.svelte @@ -63,7 +63,7 @@ info.id = id; info.name = name; info.meta.capabilities = capabilities; - info.params.stop = params.stop !== null ? params.stop.split(',').filter((s) => s.trim()) : null; + info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null; const res = await updateModelById(localStorage.token, info.id, info);