feat: gemini thinking_level && snake params - #2274
Conversation
WalkthroughAdded JSON unmarshalling support to GeminiThinkingConfig to handle snake_case field names (include_thoughts, thinking_budget, thinking_level), mapping them to camelCase equivalents during deserialization. Restored and exposed the ThinkingLevel field as json.RawMessage. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
dto/gemini.go (1)
148-177: Add clarification about the purpose of snake_case support.The implementation is correct. However, the web search confirms that the Gemini API itself uses camelCase (includeThoughts, thinkingBudget, thinkingLevel), not snake_case. The snake_case support in this UnmarshalJSON method is for parsing user input or other sources, not for API compatibility.
Consider enhancing the documentation to clarify this purpose:
// UnmarshalJSON allows GeminiThinkingConfig to accept both snake_case and camelCase fields // for flexibility in parsing user input. The Gemini API itself uses camelCase. // When both formats are present, snake_case takes precedence. func (c *GeminiThinkingConfig) UnmarshalJSON(data []byte) error {This clarifies that the dual-format support is a convenience feature, not a requirement for API compatibility.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
dto/gemini.go(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: 9Ninety
Repo: QuantumNous/new-api PR: 1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
📚 Learning: 2025-06-21T03:37:41.726Z
Learnt from: 9Ninety
Repo: QuantumNous/new-api PR: 1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
Applied to files:
dto/gemini.go
🧬 Code graph analysis (1)
dto/gemini.go (1)
common/json.go (1)
Unmarshal(9-11)
| // TODO Conflict with thinkingbudget. | ||
| // ThinkingLevel json.RawMessage `json:"thinkingLevel,omitempty"` | ||
| ThinkingLevel json.RawMessage `json:"thinkingLevel,omitempty"` |
There was a problem hiding this comment.
🧩 Analysis chain
Clarify or resolve the TODO comment.
The TODO comment mentions a "conflict with thinkingbudget" but doesn't explain what the conflict is or how it should be resolved. Since you're exposing the ThinkingLevel field in this PR, please clarify:
- What is the nature of the conflict?
- Are both fields meant to coexist?
- Should this TODO be addressed before merging?
Can you provide more context about this conflict and whether it impacts the functionality?
---
🏁 Script executed:
```shell
#!/bin/bash
# Examine the file structure and context around the TODO comment
echo "=== Lines 140-180 of dto/gemini.go ==="
sed -n '140,180p' dto/gemini.go
echo -e "\n=== Search for 'Thinking' field references ==="
rg -n -i 'thinking' dto/gemini.go | head -20
Length of output: 2231
🏁 Script executed:
#!/bin/bash
# Search for ThinkingBudget field definition
echo "=== All 'ThinkingBudget' occurrences ==="
rg -n 'ThinkingBudget' dto/gemini.go
echo -e "\n=== All 'thinking_budget' occurrences ==="
rg -n 'thinking_budget' dto/gemini.goLength of output: 488
🏁 Script executed:
#!/bin/bash
# Check the GeminiThinkingConfig struct definition
echo "=== GeminiThinkingConfig struct ==="
ast-grep --pattern 'type GeminiThinkingConfig struct { $$$ }'Length of output: 396
🏁 Script executed:
#!/bin/bash
# Search for TODO comments in the file to understand context
echo "=== All TODO comments in dto/gemini.go ==="
rg -n 'TODO' dto/gemini.goLength of output: 85
Clarify the TODO comment on line 144.
The TODO "Conflict with thinkingbudget" is vague and creates ambiguity about whether ThinkingLevel is safe to use. The UnmarshalJSON method shows both fields are intentionally supported, but the comment doesn't explain:
- What the conflict is
- Whether it's already resolved
- Any limitations or considerations for this field
Either resolve the conflict or replace the TODO with a clear comment explaining the design decision and how both fields coexist.
🤖 Prompt for AI Agents
In dto/gemini.go around lines 144 to 145, replace the vague TODO "Conflict with
thinkingbudget" with a clear explanatory comment stating the nature of the
conflict and the chosen design: note that UnmarshalJSON intentionally supports
both ThinkingLevel and ThinkingBudget, specify which field takes precedence when
both are present (or that this is undefined), document any compatibility or
migration behavior (e.g., ThinkingBudget is preferred/legacy, ThinkingLevel
added for new API), and list any limitations (format differences, validation
rules, or future deprecation plans). Update the comment to explain how callers
should set these fields and remove the TODO so future readers understand the
resolved behavior and constraints.
feat: gemini thinking_level && snake params
fix #2273 #2181
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.