diff --git a/backend/apps/web/routers/configs.py b/backend/apps/web/routers/configs.py index 379ba9f0..376686e0 100644 --- a/backend/apps/web/routers/configs.py +++ b/backend/apps/web/routers/configs.py @@ -49,14 +49,15 @@ async def set_global_default_models( ) -@router.post("/default/suggestions", response_model=str) +@router.post("/default/suggestions", response_model=List[PromptSuggestion]) async def set_global_default_suggestions( request: Request, form_data: SetDefaultSuggestionsForm, user=Depends(get_current_user), ): if user.role == "admin": - request.app.state.DEFAULT_PROMPT_SUGGESTIONS = form_data.suggestions + data = form_data.model_dump() + request.app.state.DEFAULT_PROMPT_SUGGESTIONS = data["suggestions"] return request.app.state.DEFAULT_PROMPT_SUGGESTIONS else: raise HTTPException( diff --git a/src/lib/apis/configs/index.ts b/src/lib/apis/configs/index.ts index 76256f4d..30d562ba 100644 --- a/src/lib/apis/configs/index.ts +++ b/src/lib/apis/configs/index.ts @@ -29,3 +29,33 @@ export const setDefaultModels = async (token: string, models: string) => { return res; }; + +export const setDefaultPromptSuggestions = async (token: string, promptSuggestions: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/configs/default/suggestions`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + }, + body: JSON.stringify({ + suggestions: promptSuggestions + }) + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .catch((err) => { + console.log(err); + error = err.detail; + return null; + }); + + if (error) { + throw error; + } + + return res; +}; diff --git a/src/lib/components/chat/MessageInput/Suggestions.svelte b/src/lib/components/chat/MessageInput/Suggestions.svelte index f0d4b881..058e3825 100644 --- a/src/lib/components/chat/MessageInput/Suggestions.svelte +++ b/src/lib/components/chat/MessageInput/Suggestions.svelte @@ -13,7 +13,7 @@ }} >