forked from EduCraft/curriculum-project-hub
fix(hub): default to OpenRouter Sonnet model
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { InMemoryModelRegistry } from "./models.js";
|
||||
|
||||
type Env = Readonly<Record<string, string | undefined>>;
|
||||
|
||||
const DEFAULT_SONNET_MODEL = "anthropic/claude-sonnet-5";
|
||||
const DEFAULT_SONNET_LABEL = "Claude Sonnet 5";
|
||||
|
||||
function readEnv(env: Env, name: string): string | undefined {
|
||||
const value = env[name]?.trim();
|
||||
return value === undefined || value === "" ? undefined : value;
|
||||
}
|
||||
|
||||
export function defaultSonnetModel(env: Env = process.env): string {
|
||||
return readEnv(env, "ANTHROPIC_DEFAULT_SONNET_MODEL") ?? DEFAULT_SONNET_MODEL;
|
||||
}
|
||||
|
||||
export function createDefaultModelRegistry(env: Env = process.env): InMemoryModelRegistry {
|
||||
const sonnetModel = defaultSonnetModel(env);
|
||||
const sonnetLabel =
|
||||
readEnv(env, "ANTHROPIC_DEFAULT_SONNET_MODEL_NAME") ??
|
||||
(sonnetModel === DEFAULT_SONNET_MODEL ? DEFAULT_SONNET_LABEL : sonnetModel);
|
||||
|
||||
return new InMemoryModelRegistry(
|
||||
[
|
||||
{ id: sonnetModel, label: sonnetLabel, toolCapable: true },
|
||||
],
|
||||
[
|
||||
{ id: "draft", label: "草稿", defaultModel: sonnetModel },
|
||||
{ id: "review", label: "审校", defaultModel: sonnetModel },
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user