66 lines
3.2 KiB
TypeScript
66 lines
3.2 KiB
TypeScript
export const REASONING_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
|
|
export type ReasoningEffort = (typeof REASONING_EFFORTS)[number];
|
|
export type ReasoningCapabilities = {
|
|
efforts: ReasoningEffort[];
|
|
defaultEffort: ReasoningEffort | null;
|
|
};
|
|
|
|
// Verified against official model pages on 2026-11-15:
|
|
// https://developers.openai.com/api/docs/models/{model}
|
|
// https://developers.openai.com/api/docs/guides/deployment-checklist#set-up-reasoningeffort
|
|
// Use exact documented aliases/snapshots. Do not infer support from a prefix:
|
|
// chat-latest, pro/codex variants, fine-tunes, and future snapshots can differ.
|
|
const modelGroups: { models: string[]; capabilities: ReasoningCapabilities }[] = [
|
|
{
|
|
models: ["gpt-5", "gpt-5-2025-08-07"],
|
|
capabilities: { efforts: ["minimal", "low", "medium", "high"], defaultEffort: "medium" },
|
|
},
|
|
{
|
|
models: ["gpt-5.1", "gpt-5.1-2025-11-13"],
|
|
capabilities: { efforts: ["none", "low", "medium", "high"], defaultEffort: "none" },
|
|
},
|
|
{
|
|
models: ["gpt-5.2", "gpt-5.2-2025-12-11", "gpt-5.4", "gpt-5.4-2026-03-05",
|
|
"gpt-5.4-mini", "gpt-5.4-mini-2026-03-17", "gpt-5.4-nano", "gpt-5.4-nano-2026-03-17"],
|
|
capabilities: { efforts: ["none", "low", "medium", "high", "xhigh"], defaultEffort: "none" },
|
|
},
|
|
{
|
|
models: ["gpt-5.5", "gpt-5.5-2026-04-23"],
|
|
capabilities: { efforts: ["none", "low", "medium", "high", "xhigh"], defaultEffort: "medium" },
|
|
},
|
|
{
|
|
models: ["gpt-5.6", "gpt-5.6-sol", "gpt-6-sol", "gpt-6-luna"],
|
|
capabilities: { efforts: ["none", "low", "medium", "high", "xhigh", "max"], defaultEffort: "medium" },
|
|
},
|
|
{
|
|
models: ["gpt-6.1-sol"],
|
|
capabilities: { efforts: ["low", "medium", "high", "xhigh", "max"], defaultEffort: "medium" },
|
|
},
|
|
{
|
|
models: ["gpt-6-astra"],
|
|
capabilities: { efforts: ["low", "medium", "high", "xhigh", "max"], defaultEffort: null },
|
|
},
|
|
];
|
|
|
|
const openAIModels = new Map(modelGroups.flatMap(({ models, capabilities }) => models.map((model) => [model, capabilities] as const)));
|
|
|
|
export function getReasoningCapabilities(provider: string | null | undefined, model: string | null | undefined) {
|
|
return provider === "openai" && model ? openAIModels.get(model) ?? null : null;
|
|
}
|
|
|
|
export function getReasoningCatalog(provider: string): Record<string, ReasoningCapabilities> {
|
|
if (provider !== "openai") return {};
|
|
return Object.fromEntries([...openAIModels].map(([model, value]) => [model, { ...value, efforts: [...value.efforts] }]));
|
|
}
|
|
|
|
export function normalizeReasoningEffort(provider: string | null | undefined, model: string | null | undefined, effort: unknown): ReasoningEffort | null {
|
|
const capabilities = getReasoningCapabilities(provider, model);
|
|
return capabilities?.efforts.includes(effort as ReasoningEffort) ? effort as ReasoningEffort : null;
|
|
}
|
|
|
|
export function reasoningRequestOptions(params: { provider?: string; model: string; reasoningEffort?: ReasoningEffort | null }, protocol: "responses" | "chat-completions") {
|
|
const effort = normalizeReasoningEffort(params.provider, params.model, params.reasoningEffort);
|
|
if (!effort) return {};
|
|
return protocol === "responses" ? { reasoning: { effort } } : { reasoning_effort: effort };
|
|
}
|