fix(workbuddy): omit default reasoning effort when max_tokens <= 256
When a chat does not explicitly name reasoning_effort, withDefaultEffort injects the model's default reasoning effort (e.g. 'high'). However, for lightweight tasks specifying small output limits (e.g. max_tokens <= 256 like title generation or short classification), forcing a high reasoning effort consumes the entire completion token budget on reasoning alone, producing 0 text tokens before hitting finish_reason=length. Skip default reasoning effort injection when max_tokens <= 256 while preserving explicit client-specified efforts and normal-sized chats. Issue #643, PR #644.
This commit is contained in:
@@ -149,3 +149,21 @@ test("defaultEffortOf reads defaultEffort, else effort, held to the model's leve
|
||||
expect(defaultEffortOf({ reasoning: { defaultEffort: "medium" } }, ["low", "high"])).toBeUndefined()
|
||||
expect(defaultEffortOf({}, ["low"])).toBeUndefined()
|
||||
})
|
||||
|
||||
test("a chat with small max_tokens (<= 256) is not given a default reasoning effort", async () => {
|
||||
const sent = serve()
|
||||
const opts = await loader()
|
||||
for (const max_tokens of [64, 100, 256]) {
|
||||
await ask(opts, "deepseek-v4.1-flash", { max_tokens })
|
||||
}
|
||||
await ask(opts, "deepseek-v4.1-flash", { max_completion_tokens: 64 })
|
||||
await ask(opts, "deepseek-v4.1-flash", { max_tokens: 64, reasoning_effort: "low" })
|
||||
await ask(opts, "deepseek-v4.1-flash", { max_tokens: 1000 })
|
||||
const chats = chatsOf(sent).map((c) => JSON.parse(c.text))
|
||||
expect(chats[0].reasoning_effort).toBeUndefined()
|
||||
expect(chats[1].reasoning_effort).toBeUndefined()
|
||||
expect(chats[2].reasoning_effort).toBeUndefined()
|
||||
expect(chats[3].reasoning_effort).toBeUndefined()
|
||||
expect(chats[4].reasoning_effort).toBe("low")
|
||||
expect(chats[5].reasoning_effort).toBe("high")
|
||||
})
|
||||
|
||||
@@ -3264,6 +3264,8 @@ function defaultEffortOf(d, efforts) {
|
||||
// effort the client named, "none" too, goes as it came.
|
||||
function withDefaultEffort(chat, list) {
|
||||
if (!chat || typeof chat !== "object" || namesEffort(chat)) return false
|
||||
const limit = chat.max_tokens ?? chat.max_completion_tokens
|
||||
if (typeof limit === "number" && limit > 0 && limit <= 256) return false
|
||||
const m = list?.find((x) => x.id === chat.model)
|
||||
if (!m?.effort) return false
|
||||
chat.reasoning_effort = m.effort
|
||||
|
||||
Reference in New Issue
Block a user