-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(gemini): abort default injection on existing thinking keys #862
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,10 +71,13 @@ func ApplyGeminiThinkingConfig(body []byte, budget *int, includeThoughts *bool) | |
| incl = &defaultInclude | ||
| } | ||
| if incl != nil { | ||
| valuePath := "generationConfig.thinkingConfig.include_thoughts" | ||
| rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | ||
| if err == nil { | ||
| updated = rewritten | ||
| if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() && | ||
| !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() { | ||
| valuePath := "generationConfig.thinkingConfig.include_thoughts" | ||
| rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | ||
| if err == nil { | ||
| updated = rewritten | ||
| } | ||
| } | ||
|
Comment on lines
+74
to
81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic to conditionally set |
||
| } | ||
| return updated | ||
|
|
@@ -99,10 +102,13 @@ func ApplyGeminiCLIThinkingConfig(body []byte, budget *int, includeThoughts *boo | |
| incl = &defaultInclude | ||
| } | ||
| if incl != nil { | ||
| valuePath := "request.generationConfig.thinkingConfig.include_thoughts" | ||
| rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | ||
| if err == nil { | ||
| updated = rewritten | ||
| if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() && | ||
| !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() { | ||
| valuePath := "request.generationConfig.thinkingConfig.include_thoughts" | ||
| rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | ||
| if err == nil { | ||
| updated = rewritten | ||
| } | ||
| } | ||
|
Comment on lines
+105
to
112
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| return updated | ||
|
|
@@ -130,15 +136,15 @@ func ApplyGeminiThinkingLevel(body []byte, level string, includeThoughts *bool) | |
| incl = &defaultInclude | ||
| } | ||
| if incl != nil { | ||
| valuePath := "generationConfig.thinkingConfig.includeThoughts" | ||
| rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | ||
| if err == nil { | ||
| updated = rewritten | ||
| if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() && | ||
| !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() { | ||
| valuePath := "generationConfig.thinkingConfig.includeThoughts" | ||
| rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | ||
| if err == nil { | ||
| updated = rewritten | ||
| } | ||
| } | ||
|
Comment on lines
+139
to
146
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this change correctly avoids overwriting an existing key, it removes the previous (though buggy) attempt at normalization. This function is for Gemini 3 models, which expect |
||
| } | ||
| if it := gjson.GetBytes(body, "generationConfig.thinkingConfig.include_thoughts"); it.Exists() { | ||
| updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.include_thoughts") | ||
| } | ||
| if tb := gjson.GetBytes(body, "generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() { | ||
| updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.thinkingBudget") | ||
| } | ||
|
|
@@ -167,15 +173,15 @@ func ApplyGeminiCLIThinkingLevel(body []byte, level string, includeThoughts *boo | |
| incl = &defaultInclude | ||
| } | ||
| if incl != nil { | ||
| valuePath := "request.generationConfig.thinkingConfig.includeThoughts" | ||
| rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | ||
| if err == nil { | ||
| updated = rewritten | ||
| if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() && | ||
| !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() { | ||
| valuePath := "request.generationConfig.thinkingConfig.includeThoughts" | ||
| rewritten, err := sjson.SetBytes(updated, valuePath, *incl) | ||
| if err == nil { | ||
| updated = rewritten | ||
| } | ||
| } | ||
|
Comment on lines
+176
to
183
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| if it := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.include_thoughts"); it.Exists() { | ||
| updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts") | ||
| } | ||
| if tb := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() { | ||
| updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.thinkingBudget") | ||
| } | ||
|
|
||
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 change correctly prevents overwriting an existing
includeThoughtskey. However, it misses an opportunity for normalization. This function is for models that expectinclude_thoughts(snake_case). If a request containsincludeThoughts(camelCase), this logic allows it to pass through unmodified. The API might ignore this setting if it strictly expects snake_case. It would be more robust to normalize the key toinclude_thoughts.