fix: map reasoning controls onto Zhipu BigModel's generation-specific thinking API - #748
Open
HUAN2022A wants to merge 1 commit into
Open
fix: map reasoning controls onto Zhipu BigModel's generation-specific thinking API#748HUAN2022A wants to merge 1 commit into
HUAN2022A wants to merge 1 commit into
Conversation
… thinking API Structured ingest on Zhipu BigModel endpoints failed with 'Model produced N chars of reasoning, but no actual response content': GLM thinking models spent the whole budget on reasoning_content, and the app's reasoning-off request was silently dropped because open.bigmodel.cn fell into the generic custom-gateway bucket. Wire the controls per generation, matching Zhipu's documented support: - capability layer: glm-4.5..5.1 offer auto/off; glm-5.2+ add low/high/max (medium and custom budgets are not representable); pre-4.5 ids stay auto-only, mirroring DeepSeek's gating - wire layer: reasoning off sends thinking.type=disabled on 4.5..5.2, but glm-5.3+ rejects that field with error 1210 (thinking is always on), so it maps to reasoning_effort=low; effort levels map to thinking.enabled + reasoning_effort on 5.2+ Verified against open.bigmodel.cn/api/paas/v4 with glm-5.3-flash: reasoning_effort=low returns 0 reasoning chars where the default (max) returned ~1k before the answer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Structured ingest against a Zhipu BigModel endpoint (
open.bigmodel.cn/api/paas/v4) with a GLM thinking model fails with the app's own diagnostic:Two causes stack up:
buildOpenAiCompatibleBodyhas no BigModel adapter —thinking.type=disabledis sent for Xiaomi MiMo and DeepSeek only, soreasoning: { mode: "off" }(every structured ingest call) is silently dropped and the GLM model thinks by default.resolveReasoningCapabilitiesbucketsopen.bigmodel.cnas a generic custom gateway (auto-only), so a savedoffis normalized away before the wire is built — the user has no way to fix it from the UI.Root cause: Zhipu's thinking API is generation-specific
Per Zhipu's docs (
docs.bigmodel.cn/cn/guide/capabilities/thinking,.../guide/models/text/glm-5.3), verified empirically againstglm-5.3-flashon/api/paas/v4:reasoning_contentbeforecontentthinking: {type: "disabled"}reasoning_effort: "low"thinking: {type: "enabled"} + reasoning_effortSo a straight copy of the DeepSeek/MiMo adapter would turn ingest failures into hard 400s on GLM-5.3+.
Fix
reasoning-capabilities.tsisBigModelEndpoint(endpoint)(shared, endpoint-string form;llm-providers.tsnow uses it for its image-support checks too)parseGlmVersion/isGlmAtLeast— parse the generation out of model ids (glm-4.7-flash→ 4.7,glm-5v-turbo→ 5.0,glm-z1-*/ non-GLM → null)TOGGLE_LEVELS); 5.2+ → auto/off/low/high/max (GLM_EFFORT_LEVELS;mediumand custom budgets are not representable in Zhipu's lineup)llm-providers.ts—adaptBigModelBody:off→thinking: {type: "disabled"}on 4.5..5.2;reasoning_effort: "low"on 5.3+ (which rejectsdisabledwith error 1210)low/high/max→thinking: {type: "enabled"} + reasoning_efforton 5.2+auto/ unsupported modes → body untouched (server default)Testing
llm-providers.test.ts(wire shapes per generation, incl. the 1210-avoidance path and generic-gateway isolation) andreasoning-capabilities.test.ts(mode sets per generation, version parsing)npx vitest run(mock suite): 132 files / 1884 tests passnpm run typecheckandnpx vite buildpassreasoning_effort: "low",temperature: 0.1) returns normalcontentwith zero reasoning content onglm-5.3-flashNotes
/api/paas/v4), matching the existing Zhipu preset; the Anthropic-compatible endpoint is untouched.open.bigmodel.cn), consistent with the DeepSeek/MiMo branches; a GLM model id through a generic gateway keeps auto-only capabilities.