History

Merge pull request #862 from router-for-me/gemini

fix(gemini): abort default injection on existing thinking keys

Luis Pater committed 10 months agov6.6.84

Commit e124db72 parents 8edbda5 05444cf1 file · +28 −22Browse files

Unified · Split

internal/util/gemini_thinking.go+28−22
@@ -71,10 +71,13 @@ func ApplyGeminiThinkingConfig(body []byte, budget *int, includeThoughts *bool) · 70 unmodified lines
7171 incl = &defaultInclude
7272 }
7373 if incl != nil {
74− valuePath := "generationConfig.thinkingConfig.include_thoughts"
75− rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
76− if err == nil {
77− updated = rewritten
74+ if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() &&
75+ !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() {
76+ valuePath := "generationConfig.thinkingConfig.include_thoughts"
77+ rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
78+ if err == nil {
79+ updated = rewritten
80+ }
7881 }
7982 }
8083 return updated
@@ -99,10 +102,13 @@ func ApplyGeminiCLIThinkingConfig(body []byte, budget *int, includeThoughts *boo · 18 unmodified lines
99102 incl = &defaultInclude
100103 }
101104 if incl != nil {
102− valuePath := "request.generationConfig.thinkingConfig.include_thoughts"
103− rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
104− if err == nil {
105− updated = rewritten
105+ if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() &&
106+ !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() {
107+ valuePath := "request.generationConfig.thinkingConfig.include_thoughts"
108+ rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
109+ if err == nil {
110+ updated = rewritten
111+ }
106112 }
107113 }
108114 return updated
@@ -130,15 +136,15 @@ func ApplyGeminiThinkingLevel(body []byte, level string, includeThoughts *bool) · 21 unmodified lines
130136 incl = &defaultInclude
131137 }
132138 if incl != nil {
133− valuePath := "generationConfig.thinkingConfig.includeThoughts"
134− rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
135− if err == nil {
136− updated = rewritten
139+ if !gjson.GetBytes(updated, "generationConfig.thinkingConfig.includeThoughts").Exists() &&
140+ !gjson.GetBytes(updated, "generationConfig.thinkingConfig.include_thoughts").Exists() {
141+ valuePath := "generationConfig.thinkingConfig.includeThoughts"
142+ rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
143+ if err == nil {
144+ updated = rewritten
145+ }
137146 }
138147 }
139− if it := gjson.GetBytes(body, "generationConfig.thinkingConfig.include_thoughts"); it.Exists() {
140− updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.include_thoughts")
141− }
142148 if tb := gjson.GetBytes(body, "generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() {
143149 updated, _ = sjson.DeleteBytes(updated, "generationConfig.thinkingConfig.thinkingBudget")
144150 }
@@ -167,15 +173,15 @@ func ApplyGeminiCLIThinkingLevel(body []byte, level string, includeThoughts *boo · 22 unmodified lines
167173 incl = &defaultInclude
168174 }
169175 if incl != nil {
170− valuePath := "request.generationConfig.thinkingConfig.includeThoughts"
171− rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
172− if err == nil {
173− updated = rewritten
176+ if !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.includeThoughts").Exists() &&
177+ !gjson.GetBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts").Exists() {
178+ valuePath := "request.generationConfig.thinkingConfig.includeThoughts"
179+ rewritten, err := sjson.SetBytes(updated, valuePath, *incl)
180+ if err == nil {
181+ updated = rewritten
182+ }
174183 }
175184 }
176− if it := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.include_thoughts"); it.Exists() {
177− updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.include_thoughts")
178− }
179185 if tb := gjson.GetBytes(body, "request.generationConfig.thinkingConfig.thinkingBudget"); tb.Exists() {
180186 updated, _ = sjson.DeleteBytes(updated, "request.generationConfig.thinkingConfig.thinkingBudget")
181187 }