refactor: simplify model selection in config initialization
This commit is contained in:
parent
7578e0ed2a
commit
8cb1191fde
1 changed files with 5 additions and 7 deletions
|
|
@ -24,13 +24,11 @@ export async function initConfig(old: AppConfig | null): Promise<AppConfig> {
|
|||
const models = await getModels(baseURL);
|
||||
const model = await autocomplete({
|
||||
message: "Choose a default model:",
|
||||
initialValue: old?.model ?? models[0]?.value,
|
||||
placeholder: old?.model ?? models[0]?.value,
|
||||
options: models,
|
||||
initialValue: models.includes(old?.model ?? "") ? old?.model : models[0],
|
||||
placeholder: models.includes(old?.model ?? "") ? old?.model : models[0],
|
||||
options: models.map((model) => ({ value: model })),
|
||||
validate: (value) =>
|
||||
models
|
||||
.map((model) => model.value)
|
||||
.includes(typeof value === "string" ? value : "")
|
||||
models.includes(typeof value === "string" ? value : "")
|
||||
? undefined
|
||||
: `Unable to find model "${value}"`,
|
||||
});
|
||||
|
|
@ -57,7 +55,7 @@ type Models = {
|
|||
async function getModels(url: string) {
|
||||
const response = await fetch(`${url}/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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue