Skip to content

Commit 6bd8e76

Browse files
committed
refactor(zai): bumping up maxTokens for 5.1 turbo - adding e2e test
1 parent f814306 commit 6bd8e76

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

apps/vscode-e2e/src/suite/providers/zai.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ suite("Z.ai GLM provider", function () {
153153

154154
suiteSetup(async () => {
155155
restoreFetch = installZAiFetchInterceptor(
156-
[{ match: "zai-glm-e2e:", result: "4" }],
156+
[
157+
{ match: "zai-glm-e2e:", result: "4" },
158+
{ match: "zai-glm-5-turbo-e2e:", result: "4" },
159+
],
157160
requestCapture,
158161
!!ZAI_API_KEY,
159162
)
@@ -211,4 +214,43 @@ suite("Z.ai GLM provider", function () {
211214
`max_tokens should be the documented glm-5.1 limit (131_072) but was ${requestCapture.maxTokens}`,
212215
)
213216
})
217+
218+
test("Should complete a task end-to-end using glm-5-turbo via Z.ai provider", async () => {
219+
await globalThis.api.setConfiguration({
220+
apiProvider: "zai" as const,
221+
zaiApiKey: ZAI_API_KEY ?? "mock-key",
222+
zaiApiLine: "international_api" as const,
223+
apiModelId: "glm-5-turbo",
224+
})
225+
226+
const api = globalThis.api
227+
const messages: ClineMessage[] = []
228+
229+
api.on(RooCodeEventName.Message, ({ message }) => {
230+
if (message.type === "say" && message.partial === false) {
231+
messages.push(message)
232+
}
233+
})
234+
235+
const taskId = await api.startNewTask({
236+
configuration: { mode: "ask", alwaysAllowModeSwitch: true, autoApprovalEnabled: true },
237+
text: "zai-glm-5-turbo-e2e: what is 2+2? Reply with only the number.",
238+
})
239+
240+
await waitUntilCompleted({ api, taskId })
241+
242+
const completionMessage = messages.find(
243+
({ say, text }) => (say === "completion_result" || say === "text") && text?.trim() === "4",
244+
)
245+
246+
assert.ok(completionMessage, "Task should complete with the expected Z.ai GLM-5-Turbo response")
247+
248+
// Verify max_tokens is the model's documented limit (131_072), not the 20%-of-context
249+
// heuristic cap (40_000) that guards against inaccurate OpenRouter dynamic metadata.
250+
assert.strictEqual(
251+
requestCapture.maxTokens,
252+
131_072,
253+
`max_tokens should be the documented glm-5-turbo limit (131_072) but was ${requestCapture.maxTokens}`,
254+
)
255+
})
214256
})

packages/types/src/providers/zai.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ZaiApiLine } from "../provider-settings.js"
66
// https://docs.z.ai/guides/llm/glm-4.5
77
// https://docs.z.ai/guides/llm/glm-4.6
88
// https://docs.z.ai/guides/llm/glm-5.1
9+
// https://docs.z.ai/guides/llm/glm-5-turbo
910
// https://docs.z.ai/guides/overview/pricing
1011
// https://bigmodel.cn/pricing
1112

@@ -152,7 +153,7 @@ export const internationalZAiModels = {
152153
"GLM-5.1 is Zhipu's most capable model with a 200k context window, 128k max output, and built-in thinking capabilities. It delivers top-tier reasoning, coding, and agentic performance.",
153154
},
154155
"glm-5-turbo": {
155-
maxTokens: 16_384,
156+
maxTokens: 131_072,
156157
contextWindow: 202_752,
157158
supportsImages: false,
158159
supportsPromptCache: true,
@@ -358,7 +359,7 @@ export const mainlandZAiModels = {
358359
"GLM-5.1 is Zhipu's most capable model with a 200k context window, 128k max output, and built-in thinking capabilities. It delivers top-tier reasoning, coding, and agentic performance.",
359360
},
360361
"glm-5-turbo": {
361-
maxTokens: 16_384,
362+
maxTokens: 131_072,
362363
contextWindow: 202_752,
363364
supportsImages: false,
364365
supportsPromptCache: true,

src/api/providers/__tests__/zai.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ describe("ZAiHandler", () => {
127127
expect(model.id).toBe(testModelId)
128128
expect(model.info).toEqual(internationalZAiModels[testModelId])
129129
expect(model.info.contextWindow).toBe(202_752)
130+
expect(model.info.maxTokens).toBe(131_072)
130131
expect(model.info.supportsReasoningEffort).toEqual(["disable", "medium"])
131132
expect(model.info.reasoningEffort).toBe("medium")
132133
expect(model.info.preserveReasoning).toBe(true)
@@ -257,6 +258,7 @@ describe("ZAiHandler", () => {
257258
expect(model.id).toBe(testModelId)
258259
expect(model.info).toEqual(mainlandZAiModels[testModelId])
259260
expect(model.info.contextWindow).toBe(202_752)
261+
expect(model.info.maxTokens).toBe(131_072)
260262
expect(model.info.supportsReasoningEffort).toEqual(["disable", "medium"])
261263
expect(model.info.reasoningEffort).toBe("medium")
262264
expect(model.info.preserveReasoning).toBe(true)

0 commit comments

Comments
 (0)