fix(core): turn off Workers AI thinking through the chat template (#52017)

This commit is contained in:
Aiden Cline
2026-09-29 00:45:17 -05:00
committed by GitHub
parent 2aaa265cdc
commit 6712cc4c2c
2 changed files with 51 additions and 1 deletions
+20 -1
View File
@@ -160,6 +160,25 @@ const nvidiaChat: Protocol = (model, support) => {
}
}
// Workers AI ignores or rejects `reasoning_effort: "none"` on most models. Kimi's chat template reads
// `thinking`; the others read `enable_thinking`, so both are sent.
const workersAITemplate = (thinking: boolean): Overlay => ({
body: { chat_template_kwargs: { enable_thinking: thinking, thinking } },
})
const workersAIChat: Protocol = (_, support) => {
switch (support.type) {
case "effort":
return efforts(support.values ?? EFFORTS, (effort) =>
effort === "none" ? workersAITemplate(false) : { settings: { reasoningEffort: effort } },
)
case "toggle":
return toggle(workersAITemplate(false), workersAITemplate(true))
case "budget_tokens":
return []
}
}
const basetenTemplate = (enable_thinking: boolean): Overlay => ({
body: { chat_template_args: { enable_thinking } },
})
@@ -552,7 +571,7 @@ const PROTOCOLS: Readonly<Record<string, Protocol>> = {
"@opencode/ai/providers/alibaba/chat": alibabaChat,
"@opencode/ai/providers/baseten": basetenChat,
"@opencode/ai/providers/cerebras": openaiChat,
"@opencode/ai/providers/cloudflare-workers-ai": openaiChat,
"@opencode/ai/providers/cloudflare-workers-ai": workersAIChat,
"@opencode/ai/providers/deepinfra": deepinfraChat,
"@opencode/ai/providers/deepseek": deepseekChat,
"@opencode/ai/providers/fireworks": openaiChat,
+31
View File
@@ -264,6 +264,37 @@ test("caps Alibaba thinking budget variants at 64k", () => {
])
})
test("spells Workers AI thinking controls through the chat template", () => {
const pkg = "@opencode/ai/providers/cloudflare-workers-ai"
const off = { body: { chat_template_kwargs: { enable_thinking: false, thinking: false } } }
const on = { body: { chat_template_kwargs: { enable_thinking: true, thinking: true } } }
expect(
resolve(model(pkg, "@cf/deepseek-ai/deepseek-v4-flash-0731"), [
{ type: "effort", values: ["none", "low", "high", "max"] },
]),
).toEqual([
{ id: "none", ...off },
{ id: "low", settings: { reasoningEffort: "low" } },
{ id: "high", settings: { reasoningEffort: "high" } },
{ id: "max", settings: { reasoningEffort: "max" } },
])
expect(resolve(model(pkg, "@cf/zai-org/glm-4.7-flash"), [{ type: "toggle" }])).toEqual([
{ id: "none", ...off },
{ id: "thinking", ...on },
])
expect(
resolve(model(pkg, "@cf/qwen/qwen3.8-27b"), [
{ type: "toggle" },
{ type: "effort", values: ["low", "medium", "xhigh"] },
]),
).toEqual([
{ id: "none", ...off },
{ id: "low", settings: { reasoningEffort: "low" } },
{ id: "medium", settings: { reasoningEffort: "medium" } },
{ id: "xhigh", settings: { reasoningEffort: "xhigh" } },
])
})
test("spells Chat Completions variants for hosting providers", () => {
expect(
resolve(model("@opencode/ai/providers/openai-compatible", "deepseek-ai/deepseek-v4-pro", undefined, "nvidia"), [