diff --git a/src/lib/components/SettingsModal.svelte b/src/lib/components/SettingsModal.svelte index 01c80de..b0a04b8 100644 --- a/src/lib/components/SettingsModal.svelte +++ b/src/lib/components/SettingsModal.svelte @@ -5,6 +5,8 @@ showSettings, DEFAULT_SYSTEM_MESSAGE, db, + getOpenAi, + chatModels, } from "$lib/stores/stores"; import { DB_NAME } from "$lib/constants"; import AutosizeTextarea from "./AutosizeTextarea.svelte"; @@ -13,6 +15,7 @@ import { ChatMessage, Thread } from "$lib/db"; import { mapKeys, toCamelCase } from "$lib/utils"; import CloseButton from "./CloseButton.svelte"; + import type OpenAI from "openai"; let schema; let migrationVersion; @@ -21,6 +24,14 @@ ?.map((x) => x.sql) ?.filter((x) => !x.includes("sqlite_") && !x.includes("crsql")); migrationVersion = (await $db?.execA(`PRAGMA user_version`))?.[0]; + + if (!$chatModels.length) { + const openai = getOpenAi(); + const xs = await openai.models.list(); + $chatModels = xs.data + .filter((x) => x.id.startsWith("gpt")) + .sort((a, b) => a.id.localeCompare(b.id)); + } }); let showAdvanced = false; @@ -96,9 +107,9 @@
{#if $gptProfileStore.model === "gpt-4"}

diff --git a/src/lib/stores/stores.ts b/src/lib/stores/stores.ts index c53e110..9f4a379 100644 --- a/src/lib/stores/stores.ts +++ b/src/lib/stores/stores.ts @@ -856,3 +856,5 @@ ChatMessage.onTableChange(() => { console.debug("%cmessage table changed", "color:salmon;"); currentChatThread.invalidate(); }); + +export const chatModels = writable([]);