forked from Blendman974/faceclaw
Add a model picker and support for the OpenAI API
This commit is contained in:
1 parent
1c2e445519
commit
ccdeedd687
13 files changed
+688
-131
No files matched your search
@@ -0,0 +1,88 @@
|
||||
export const ASSISTANT_MODEL_VALUES = [
|
||||
"auto",
|
||||
"hauku",
|
||||
"sonnet",
|
||||
"opus",
|
||||
"fable",
|
||||
"luna",
|
||||
"terra",
|
||||
"sol",
|
||||
] as const;
|
||||
|
||||
export type AssistantModel = (typeof ASSISTANT_MODEL_VALUES)[number];
|
||||
export type AssistantProvider = "anthropic" | "openai";
|
||||
|
||||
export type AssistantApiKeys = {
|
||||
anthropic: string;
|
||||
openai: string;
|
||||
};
|
||||
|
||||
export type ResolvedAssistantModel = {
|
||||
selection: AssistantModel;
|
||||
provider: AssistantProvider;
|
||||
model: string;
|
||||
apiKey: string;
|
||||
effort?: "low" | "medium" | "high";
|
||||
};
|
||||
|
||||
type ModelDefinition = {
|
||||
label: string;
|
||||
provider: AssistantProvider;
|
||||
model: string;
|
||||
effort?: "low" | "medium" | "high";
|
||||
};
|
||||
|
||||
const MODEL_DEFINITIONS: Record<Exclude<AssistantModel, "auto">, ModelDefinition> = {
|
||||
// Keep the user-facing spelling requested for the picker while using
|
||||
// Anthropic's canonical Haiku alias on the wire.
|
||||
hauku: { label: "Hauku", provider: "anthropic", model: "claude-haiku-4-5" },
|
||||
sonnet: { label: "Sonnet", provider: "anthropic", model: "claude-sonnet-5", effort: "low" },
|
||||
opus: { label: "Opus", provider: "anthropic", model: "claude-opus-5", effort: "low" },
|
||||
fable: { label: "Fable", provider: "anthropic", model: "claude-fable-5", effort: "low" },
|
||||
luna: { label: "Luna", provider: "openai", model: "gpt-5.6-luna", effort: "low" },
|
||||
terra: { label: "Terra", provider: "openai", model: "gpt-5.6-terra", effort: "low" },
|
||||
sol: { label: "Sol", provider: "openai", model: "gpt-5.6-sol", effort: "low" },
|
||||
};
|
||||
|
||||
export function assistantModelLabel(value: AssistantModel): string {
|
||||
return value === "auto" ? "Auto" : MODEL_DEFINITIONS[value].label;
|
||||
}
|
||||
|
||||
export function assistantModelProvider(value: AssistantModel): AssistantProvider | null {
|
||||
return value === "auto" ? null : MODEL_DEFINITIONS[value].provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve Auto and attach the credential needed by the chosen provider.
|
||||
* Auto intentionally prefers Terra over Sonnet when both keys are available.
|
||||
*/
|
||||
export function resolveAssistantModel(
|
||||
selection: AssistantModel,
|
||||
keys: AssistantApiKeys,
|
||||
): ResolvedAssistantModel | null {
|
||||
const normalizedKeys: AssistantApiKeys = {
|
||||
anthropic: keys.anthropic.trim(),
|
||||
openai: keys.openai.trim(),
|
||||
};
|
||||
let resolvedSelection = selection;
|
||||
if (selection === "auto") {
|
||||
if (normalizedKeys.openai) {
|
||||
resolvedSelection = "terra";
|
||||
} else if (normalizedKeys.anthropic) {
|
||||
resolvedSelection = "sonnet";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const definition = MODEL_DEFINITIONS[resolvedSelection as Exclude<AssistantModel, "auto">];
|
||||
const apiKey = normalizedKeys[definition.provider];
|
||||
if (!apiKey) return null;
|
||||
return {
|
||||
selection,
|
||||
provider: definition.provider,
|
||||
model: definition.model,
|
||||
apiKey,
|
||||
effort: definition.effort,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user