Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit da8d6fa

Browse files
committed
pull model list from api to remain current
1 parent 437ef16 commit da8d6fa

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/lib/components/SettingsModal.svelte

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
showSettings,
66
DEFAULT_SYSTEM_MESSAGE,
77
db,
8+
getOpenAi,
9+
chatModels,
810
} from "$lib/stores/stores";
911
import { DB_NAME } from "$lib/constants";
1012
import AutosizeTextarea from "./AutosizeTextarea.svelte";
@@ -13,6 +15,7 @@
1315
import { ChatMessage, Thread } from "$lib/db";
1416
import { mapKeys, toCamelCase } from "$lib/utils";
1517
import CloseButton from "./CloseButton.svelte";
18+
import type OpenAI from "openai";
1619

1720
let schema;
1821
let migrationVersion;
@@ -21,6 +24,14 @@
2124
?.map((x) => x.sql)
2225
?.filter((x) => !x.includes("sqlite_") && !x.includes("crsql"));
2326
migrationVersion = (await $db?.execA<number[]>(`PRAGMA user_version`))?.[0];
27+
28+
if (!$chatModels.length) {
29+
const openai = getOpenAi();
30+
const xs = await openai.models.list();
31+
$chatModels = xs.data
32+
.filter((x) => x.id.startsWith("gpt"))
33+
.sort((a, b) => a.id.localeCompare(b.id));
34+
}
2435
});
2536
let showAdvanced = false;
2637
</script>
@@ -96,9 +107,9 @@
96107
<label for="a" class="label"> Model: </label>
97108
<div class:info={$gptProfileStore.model === "gpt-4"}>
98109
<select id="a" class="input rounded w-full" bind:value={$gptProfileStore.model}>
99-
<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>
100-
<option value="gpt-3.5-turbo-16k">gpt-3.5-turbo-16k</option>
101-
<option value="gpt-4">gpt-4</option>
110+
{#each $chatModels as model}
111+
<option value={model.id}>{model.id}</option>
112+
{/each}
102113
</select>
103114
{#if $gptProfileStore.model === "gpt-4"}
104115
<p>

src/lib/stores/stores.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,3 +856,5 @@ ChatMessage.onTableChange(() => {
856856
console.debug("%cmessage table changed", "color:salmon;");
857857
currentChatThread.invalidate();
858858
});
859+
860+
export const chatModels = writable<OpenAI.Model[]>([]);

0 commit comments

Comments
 (0)