refactor: simplify model selection in config initialization

This commit is contained in:
mitchell 2026-05-11 19:42:32 -04:00
parent 7578e0ed2a
commit 8cb1191fde

View file

@ -24,13 +24,11 @@ export async function initConfig(old: AppConfig | null): Promise<AppConfig> {
const models = await getModels(baseURL); const models = await getModels(baseURL);
const model = await autocomplete({ const model = await autocomplete({
message: "Choose a default model:", message: "Choose a default model:",
initialValue: old?.model ?? models[0]?.value, initialValue: models.includes(old?.model ?? "") ? old?.model : models[0],
placeholder: old?.model ?? models[0]?.value, placeholder: models.includes(old?.model ?? "") ? old?.model : models[0],
options: models, options: models.map((model) => ({ value: model })),
validate: (value) => validate: (value) =>
models models.includes(typeof value === "string" ? value : "")
.map((model) => model.value)
.includes(typeof value === "string" ? value : "")
? undefined ? undefined
: `Unable to find model "${value}"`, : `Unable to find model "${value}"`,
}); });
@ -57,7 +55,7 @@ type Models = {
async function getModels(url: string) { async function getModels(url: string) {
const response = await fetch(`${url}/models`); const response = await fetch(`${url}/models`);
const models = (await response.json()) as Models; const models = (await response.json()) as Models;
return models.data.map((model) => ({ value: model.id })); return models.data.map((model) => model.id);
} }
export async function loadConfig( export async function loadConfig(