Files
HealthLog/src/lib/ai/openai-capabilities.ts
T
Marc-André Bombeck 8787d71d1c fix(ai): recognise the gpt-6 model family in every model gate
The ChatGPT Codex backend and the OpenAI API serve gpt-6-sol, gpt-6-luna,
gpt-6-astra and gpt-6.1-sol, but the reasoning, Chat Completions and vision
gates only knew the gpt-5 line. A gpt-6 model got no reasoning control and
no real "off", went out on the legacy wire with max_tokens and a
temperature that reasoning models refuse, and was denied image input.

The three gates now read one classifier, openai-model-family.ts, so a new
generation is taught in one place. Every GPT from 5.1 on, the gpt-6 line
included, is the family that takes effort "none"; every GPT from 5 on reads
images. The upstream catalog (codex-rs/models-manager/models.json) lists
image input for every gpt-6 slug and the same reasoning presets as the
gpt-5.6 line; the presets omit "none" for gpt-5.5 too, which accepts it.

The Codex slug ladder moves into codex-slug-chain.ts and gains gpt-6-sol,
gpt-6.1-sol and gpt-6-luna. gpt-5.6-terra stays first as the slug verified
against the backend; the catalog names gpt-6-sol as its upgrade, and a
rotation retires a whole line at once, so the gpt-6 rungs follow before
terra's own siblings. The ladder test now holds every rung to a recognised
reasoning family with a real off and image input. The OpenAI presets offer
gpt-6.1-sol and gpt-6-luna.
2026-10-24 10:11:16 +02:00

63 lines
1.8 KiB
TypeScript

import { openAIModelFamily } from "./openai-model-family";
export type OpenAIChatCompletionsCapabilities =
| {
tokenBudgetField: "max_completion_tokens";
supportsSamplingControls: false;
}
| {
tokenBudgetField: "max_tokens";
supportsSamplingControls: true;
};
const MODERN_CANONICAL_CAPABILITIES = {
tokenBudgetField: "max_completion_tokens",
supportsSamplingControls: false,
} as const;
const LEGACY_COMPATIBLE_CAPABILITIES = {
tokenBudgetField: "max_tokens",
supportsSamplingControls: true,
} as const;
/**
* A reasoning model (gpt-5 on, the gpt-6 line included, the o-series) takes
* `max_completion_tokens` and refuses sampling controls; the family reading
* is shared with the reasoning and vision gates.
*/
function isModernCanonicalModel(model: string): boolean {
return openAIModelFamily(model)?.reasoning != null;
}
export function isCanonicalOpenAIEndpoint(baseUrl: string): boolean {
try {
const url = new URL(baseUrl);
return (
url.protocol === "https:" &&
url.hostname === "api.openai.com" &&
url.port === "" &&
url.pathname.replace(/\/+$/, "") === "/v1" &&
url.username === "" &&
url.password === "" &&
url.search === "" &&
url.hash === ""
);
} catch {
return false;
}
}
/**
* Select Chat Completions request capabilities from both endpoint and model.
* Custom OpenAI-compatible gateways retain the broadly supported legacy wire,
* even when their model name resembles a modern OpenAI model.
*/
export function selectOpenAIChatCompletionsCapabilities(
baseUrl: string,
model: string,
): OpenAIChatCompletionsCapabilities {
return isCanonicalOpenAIEndpoint(baseUrl) && isModernCanonicalModel(model)
? MODERN_CANONICAL_CAPABILITIES
: LEGACY_COMPATIBLE_CAPABILITIES;
}