feat: show 2 latest versions per family (opus/sonnet/haiku) in model refresh
This commit is contained in:
+12
-5
@@ -84,7 +84,10 @@ export class ClaudeClient {
|
|||||||
return response.json.content?.[0]?.text ?? "";
|
return response.json.content?.[0]?.text ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fetch the 3 newest Claude models from the Anthropic Models API. */
|
/**
|
||||||
|
* Fetch Claude models from the Anthropic Models API.
|
||||||
|
* Returns the 2 newest versions of each family (opus, sonnet, haiku), in that order.
|
||||||
|
*/
|
||||||
async fetchModels(apiKey: string): Promise<{ id: string; name: string }[]> {
|
async fetchModels(apiKey: string): Promise<{ id: string; name: string }[]> {
|
||||||
const response = await requestUrl({
|
const response = await requestUrl({
|
||||||
url: "https://api.anthropic.com/v1/models",
|
url: "https://api.anthropic.com/v1/models",
|
||||||
@@ -102,9 +105,13 @@ export class ClaudeClient {
|
|||||||
throw new Error("No models returned");
|
throw new Error("No models returned");
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
const sorted = data.sort((a, b) => b.created - a.created);
|
||||||
.sort((a, b) => b.created - a.created)
|
const families = ["opus", "sonnet", "haiku"] as const;
|
||||||
.slice(0, 3)
|
return families.flatMap((family) =>
|
||||||
.map((m) => ({ id: m.id, name: m.id }));
|
sorted
|
||||||
|
.filter((m) => m.id.includes(family))
|
||||||
|
.slice(0, 2)
|
||||||
|
.map((m) => ({ id: m.id, name: m.id }))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user