Skip to content

Commit

Permalink
pull model list from api to remain current
Browse files Browse the repository at this point in the history
  • Loading branch information
iansinnott committed Aug 22, 2023
1 parent 437ef16 commit da8d6fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib/components/SettingsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -21,6 +24,14 @@
?.map((x) => x.sql)
?.filter((x) => !x.includes("sqlite_") && !x.includes("crsql"));
migrationVersion = (await $db?.execA<number[]>(`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;
</script>
Expand Down Expand Up @@ -96,9 +107,9 @@
<label for="a" class="label"> Model: </label>
<div class:info={$gptProfileStore.model === "gpt-4"}>
<select id="a" class="input rounded w-full" bind:value={$gptProfileStore.model}>
<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>
<option value="gpt-3.5-turbo-16k">gpt-3.5-turbo-16k</option>
<option value="gpt-4">gpt-4</option>
{#each $chatModels as model}
<option value={model.id}>{model.id}</option>
{/each}
</select>
{#if $gptProfileStore.model === "gpt-4"}
<p>
Expand Down
2 changes: 2 additions & 0 deletions src/lib/stores/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,5 @@ ChatMessage.onTableChange(() => {
console.debug("%cmessage table changed", "color:salmon;");
currentChatThread.invalidate();
});

export const chatModels = writable<OpenAI.Model[]>([]);

0 comments on commit da8d6fa

Please sign in to comment.