-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add thinking mode support for GLM-4.6 and GLM-4.6V models #11114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…1071 This PR combines: 1. PR #11093 fix: NativeToolCallParser processFinishReason hasStarted check 2. GLM model detection utility for LM Studio and OpenAI-compatible providers 3. mergeToolResultText optimization for GLM models 4. Disable parallel_tool_calls for GLM models 5. GLM-4.7 thinking parameter support 6. Diagnostic logging for GLM detection Closes #11071
This commit adds GLM model detection and related optimizations to the
OpenAI Compatible provider (OpenAiHandler), which handles the "OpenAI
Compatible" option in the UI when users set a custom base URL.
Changes:
- Import GLM detection utilities and Z.ai format converter
- Add glmConfig property to track GLM model configuration
- Detect GLM model on construction when model ID is available
- Re-detect GLM model in createMessage if model ID changes
- For GLM models:
- Use convertToZAiFormat with mergeToolResultText to prevent
conversation flow disruption
- Disable parallel_tool_calls as GLM models may not support it
- Add thinking parameter for GLM-4.7 models
- Add console logging for detection results and applied optimizations
This addresses the feedback in issue #11071 where the user clarified
they are using the "OpenAI Compatible" provider, not the "OpenAI"
provider. The previous changes in this PR only affected the
base-openai-compatible-provider.ts (used by Z.ai, Groq, etc.) and
lm-studio.ts, but not openai.ts which handles OpenAI Compatible.
- Add supportsReasoningEffort to GLM-4.6 and GLM-4.6V model definitions - Update GLM detection logic to recognize GLM-4.6/4.6V thinking support - Update Z.ai provider to handle thinking mode for all GLM models with reasoning - Update tests to reflect GLM-4.6/4.6V thinking support Addresses issue #11071 where Z.ai documentation shows GLM-4.6 and GLM-4.6V support thinking mode, but this was not reflected in the codebase.
Review complete. Found 2 issues to address:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| // GLM-4.6, GLM-4.6V, and GLM-4.7 have built-in thinking support | ||
| // For GLM-4.6, only the base model and vision variants support thinking | ||
| const supportsThinking = | ||
| version === "4.7" || | ||
| (version === "4.6" && | ||
| (variant === "base" || variant === "v" || variant === "v-flash" || variant === "v-flashx")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This detection includes v-flash and v-flashx variants as supporting thinking, but the model definitions in zai.ts don't include supportsReasoningEffort for glm-4.6v-flash or glm-4.6v-flashx. This inconsistency means the Z.ai provider (which checks Array.isArray(info.supportsReasoningEffort)) will correctly exclude these models from thinking mode, but LM Studio and OpenAI Compatible providers will incorrectly try to send the thinking parameter to them. Either add supportsReasoningEffort to the flash variants in zai.ts if they truly support thinking, or remove v-flash and v-flashx from this detection logic.
Fix it with Roo Code or mention @roomote and request a fix.
| if (this.glmConfig.isGlmModel && this.glmConfig.supportsThinking) { | ||
| const useReasoning = this.options.enableReasoningEffort !== false // Default to enabled for GLM-4.7 | ||
| ;(params as any).thinking = useReasoning ? { type: "enabled" } : { type: "disabled" } | ||
| console.log(`[${this.providerName}] GLM-4.7 thinking mode: ${useReasoning ? "enabled" : "disabled"}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log message says "GLM-4.7 thinking mode" but this code now also executes for GLM-4.6 and GLM-4.6V models. Consider updating to something like "GLM thinking mode" or using this.glmConfig.displayName for accuracy. The same issue exists in lm-studio.ts and openai.ts.
| console.log(`[${this.providerName}] GLM-4.7 thinking mode: ${useReasoning ? "enabled" : "disabled"}`) | |
| console.log(`[${this.providerName}] ${this.glmConfig.displayName} thinking mode: ${useReasoning ? "enabled" : "disabled"}`) |
Fix it with Roo Code or mention @roomote and request a fix.
This PR attempts to address Issue #11071.
Related GitHub Issue
Addresses: #11071 (comment by @mark-ucalgary)
Description
According to the Z.ai documentation for GLM-4.6 and GLM-4.6V, both models support thinking mode. However, the current codebase only defines thinking support for GLM-4.7.
This PR adds thinking mode support for GLM-4.6 and GLM-4.6V models across:
Changes Made
1. Model Definitions (
packages/types/src/providers/zai.ts)supportsReasoningEffort: ["disable", "medium"]to GLM-4.6 (international and mainland)supportsReasoningEffort: ["disable", "medium"]to GLM-4.6V (international and mainland)reasoningEffort: "medium"andpreserveReasoning: trueto both models2. GLM Detection (
src/api/providers/utils/glm-model-detection.ts)supportsThinkingdetection to include GLM-4.6 base model3. Z.ai Provider (
src/api/providers/zai.ts)supportsReasoningEffortarray4. Tests (
src/api/providers/utils/__tests__/glm-model-detection.spec.ts)Test Procedure
Run the GLM detection tests:
The updated tests verify:
supportsThinking: truesupportsThinking: truesupportsThinking: truesupportsThinking: falseImpact
For Z.ai provider users:
thinkingparameterFor LM Studio and OpenAI-compatible endpoint users:
supportsThinking: truefor these modelsPre-Submission Checklist
Screenshots / Videos
N/A - Backend feature, no UI changes.
Documentation Updates
Additional Notes
This PR builds on the GLM detection work in PR #11096 and addresses the specific feedback from @mark-ucalgary regarding GLM-4.6 and GLM-4.6V thinking support as documented by Z.ai.
Feedback and guidance are welcome!
Important
Adds thinking mode support for GLM-4.6 and GLM-4.6V models, updating model definitions, detection logic, provider implementations, and tests.
zai.ts,glm-model-detection.ts, andzai.ts.glm-model-detection.tsto include GLM-4.6 and GLM-4.6V.createStreaminbase-openai-compatible-provider.tsto handle thinking mode for GLM models.glm-model-detection.spec.ts.zai.tsto reflect new model support.NativeToolCallParserto handle tool call synchronization more robustly.This description was created by
for 23256cd. You can customize this summary. It will automatically update as commits are pushed.