fix(provider): support OpenAI pro reasoning mode (#36694)
This commit is contained in:
parent
c2f93ae2ad
commit
e434ce01d3
8 changed files with 75 additions and 27 deletions
|
|
@ -67,7 +67,7 @@
|
|||
"@ai-sdk/google-vertex": "4.0.128",
|
||||
"@ai-sdk/groq": "3.0.31",
|
||||
"@ai-sdk/mistral": "3.0.27",
|
||||
"@ai-sdk/openai": "3.0.53",
|
||||
"@ai-sdk/openai": "3.0.84",
|
||||
"@ai-sdk/openai-compatible": "2.0.41",
|
||||
"@ai-sdk/perplexity": "3.0.26",
|
||||
"@ai-sdk/provider": "3.0.8",
|
||||
|
|
|
|||
|
|
@ -286,6 +286,7 @@ export async function CodexAuthPlugin(input: PluginInput, options: CodexAuthPlug
|
|||
return Object.fromEntries(
|
||||
Object.entries(provider.models)
|
||||
.filter(([, model]) => {
|
||||
if (model.options.reasoningMode === "pro") return false
|
||||
if (ALLOWED_MODELS.has(model.api.id)) return true
|
||||
if (DISALLOWED_MODELS.has(model.api.id)) return false
|
||||
if (model.api.id === "gpt-5.6") return false
|
||||
|
|
|
|||
|
|
@ -1267,14 +1267,7 @@ export function fromModelsDevProvider(provider: ModelsDev.Provider): Info {
|
|||
id: ModelV2.ID.make(id),
|
||||
name: `${model.name} ${mode[0].toUpperCase()}${mode.slice(1)}`,
|
||||
cost: opts.cost ? mergeDeep(base.cost, cost(opts.cost)) : base.cost,
|
||||
options: opts.provider?.body
|
||||
? Object.fromEntries(
|
||||
Object.entries(opts.provider.body).map(([k, v]) => [
|
||||
k.replace(/_([a-z])/g, (_, c) => c.toUpperCase()),
|
||||
v,
|
||||
]),
|
||||
)
|
||||
: base.options,
|
||||
options: modeOptions(base, opts.provider?.body),
|
||||
headers: opts.provider?.headers ?? base.headers,
|
||||
}
|
||||
}
|
||||
|
|
@ -1289,6 +1282,17 @@ export function fromModelsDevProvider(provider: ModelsDev.Provider): Info {
|
|||
}
|
||||
}
|
||||
|
||||
function modeOptions(model: Model, body: Record<string, unknown> | undefined) {
|
||||
if (!body) return model.options
|
||||
const options = Object.fromEntries(
|
||||
Object.entries(body).map(([key, value]) => [key.replace(/_([a-z])/g, (_, char) => char.toUpperCase()), value]),
|
||||
)
|
||||
const reasoning = body.reasoning
|
||||
if (model.api.npm !== "@ai-sdk/openai" || !isRecord(reasoning) || typeof reasoning.mode !== "string") return options
|
||||
const { reasoning: _, ...rest } = options
|
||||
return { ...rest, reasoningMode: reasoning.mode }
|
||||
}
|
||||
|
||||
function modelSuggestions(provider: Info | undefined, modelID: ModelV2.ID, enableExperimentalModels: boolean) {
|
||||
const available = provider
|
||||
? Object.keys(provider.models).filter((id) => {
|
||||
|
|
|
|||
|
|
@ -149,16 +149,31 @@ describe("plugin.codex", () => {
|
|||
await enabled.dispose?.()
|
||||
})
|
||||
|
||||
test("uses Codex context limits for OAuth GPT models", async () => {
|
||||
test("filters unsupported modes and uses Codex context limits for OAuth GPT models", async () => {
|
||||
const hooks = await CodexAuthPlugin({} as never)
|
||||
const limit = { context: 1_050_000, input: 922_000, output: 128_000 }
|
||||
const provider = {
|
||||
models: Object.fromEntries(
|
||||
["gpt-5.4", "gpt-5.5", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"].map((id) => [
|
||||
id,
|
||||
{ id, api: { id }, limit, cost: {} },
|
||||
]),
|
||||
),
|
||||
models: {
|
||||
...Object.fromEntries(
|
||||
["gpt-5.4", "gpt-5.5", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-5.7-pro"].map(
|
||||
(id) => [id, { id, api: { id }, limit, cost: {}, options: {} }],
|
||||
),
|
||||
),
|
||||
"gpt-5.4-pro": {
|
||||
id: "gpt-5.4-pro",
|
||||
api: { id: "gpt-5.4" },
|
||||
limit,
|
||||
cost: {},
|
||||
options: { reasoningMode: "pro" },
|
||||
},
|
||||
"gpt-5.6-sol-high": {
|
||||
id: "gpt-5.6-sol-high",
|
||||
api: { id: "gpt-5.6-sol" },
|
||||
limit,
|
||||
cost: {},
|
||||
options: { reasoningEffort: "high" },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const models = await hooks.provider!.models!(provider as never, { auth: { type: "oauth" } } as never)
|
||||
|
|
@ -168,6 +183,9 @@ describe("plugin.codex", () => {
|
|||
expect(models["gpt-5.6-sol"]?.limit).toEqual({ context: 500_000, input: 372_000, output: 128_000 })
|
||||
expect(models["gpt-5.6-terra"]?.limit).toEqual({ context: 500_000, input: 372_000, output: 128_000 })
|
||||
expect(models["gpt-5.6-luna"]?.limit).toEqual({ context: 500_000, input: 372_000, output: 128_000 })
|
||||
expect(models["gpt-5.4-pro"]).toBeUndefined()
|
||||
expect(models["gpt-5.7-pro"]).toBeDefined()
|
||||
expect(models["gpt-5.6-sol-high"]).toBeDefined()
|
||||
expect(await hooks.provider!.models!(provider as never, { auth: { type: "api" } } as never)).toBe(
|
||||
provider.models as never,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1376,16 +1376,17 @@ it.instance(
|
|||
},
|
||||
)
|
||||
|
||||
test("mode cost preserves over-200k pricing from base model", () => {
|
||||
test("mode options and cost are derived from the base model", () => {
|
||||
const provider = {
|
||||
id: "openai",
|
||||
name: "OpenAI",
|
||||
env: [],
|
||||
npm: "@ai-sdk/openai",
|
||||
api: "https://api.openai.com/v1",
|
||||
models: {
|
||||
"gpt-5.4": {
|
||||
id: "gpt-5.4",
|
||||
name: "GPT-5.4",
|
||||
"gpt-5.6-sol": {
|
||||
id: "gpt-5.6-sol",
|
||||
name: "GPT-5.6 Sol",
|
||||
family: "gpt",
|
||||
release_date: "2026-03-05",
|
||||
attachment: true,
|
||||
|
|
@ -1421,18 +1422,29 @@ test("mode cost preserves over-200k pricing from base model", () => {
|
|||
},
|
||||
},
|
||||
},
|
||||
pro: {
|
||||
provider: {
|
||||
body: {
|
||||
reasoning: { mode: "pro" },
|
||||
service_tier: "priority",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ModelsDev.Provider
|
||||
|
||||
const model = Provider.fromModelsDevProvider(provider).models["gpt-5.4-fast"]
|
||||
const model = Provider.fromModelsDevProvider(provider).models["gpt-5.6-sol-fast"]
|
||||
expect(model.cost.input).toEqual(5)
|
||||
expect(model.cost.output).toEqual(30)
|
||||
expect(model.cost.cache.read).toEqual(0.5)
|
||||
expect(model.cost.cache.write).toEqual(0)
|
||||
expect(model.options["serviceTier"]).toEqual("priority")
|
||||
const pro = Provider.fromModelsDevProvider(provider).models["gpt-5.6-sol-pro"]
|
||||
expect(pro.api.id).toEqual("gpt-5.6-sol")
|
||||
expect(pro.options).toEqual({ reasoningMode: "pro", serviceTier: "priority" })
|
||||
expect(model.cost.experimentalOver200K).toEqual({
|
||||
input: 5,
|
||||
output: 22.5,
|
||||
|
|
|
|||
|
|
@ -1092,7 +1092,7 @@ describe("session.llm.stream", () => {
|
|||
const agent = {
|
||||
name: "test",
|
||||
mode: "primary",
|
||||
options: {},
|
||||
options: { reasoningMode: "pro" },
|
||||
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
||||
temperature: 0.2,
|
||||
} satisfies Agent.Info
|
||||
|
|
@ -1123,6 +1123,7 @@ describe("session.llm.stream", () => {
|
|||
expect(body.model).toBe(resolved.api.id)
|
||||
expect(body.stream).toBe(true)
|
||||
expect((body.reasoning as { effort?: string } | undefined)?.effort).toBe("high")
|
||||
expect((body.reasoning as { mode?: string } | undefined)?.mode).toBe("pro")
|
||||
|
||||
const maxTokens = body.max_output_tokens as number | undefined
|
||||
expect(maxTokens).toBe(undefined) // match codex cli behavior
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue