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 @@ }} >
- {#if prompt.title} + {#if prompt.title && prompt.title[0] !== ''}
{prompt.title[0]}
{prompt.title[1]}
{:else} diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index bd80cd59..36ac2a62 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -34,6 +34,8 @@ updateOpenAIUrl } from '$lib/apis/openai'; import { resetVectorDB } from '$lib/apis/rag'; + import { setDefaultPromptSuggestions } from '$lib/apis/configs'; + import { getBackendConfig } from '$lib/apis'; export let show = false; @@ -99,6 +101,9 @@ let OPENAI_API_KEY = ''; let OPENAI_API_BASE_URL = ''; + // Interface + let promptSuggestions = []; + // Addons let titleAutoGenerate = true; let speechAutoSend = false; @@ -191,6 +196,11 @@ await models.set(await getModels()); }; + const updateInterfaceHandler = async () => { + promptSuggestions = await setDefaultPromptSuggestions(localStorage.token, promptSuggestions); + await config.set(await getBackendConfig()); + }; + const toggleTheme = async () => { if (theme === 'dark') { theme = 'light'; @@ -577,6 +587,7 @@ API_BASE_URL = await getOllamaAPIUrl(localStorage.token); OPENAI_API_BASE_URL = await getOpenAIUrl(localStorage.token); OPENAI_API_KEY = await getOpenAIKey(localStorage.token); + promptSuggestions = $config?.default_prompt_suggestions; } let settings = JSON.parse(localStorage.getItem('settings') ?? '{}'); @@ -745,6 +756,32 @@
External
+ + {/if} - {#if !$config || ($config && !$config.auth)} - - {/if} - -
+
{#if selectedTab === 'general'}
@@ -1048,7 +1057,7 @@
{:else if selectedTab === 'advanced'}
-
+
Parameters
@@ -1483,6 +1492,103 @@
+
+ +
+ + {:else if selectedTab === 'interface'} +
{ + updateInterfaceHandler(); + show = false; + }} + > +
+
+
Default Prompt Suggestions
+ + +
+
+ {#each promptSuggestions as prompt, promptIdx} +
+
+
+ + + +
+ + +
+ + +
+ {/each} +
+ + {#if promptSuggestions.length > 0} +
+ Adjusting these settings will apply changes universally to all users. +
+ {/if} +
+