mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
feat: add thinking mode support for GLM-4.6 and GLM-4.6V models
- 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.
This commit is contained in:
parent
9e96578df4
commit
23256cd6da
4 changed files with 41 additions and 14 deletions
|
|
@ -86,6 +86,9 @@ export const internationalZAiModels = {
|
|||
contextWindow: 131_072,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoningEffort: ["disable", "medium"],
|
||||
reasoningEffort: "medium",
|
||||
preserveReasoning: true,
|
||||
inputPrice: 0.3,
|
||||
outputPrice: 0.9,
|
||||
cacheWritesPrice: 0,
|
||||
|
|
@ -98,6 +101,9 @@ export const internationalZAiModels = {
|
|||
contextWindow: 200_000,
|
||||
supportsImages: false,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoningEffort: ["disable", "medium"],
|
||||
reasoningEffort: "medium",
|
||||
preserveReasoning: true,
|
||||
inputPrice: 0.6,
|
||||
outputPrice: 2.2,
|
||||
cacheWritesPrice: 0,
|
||||
|
|
@ -259,6 +265,9 @@ export const mainlandZAiModels = {
|
|||
contextWindow: 204_800,
|
||||
supportsImages: false,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoningEffort: ["disable", "medium"],
|
||||
reasoningEffort: "medium",
|
||||
preserveReasoning: true,
|
||||
inputPrice: 0.29,
|
||||
outputPrice: 1.14,
|
||||
cacheWritesPrice: 0,
|
||||
|
|
@ -310,6 +319,9 @@ export const mainlandZAiModels = {
|
|||
contextWindow: 131_072,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoningEffort: ["disable", "medium"],
|
||||
reasoningEffort: "medium",
|
||||
preserveReasoning: true,
|
||||
inputPrice: 0.15,
|
||||
outputPrice: 0.45,
|
||||
cacheWritesPrice: 0,
|
||||
|
|
|
|||
|
|
@ -130,17 +130,28 @@ describe("GLM Model Detection", () => {
|
|||
})
|
||||
|
||||
describe("thinking support detection", () => {
|
||||
it("should detect thinking support for GLM-4.7", () => {
|
||||
it("should detect thinking support for GLM-4.7 variants", () => {
|
||||
expect(detectGlmModel("glm-4.7").supportsThinking).toBe(true)
|
||||
expect(detectGlmModel("glm-4.7-flash").supportsThinking).toBe(true)
|
||||
expect(detectGlmModel("GLM-4.7-FlashX").supportsThinking).toBe(true)
|
||||
})
|
||||
|
||||
it("should NOT detect thinking support for GLM-4.5 and GLM-4.6", () => {
|
||||
it("should detect thinking support for GLM-4.6 base model", () => {
|
||||
expect(detectGlmModel("glm-4.6").supportsThinking).toBe(true)
|
||||
})
|
||||
|
||||
it("should detect thinking support for GLM-4.6V vision variants", () => {
|
||||
expect(detectGlmModel("glm-4.6v").supportsThinking).toBe(true)
|
||||
expect(detectGlmModel("GLM-4.6V").supportsThinking).toBe(true)
|
||||
expect(detectGlmModel("glm-4.6v-flash").supportsThinking).toBe(true)
|
||||
expect(detectGlmModel("glm-4.6v-flashx").supportsThinking).toBe(true)
|
||||
})
|
||||
|
||||
it("should NOT detect thinking support for GLM-4.5 variants", () => {
|
||||
expect(detectGlmModel("glm-4.5").supportsThinking).toBe(false)
|
||||
expect(detectGlmModel("glm-4.6").supportsThinking).toBe(false)
|
||||
expect(detectGlmModel("glm-4.5-air").supportsThinking).toBe(false)
|
||||
expect(detectGlmModel("glm-4.6v").supportsThinking).toBe(false)
|
||||
expect(detectGlmModel("glm-4.5-flash").supportsThinking).toBe(false)
|
||||
expect(detectGlmModel("glm-4.5v").supportsThinking).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -138,8 +138,12 @@ export function detectGlmModel(modelId: string): GlmModelConfig {
|
|||
variant = "x"
|
||||
}
|
||||
|
||||
// GLM-4.7 has built-in thinking support
|
||||
const supportsThinking = version === "4.7"
|
||||
// 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"))
|
||||
|
||||
// Generate display name
|
||||
let displayName = `GLM-${version !== "unknown" ? version : "4.x"}`
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Override createStream to handle GLM-4.7's thinking mode.
|
||||
* GLM-4.7 has thinking enabled by default in the API, so we need to
|
||||
* explicitly send { type: "disabled" } when the user turns off reasoning.
|
||||
* Override createStream to handle thinking mode for GLM models.
|
||||
* GLM-4.6, GLM-4.6V, and GLM-4.7 have thinking enabled by default in the API,
|
||||
* so we need to explicitly send { type: "disabled" } when the user turns off reasoning.
|
||||
*/
|
||||
protected override createStream(
|
||||
systemPrompt: string,
|
||||
|
|
@ -52,11 +52,11 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
|
|||
) {
|
||||
const { id: modelId, info } = this.getModel()
|
||||
|
||||
// Check if this is a GLM-4.7 model with thinking support
|
||||
const isThinkingModel = modelId === "glm-4.7" && Array.isArray(info.supportsReasoningEffort)
|
||||
// Check if this is a GLM model with thinking support (GLM-4.6, GLM-4.6V, GLM-4.7)
|
||||
const isThinkingModel = Array.isArray(info.supportsReasoningEffort)
|
||||
|
||||
if (isThinkingModel) {
|
||||
// For GLM-4.7, thinking is ON by default in the API.
|
||||
// For GLM thinking models, thinking is ON by default in the API.
|
||||
// We need to explicitly disable it when reasoning is off.
|
||||
const useReasoning = shouldUseReasoningEffort({ model: info, settings: this.options })
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a stream with explicit thinking control for GLM-4.7
|
||||
* Creates a stream with explicit thinking control for GLM thinking models (4.6, 4.6V, 4.7)
|
||||
*/
|
||||
private createStreamWithThinking(
|
||||
systemPrompt: string,
|
||||
|
|
@ -99,7 +99,7 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
|
|||
messages: [{ role: "system", content: systemPrompt }, ...convertedMessages],
|
||||
stream: true,
|
||||
stream_options: { include_usage: true },
|
||||
// For GLM-4.7: thinking is ON by default, so we explicitly disable when needed
|
||||
// For GLM thinking models: thinking is ON by default, so we explicitly disable when needed
|
||||
thinking: useReasoning ? { type: "enabled" } : { type: "disabled" },
|
||||
tools: this.convertToolsForOpenAI(metadata?.tools),
|
||||
tool_choice: metadata?.tool_choice,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue