From b7fc37d9926918816c8c5775d4b8f0a36225229b Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 26 May 2024 15:21:08 -0700 Subject: [PATCH] fix: spinner --- .../chat/Settings/Connections.svelte | 382 +++++++++--------- 1 file changed, 200 insertions(+), 182 deletions(-) diff --git a/src/lib/components/chat/Settings/Connections.svelte b/src/lib/components/chat/Settings/Connections.svelte index b9978e129..d5f49f4cf 100644 --- a/src/lib/components/chat/Settings/Connections.svelte +++ b/src/lib/components/chat/Settings/Connections.svelte @@ -20,6 +20,7 @@ } from '$lib/apis/openai'; import { toast } from 'svelte-sonner'; import Switch from '$lib/components/common/Switch.svelte'; + import Spinner from '$lib/components/common/Spinner.svelte'; const i18n = getContext('i18n'); @@ -31,8 +32,8 @@ let OPENAI_API_KEYS = ['']; let OPENAI_API_BASE_URLS = ['']; - let ENABLE_OPENAI_API = false; - let ENABLE_OLLAMA_API = false; + let ENABLE_OPENAI_API = null; + let ENABLE_OLLAMA_API = null; const updateOpenAIHandler = async () => { OPENAI_API_BASE_URLS = await updateOpenAIUrls(localStorage.token, OPENAI_API_BASE_URLS); @@ -57,16 +58,23 @@ onMount(async () => { if ($user.role === 'admin') { + await Promise.all([ + (async () => { + OLLAMA_BASE_URLS = await getOllamaUrls(localStorage.token); + })(), + (async () => { + OPENAI_API_BASE_URLS = await getOpenAIUrls(localStorage.token); + })(), + (async () => { + OPENAI_API_KEYS = await getOpenAIKeys(localStorage.token); + })() + ]); + const ollamaConfig = await getOllamaConfig(localStorage.token); const openaiConfig = await getOpenAIConfig(localStorage.token); ENABLE_OPENAI_API = openaiConfig.ENABLE_OPENAI_API; ENABLE_OLLAMA_API = ollamaConfig.ENABLE_OLLAMA_API; - - OLLAMA_BASE_URLS = await getOllamaUrls(localStorage.token); - - OPENAI_API_BASE_URLS = await getOpenAIUrls(localStorage.token); - OPENAI_API_KEYS = await getOpenAIKeys(localStorage.token); } }); @@ -79,201 +87,211 @@ }} >
-
-
+ {#if ENABLE_OPENAI_API !== null && ENABLE_OLLAMA_API !== null} +
+
+
+
{$i18n.t('OpenAI API')}
+ +
+ { + updateOpenAIConfig(localStorage.token, ENABLE_OPENAI_API); + }} + /> +
+
+ + {#if ENABLE_OPENAI_API} +
+ {#each OPENAI_API_BASE_URLS as url, idx} +
+
+ +
+ +
+ +
+
+ {#if idx === 0} + + {:else} + + {/if} +
+
+
+ {$i18n.t('WebUI will make requests to')} + '{url}/models' +
+ {/each} +
+ {/if} +
+
+ +
+ +
-
{$i18n.t('OpenAI API')}
+
{$i18n.t('Ollama API')}
{ - updateOpenAIConfig(localStorage.token, ENABLE_OPENAI_API); + updateOllamaConfig(localStorage.token, ENABLE_OLLAMA_API); }} />
- - {#if ENABLE_OPENAI_API} -
- {#each OPENAI_API_BASE_URLS as url, idx} -
-
+ {#if ENABLE_OLLAMA_API} +
+
+ {#each OLLAMA_BASE_URLS as url, idx} +
-
-
- + {#if idx === 0} + + {:else} + + {/if} +
+
+ {/each} +
+ +
+
-
- {#if idx === 0} - - {:else} - - {/if} -
-
-
- {$i18n.t('WebUI will make requests to')} - '{url}/models' -
- {/each} + + +
+
+ +
+ {$i18n.t('Trouble accessing Ollama?')} + + {$i18n.t('Click here for help.')} +
{/if}
-
- -
- -
-
-
{$i18n.t('Ollama API')}
- -
- { - updateOllamaConfig(localStorage.token, ENABLE_OLLAMA_API); - }} - /> + {:else} +
+
+
- {#if ENABLE_OLLAMA_API} -
-
- {#each OLLAMA_BASE_URLS as url, idx} -
- - -
- {#if idx === 0} - - {:else} - - {/if} -
-
- {/each} -
- -
- -
-
- -
- {$i18n.t('Trouble accessing Ollama?')} - - {$i18n.t('Click here for help.')} - -
- {/if} -
+ {/if}