diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index d10db74f8c..ca5bad0061 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -8,17 +8,26 @@ import { toast } from 'svelte-sonner'; export const getModels = async ( token: string = '', connections: object | null = null, - base: boolean = false + base: boolean = false, + refresh: boolean = false ) => { + const searchParams = new URLSearchParams(); + if (refresh) { + searchParams.append('refresh', 'true'); + } + let error = null; - const res = await fetch(`${WEBUI_BASE_URL}/api/models${base ? '/base' : ''}`, { - method: 'GET', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - ...(token && { authorization: `Bearer ${token}` }) + const res = await fetch( + `${WEBUI_BASE_URL}/api/models${base ? '/base' : ''}?${searchParams.toString()}`, + { + method: 'GET', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) + } } - }) + ) .then(async (res) => { if (!res.ok) throw await res.json(); return res.json(); diff --git a/src/lib/components/admin/Settings/Connections.svelte b/src/lib/components/admin/Settings/Connections.svelte index ac0566f225..df0b4f6809 100644 --- a/src/lib/components/admin/Settings/Connections.svelte +++ b/src/lib/components/admin/Settings/Connections.svelte @@ -25,7 +25,9 @@ const getModels = async () => { const models = await _getModels( localStorage.token, - $config?.features?.enable_direct_connections && ($settings?.directConnections ?? null) + $config?.features?.enable_direct_connections && ($settings?.directConnections ?? null), + false, + true ); return models; }; @@ -216,35 +218,102 @@
{#if ENABLE_OPENAI_API !== null && ENABLE_OLLAMA_API !== null && directConnectionsConfig !== null} -
-
-
-
{$i18n.t('OpenAI API')}
+
+
{$i18n.t('General')}
-
-
- { - updateOpenAIHandler(); - }} - /> +
+ +
+
+
+
{$i18n.t('OpenAI API')}
+ +
+
+ { + updateOpenAIHandler(); + }} + /> +
+ + {#if ENABLE_OPENAI_API} +
+
+
{$i18n.t('Manage OpenAI API Connections')}
+ + + + +
+ +
+ {#each OPENAI_API_BASE_URLS as url, idx} + { + updateOpenAIHandler(); + }} + onDelete={() => { + OPENAI_API_BASE_URLS = OPENAI_API_BASE_URLS.filter( + (url, urlIdx) => idx !== urlIdx + ); + OPENAI_API_KEYS = OPENAI_API_KEYS.filter((key, keyIdx) => idx !== keyIdx); + + let newConfig = {}; + OPENAI_API_BASE_URLS.forEach((url, newIdx) => { + newConfig[newIdx] = + OPENAI_API_CONFIGS[newIdx < idx ? newIdx : newIdx + 1]; + }); + OPENAI_API_CONFIGS = newConfig; + updateOpenAIHandler(); + }} + /> + {/each} +
+
+ {/if} +
+
+ +
+
+
{$i18n.t('Ollama API')}
+ +
+ { + updateOllamaHandler(); + }} + /> +
- {#if ENABLE_OPENAI_API} -
- + {#if ENABLE_OLLAMA_API}
-
{$i18n.t('Manage OpenAI API Connections')}
+
{$i18n.t('Manage Ollama API Connections')}
-
- {#each OPENAI_API_BASE_URLS as url, idx} - { - updateOpenAIHandler(); - }} - onDelete={() => { - OPENAI_API_BASE_URLS = OPENAI_API_BASE_URLS.filter( - (url, urlIdx) => idx !== urlIdx - ); - OPENAI_API_KEYS = OPENAI_API_KEYS.filter((key, keyIdx) => idx !== keyIdx); +
+
+ {#each OLLAMA_BASE_URLS as url, idx} + { + updateOllamaHandler(); + }} + onDelete={() => { + OLLAMA_BASE_URLS = OLLAMA_BASE_URLS.filter((url, urlIdx) => idx !== urlIdx); - let newConfig = {}; - OPENAI_API_BASE_URLS.forEach((url, newIdx) => { - newConfig[newIdx] = OPENAI_API_CONFIGS[newIdx < idx ? newIdx : newIdx + 1]; - }); - OPENAI_API_CONFIGS = newConfig; - updateOpenAIHandler(); - }} - /> - {/each} + let newConfig = {}; + OLLAMA_BASE_URLS.forEach((url, newIdx) => { + newConfig[newIdx] = + OLLAMA_API_CONFIGS[newIdx < idx ? newIdx : newIdx + 1]; + }); + OLLAMA_API_CONFIGS = newConfig; + }} + /> + {/each} +
+
+ +
+ {$i18n.t('Trouble accessing Ollama?')} + + {$i18n.t('Click here for help.')} +
{/if}
-
-
+
+
+
{$i18n.t('Direct Connections')}
-
-
-
{$i18n.t('Ollama API')}
- -
- { - updateOllamaHandler(); - }} - /> -
-
- - {#if ENABLE_OLLAMA_API} -
- -
-
-
{$i18n.t('Manage Ollama API Connections')}
- - - - -
- -
-
- {#each OLLAMA_BASE_URLS as url, idx} - { - updateOllamaHandler(); - }} - onDelete={() => { - OLLAMA_BASE_URLS = OLLAMA_BASE_URLS.filter((url, urlIdx) => idx !== urlIdx); - - let newConfig = {}; - OLLAMA_BASE_URLS.forEach((url, newIdx) => { - newConfig[newIdx] = OLLAMA_API_CONFIGS[newIdx < idx ? newIdx : newIdx + 1]; - }); - OLLAMA_API_CONFIGS = newConfig; - }} - /> - {/each} + />
- -
- {$i18n.t('Trouble accessing Ollama?')} - - {$i18n.t('Click here for help.')} - -
- {/if} -
-
- -
-
-
{$i18n.t('Direct Connections')}
- -
-
- { - updateDirectConnectionsHandler(); - }} - /> -
-
-
- -
-
+
{$i18n.t( 'Direct Connections allow users to connect to their own OpenAI compatible API endpoints.' )} diff --git a/src/lib/components/workspace/Prompts.svelte b/src/lib/components/workspace/Prompts.svelte index b1698b2866..6e57d15c33 100644 --- a/src/lib/components/workspace/Prompts.svelte +++ b/src/lib/components/workspace/Prompts.svelte @@ -378,6 +378,6 @@ {/if} {:else}
- +
{/if}