fix(translator): zai thinkingFormat sends reasoning.effort object
Z.ai / GLM-5.2+ require a top-level reasoning_effort (low/high/max)
alongside thinking:{type:"enabled"} to control reasoning depth; the zai
branch previously only set thinking and dropped reasoning_effort, so every
GLM-5.x request ran at the model default (max). Gate the field behind
GLM-5.2+ (thinkingEffortSupported in capabilities.js) since older GLM
(4.x, 5.0, 5.1, 5-turbo, 5v-turbo) do not read it, and map client levels
to the exact low/high/max values z.ai accepts.
extractThinking now checks reasoning_effort/reasoning.effort before the
thinking object so a client-supplied effort is not overwritten by
thinking:{type:"enabled"} mapping to mode:auto.
Fixes #2721
This commit is contained in:
@@ -58,6 +58,18 @@ describe("extractThinking", () => {
|
||||
it("no intent → null", () => {
|
||||
expect(extractThinking({ messages: [] })).toBeNull();
|
||||
});
|
||||
it("reasoning_effort wins over thinking:{type:enabled} (no budget)", () => {
|
||||
expect(extractThinking({
|
||||
thinking: { type: "enabled" },
|
||||
reasoning_effort: "high",
|
||||
})).toEqual({ mode: "level", level: "high" });
|
||||
});
|
||||
it("reasoning.effort wins over thinking:{type:enabled} (no budget)", () => {
|
||||
expect(extractThinking({
|
||||
thinking: { type: "enabled" },
|
||||
reasoning: { effort: "medium" },
|
||||
})).toEqual({ mode: "level", level: "medium" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyThinking per provider format", () => {
|
||||
@@ -114,6 +126,27 @@ describe("applyThinking per provider format", () => {
|
||||
expect(out.enable_thinking).toBe(false);
|
||||
expect(out.thinking).toBeUndefined();
|
||||
});
|
||||
it.each([
|
||||
["high", "high"],
|
||||
["max", "max"],
|
||||
["xhigh", "max"],
|
||||
["low", "low"],
|
||||
["medium", "high"],
|
||||
["minimal", "low"],
|
||||
])("GLM-5.3 %s → reasoning_effort=%s (low|high|max only, per z.ai docs)", (input, expected) => {
|
||||
const out = apply("openai", "glm-5.3", { reasoning_effort: input }, "glm-cn");
|
||||
expect(out.thinking).toEqual({ type: "enabled" });
|
||||
expect(out.reasoning_effort).toBe(expected);
|
||||
});
|
||||
it("GLM-5.2 also gets reasoning_effort (supported from 5.2 onward)", () => {
|
||||
const out = apply("openai", "glm-5.2", { reasoning_effort: "low" }, "glm-cn");
|
||||
expect(out.reasoning_effort).toBe("low");
|
||||
});
|
||||
it("GLM-4.7 (pre-5.2) does not get reasoning_effort — z.ai ignores it", () => {
|
||||
const out = apply("openai", "glm-4.7", { reasoning_effort: "low" }, "glm-cn");
|
||||
expect(out.thinking).toEqual({ type: "enabled" });
|
||||
expect(out.reasoning_effort).toBeUndefined();
|
||||
});
|
||||
it("Qwen on → enable_thinking + thinking_budget", () => {
|
||||
const out = apply("openai", "qwen3-max", { reasoning_effort: "medium" }, "qwen");
|
||||
expect(out.enable_thinking).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user