Skip to content

Commit

Permalink
improve variable naming and toast messages
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoMac1 committed Oct 18, 2024
1 parent 424d24e commit 1344237
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const en = {
numa: 'NUMA',
ollamaConnectionError: "Couldn't connect to Ollama. Is the [server running](/settings)?",
ollamaLibrary: "Ollama's library",
openaiSyncFailed: 'Failed to connect to OpenAI. Check your API key or network connection',
openaiSyncSuccessful: 'Sync was successful. OpenAI models are now available in Sessions',
otherModels: 'Other models',
penalizeNewline: 'Penalize newline',
presencePenalty: 'Presence penalty',
Expand Down
16 changes: 16 additions & 0 deletions src/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ type RootTranslation = {
* O​l​l​a​m​a​'​s​ ​l​i​b​r​a​r​y
*/
ollamaLibrary: string
/**
* F​a​i​l​e​d​ ​t​o​ ​c​o​n​n​e​c​t​ ​t​o​ ​O​p​e​n​A​I​.​ ​C​h​e​c​k​ ​y​o​u​r​ ​A​P​I​ ​k​e​y​ ​o​r​ ​n​e​t​w​o​r​k​ ​c​o​n​n​e​c​t​i​o​n
*/
openaiSyncFailed: string
/**
* S​y​n​c​ ​w​a​s​ ​s​u​c​c​e​s​s​f​u​l​.​ ​O​p​e​n​A​I​ ​m​o​d​e​l​s​ ​a​r​e​ ​n​o​w​ ​a​v​a​i​l​a​b​l​e​ ​i​n​ ​S​e​s​s​i​o​n​s
*/
openaiSyncSuccessful: string
/**
* O​t​h​e​r​ ​m​o​d​e​l​s
*/
Expand Down Expand Up @@ -931,6 +939,14 @@ The completion in progress will stop
* Ollama's library
*/
ollamaLibrary: () => LocalizedString
/**
* Failed to connect to OpenAI. Check your API key or network connection
*/
openaiSyncFailed: () => LocalizedString
/**
* Sync was successful. OpenAI models are now available in Sessions
*/
openaiSyncSuccessful: () => LocalizedString
/**
* Other models
*/
Expand Down
18 changes: 9 additions & 9 deletions src/routes/settings/OpenAI.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
let openai = new OpenAIStrategy();
let openaiServer = $settingsStore.openaiServer || DEFAULT_OPENAI_SERVER;
let openaiApiKey = $settingsStore.openaiApiKey || '';
let openaiServerStatus: 'connected' | 'disconnected' | 'connecting' = 'disconnected';
let openaiServerStatus: 'success' | 'error' | 'loading';
$: settingsStore.update((settings) => ({ ...settings, openaiServer, openaiApiKey }));
async function getModelsList(): Promise<void> {
openaiServerStatus = 'connecting';
openaiServerStatus = 'loading';
const toastId = toast.loading($LL.connecting());
try {
await openai.getModels();
openaiServerStatus = 'connected';
toast.success($LL.connected(), { id: toastId });
openaiServerStatus = 'success';
toast.success($LL.openaiSyncSuccessful(), { id: toastId });
} catch {
openaiServerStatus = 'disconnected';
toast.error($LL.disconnected(), { id: toastId });
openaiServerStatus = 'error';
toast.error($LL.openaiSyncFailed(), { id: toastId });
}
}
Expand Down Expand Up @@ -60,16 +60,16 @@
variant="outline"
aria-label={$LL.connect()}
class="h-full text-muted"
isLoading={openaiServerStatus === 'connecting'}
disabled={openaiServerStatus === 'connecting' || !openaiServer || !openaiApiKey}
isLoading={openaiServerStatus === 'loading'}
disabled={openaiServerStatus === 'loading' || !openaiServer || !openaiApiKey}
on:click={updateOpenAIConfig}
>
<RefreshCw class="base-icon" />
</Button>
</svelte:fragment>

<svelte:fragment slot="help">
{#if openaiApiKey === 'ollama' || openaiServerStatus === 'disconnected'}
{#if openaiApiKey === 'ollama' || openaiServerStatus === 'error'}
<FieldHelp>
<P>
<Button
Expand Down

0 comments on commit 1344237

Please sign in to comment.