Skip to content

Commit 0371f34

Browse files
committed
Stop stripping thinkingConfig
Keep generationConfig.thinkingConfig for CloudCode requests so thought parts remain marked as thought instead of collapsing into normal text. Only drop it when thinkingBudget=0 explicitly disables thinking.
1 parent b804a67 commit 0371f34

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

internal/server/gemini_helpers.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ func TransformSSELine(line string) string {
112112

113113
// sanitizeGeminiRequest: minimal shape fixes for CloudCode.
114114
// - Force systemInstruction.role = "system"
115-
// - Strip thinkingConfig entirely (CloudCode doesn't accept it)
116115
func sanitizeGeminiRequest(r *gemini.GeminiInternalRequest, model string) {
117116
if r == nil {
118117
return
@@ -125,9 +124,14 @@ func sanitizeGeminiRequest(r *gemini.GeminiInternalRequest, model string) {
125124
logger.Get().Debug().Msg("Normalized systemInstruction.role to 'system'")
126125
}
127126
}
128-
// Strip thinkingConfig entirely for CloudCode compatibility
127+
// Keep thinkingConfig for newer Gemini models.
128+
// Some models require thinking to be configured (or at least not forcibly disabled),
129+
// and stripping it can cause "thought" parts to be emitted as regular text.
130+
// We only drop it when it is explicitly set to a disabling value.
129131
if r.GenerationConfig != nil && r.GenerationConfig.ThinkingConfig != nil {
130-
r.GenerationConfig.ThinkingConfig = nil
131-
logger.Get().Debug().Msg("Removed thinkingConfig for CloudCode compatibility")
132+
if r.GenerationConfig.ThinkingConfig.ThinkingBudget == 0 {
133+
r.GenerationConfig.ThinkingConfig = nil
134+
logger.Get().Debug().Msg("Removed thinkingConfig with thinkingBudget=0")
135+
}
132136
}
133137
}

0 commit comments

Comments
 (0)