qoder 0.2.55: a request whose max_tokens is 1024 or less does not think at the default (#643)

The same default as WorkBuddy's #643 (itspig): qoderBody's effortFor
thought at the model's default effort when no effort was asked, so a
title asked at a small max_tokens could spend it on reasoning. A request
that names no effort and a max_tokens (or max_completion_tokens) of 1024
or less is now asked as "none": thinking off, or the lowest level for a
model that always thinks. An asked effort, and a larger or unnamed budget,
are unchanged.

Run, at this head, on mote:
- packages/qoder: bun test, 365 pass, 0 fail; small-budget.test.mjs new.
- bun scripts/check.mjs qoder: ok.
- Broken by hand (the SMALL_BUDGET line in effortFor removed):
  small-budget.test.mjs is red, 1 pass, 1 fail.

Not tried: a real Qoder account. Qoder answers 401 to the owner's account
(plugins#181), and no Qoder report showed a small budget spent on
thinking; the change follows WorkBuddy's measured case.
Other siblings checked: trae, devin, commandcode, loomy and kiro send only
an effort the client asked or leave the server's default; none add one.
This commit is contained in:
yetone
2026-11-03 02:25:46 +08:00
parent d51bd50cf6
commit 58adeadfac
4 changed files with 51 additions and 5 deletions
+4 -1
View File
@@ -138,7 +138,10 @@ itself.
- The model's own configuration from Qoder's list goes with it.
- It picks the reasoning effort from the model's own levels:
- The nearest level to the one asked, the higher one on a tie.
- The model's default when none is asked.
- The model's default when none is asked, unless the request's
`max_tokens` is 1024 or less: that is asked as "none" (since 0.2.55,
plugins#643), since thinking would spend so small a budget on
reasoning alone.
- The lowest level for "none", when the model can't turn thinking off.
- It picks the context window (`context_length`) from the model's own
windows (Qoder's Context setting: 200K, 400K, 1M): the default while the
+16 -3
View File
@@ -898,12 +898,24 @@ function fitEffort(want, levels) {
return best
}
// SMALL_BUDGET is the largest max_tokens a request can name and still be
// one no client meant to think in: Anthropic's API takes thinking only with
// a budget of at least 1024 tokens and a max_tokens above it, and a client's
// own short asks (a session title, a classification) name such budgets.
// Thinking by default spends them on reasoning: on WorkBuddy, a title asked
// at 64 tokens ended "length" with 64 reasoning tokens and no text
// (plugins#643, itspig).
const SMALL_BUDGET = 1024
// effortFor is whether to think and at which of the model's efforts ("" for
// none): asked for none, a model that always thinks thinks at its lowest;
// asked for nothing, or a level Qoder doesn't name, at its own default.
function effortFor(asked, m) {
// asked for nothing, or a level Qoder doesn't name, at its own default —
// unless the request's own budget (max_tokens, 0 when it named none) is
// SMALL_BUDGET or less, which is asked as none.
function effortFor(asked, m, budget = 0) {
let want = String(asked ?? "").toLowerCase()
if (!EFFORT_RANK.includes(want)) want = ""
if (want === "" && budget > 0 && budget <= SMALL_BUDGET) want = "none"
if (!m.thinks || (want === "none" && !m.alwaysThinks)) return [false, ""]
if (!m.efforts.length) return [true, ""]
if (want === "") return [true, m.defaultEffort]
@@ -1268,7 +1280,8 @@ function qoderBody(chat, m, named = "", task, site) {
let sysText = system ? baseSystem + "\n\n" + system : baseSystem
if (chat.tool_choice === "required" && tools.length) sysText += "\nYou must call an available function in this response."
const sys = { type: "text", text: sysText }
const [thinking, effort] = effortFor(chat.reasoning_effort, m)
const budget = chat.max_completion_tokens || chat.max_tokens || 0
const [thinking, effort] = effortFor(chat.reasoning_effort, m, typeof budget === "number" ? budget : 0)
const params = { enable_thinking: thinking, max_tokens: chat.max_completion_tokens || chat.max_tokens || 32000 }
if (effort) params.reasoning_effort = effort
const window = windowFor(chat, m, params.max_tokens)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.54",
"version": "0.2.55",
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship, VPC and dedicated domains",
"type": "module",
"main": "./index.mjs",
+30
View File
@@ -0,0 +1,30 @@
// A request whose own max_tokens is small asks for no thinking: the default
// effort would spend its whole output budget on reasoning, as WorkBuddy's
// did on a 64-token title (plugins#643, itspig). Qoder's qoderBody had the
// same default, so it gets the same rule.
import { expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const { qoderBody, modelInfo } = _internal
const tc = (disabled) => ({ enabled: { efforts: { low: {}, medium: {}, high: { is_default: true } } }, ...(disabled ? { disabled: {} } : {}) })
const optional = modelInfo({ key: "think-opt", is_reasoning: true, thinking_config: tc(true) })
const always = modelInfo({ key: "think-always", is_reasoning: true, thinking_config: tc(false) })
const chat = (extra) => ({ messages: [{ role: "user", content: "Title this chat." }], ...extra })
const params = (m, extra) => qoderBody(chat(extra), m).parameters
test("a small max_tokens with no effort asked does not think at the default", () => {
for (const extra of [{ max_tokens: 64 }, { max_tokens: 1024 }, { max_completion_tokens: 64 }]) {
expect(params(optional, extra).enable_thinking).toBe(false)
expect(params(optional, extra).reasoning_effort).toBeUndefined()
// A model that always thinks thinks at its lowest, as a request for none does.
expect(params(always, extra)).toMatchObject({ enable_thinking: true, reasoning_effort: "low" })
}
expect(params(optional, { max_tokens: 64 }).max_tokens).toBe(64)
})
test("an asked effort, a larger budget or none named keeps what it had", () => {
expect(params(optional, { max_tokens: 64, reasoning_effort: "high" })).toMatchObject({ enable_thinking: true, reasoning_effort: "high" })
for (const extra of [{ max_tokens: 1025 }, { max_completion_tokens: 32000 }, {}]) {
expect(params(optional, extra)).toMatchObject({ enable_thinking: true, reasoning_effort: "high" })
}
})