Repository navigation
feat: gemini 3 thinking level gemini-3-pro-preview-high - #2344
Conversation
WalkthroughThis PR extends Gemini model name parsing to support effort-level suffixes (-low, -medium, -high) as an alternative to thinking-budget parameters. It introduces a new suffix-extraction utility, updates the DTO's ThinkingLevel field type from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
dto/gemini.go (1)
106-124: Fix JSON shape detection in GetTools (currently never detects arrays correctly)
GetToolsis usingstrings.HasSuffix(string(r.Tools), "[")to decide whethertoolsis an array, but valid JSON arrays start with[and end with]. As written, neither arrays ([...]) nor objects ({...}) will be classified correctly unless the raw string literally ends with[.This means tool payloads won’t be parsed at all in normal cases. You can make this robust by trimming whitespace, early‑returning on empty/null, and checking the prefix:
func (r *GeminiChatRequest) GetTools() []GeminiChatTool { - var tools []GeminiChatTool - if strings.HasSuffix(string(r.Tools), "[") { - // is array - if err := common.Unmarshal(r.Tools, &tools); err != nil { - logger.LogError(nil, "error_unmarshalling_tools: "+err.Error()) - return nil - } - } else if strings.HasPrefix(string(r.Tools), "{") { + var tools []GeminiChatTool + raw := strings.TrimSpace(string(r.Tools)) + if raw == "" || raw == "null" { + return nil + } + + if strings.HasPrefix(raw, "[") { + // is array + if err := common.Unmarshal(r.Tools, &tools); err != nil { + logger.LogError(nil, "error_unmarshalling_tools: "+err.Error()) + return nil + } + } else if strings.HasPrefix(raw, "{") { // is object singleTool := GeminiChatTool{} - if err := common.Unmarshal(r.Tools, &singleTool); err != nil { + if err := common.Unmarshal(r.Tools, &singleTool); err != nil { logger.LogError(nil, "error_unmarshalling_single_tool: "+err.Error()) return nil } tools = []GeminiChatTool{singleTool} } return tools }This keeps existing unmarshalling behavior while fixing detection for both array and object shapes and handling empty/null safely.
🧹 Nitpick comments (1)
web/src/i18n/locales/en.json (1)
1999-1999: Reasoning-suffix English string is correct; consider slightly clearer wordingThe updated text correctly reflects support for
-thinking,-thinking-budget<number>,-nothinking, and-low/-medium/-high. If you want it a bit clearer for admins, something like “Support-thinking,-thinking-budget<number>,-nothinking, and-low/-medium/-highsuffixes” reads more naturally, but the current wording is acceptable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
README.en.md(1 hunks)README.fr.md(1 hunks)README.ja.md(1 hunks)README.md(1 hunks)dto/gemini.go(2 hunks)relay/channel/gemini/adaptor.go(1 hunks)relay/channel/gemini/relay-gemini.go(3 hunks)setting/model_setting/global.go(1 hunks)setting/ratio_setting/model_ratio.go(2 hunks)setting/reasoning/suffix.go(1 hunks)web/src/i18n/locales/en.json(2 hunks)web/src/i18n/locales/fr.json(2 hunks)web/src/i18n/locales/ja.json(2 hunks)web/src/i18n/locales/ru.json(2 hunks)web/src/i18n/locales/vi.json(2 hunks)web/src/i18n/locales/zh.json(2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 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.
Learnt from: neotf
Repo: QuantumNous/new-api PR: 1511
File: setting/ratio_setting/model_ratio.go:118-123
Timestamp: 2025-08-05T17:14:17.246Z
Learning: Claude models handle "-thinking" variants differently from Gemini models. For Claude models, only the base model (without "-thinking") gets an entry in defaultModelRatio map. The "-thinking" variants rely on the Claude relay handler stripping the suffix using strings.TrimSuffix(textRequest.Model, "-thinking") before looking up the ratio, so they automatically use the base model's ratio.
📚 Learning: 2025-08-05T17:14:17.246Z
Learnt from: neotf
Repo: QuantumNous/new-api PR: 1511
File: setting/ratio_setting/model_ratio.go:118-123
Timestamp: 2025-08-05T17:14:17.246Z
Learning: Claude models handle "-thinking" variants differently from Gemini models. For Claude models, only the base model (without "-thinking") gets an entry in defaultModelRatio map. The "-thinking" variants rely on the Claude relay handler stripping the suffix using strings.TrimSuffix(textRequest.Model, "-thinking") before looking up the ratio, so they automatically use the base model's ratio.
Applied to files:
setting/model_setting/global.goREADME.ja.mdrelay/channel/gemini/relay-gemini.gorelay/channel/gemini/adaptor.goREADME.en.mdsetting/ratio_setting/model_ratio.goREADME.md
📚 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:
README.ja.mdrelay/channel/gemini/relay-gemini.gorelay/channel/gemini/adaptor.goREADME.en.mdsetting/ratio_setting/model_ratio.goREADME.mddto/gemini.go
📚 Learning: 2025-08-08T17:12:43.157Z
Learnt from: RedwindA
Repo: QuantumNous/new-api PR: 1537
File: relay/gemini_handler.go:330-342
Timestamp: 2025-08-08T17:12:43.157Z
Learning: In the new-api repository, the `GeminiEmbeddingHandler` function in `relay/gemini_handler.go` is designed specifically for native Gemini embedding requests and therefore does not require the `ConvertGeminiRequest` step that is used in the chat handler. The embedding requests are already in the native Gemini format and don't need conversion.
Applied to files:
relay/channel/gemini/relay-gemini.go
📚 Learning: 2025-08-21T06:31:11.073Z
Learnt from: jiajunly
Repo: QuantumNous/new-api PR: 1629
File: relay/channel/openai/relay-openai.go:170-174
Timestamp: 2025-08-21T06:31:11.073Z
Learning: In relay/channel/openai/relay-openai.go, the streaming logic for the AddThinkFirst feature is designed so that only the first chunk of a stream gets the "<think>\n" prefix. The final flush in the streaming handler intentionally uses addThink=false because the last chunk should never receive the prefix, even in single-chunk streams where the prefix would have been applied during normal processing.
Applied to files:
relay/channel/gemini/relay-gemini.go
🧬 Code graph analysis (3)
relay/channel/gemini/relay-gemini.go (2)
setting/reasoning/suffix.go (1)
TrimEffortSuffix(12-20)dto/gemini.go (1)
GeminiThinkingConfig(141-146)
setting/ratio_setting/model_ratio.go (1)
setting/reasoning/suffix.go (1)
TrimEffortSuffix(12-20)
dto/gemini.go (2)
dto/openai_image.go (2)
Alias(47-47)Alias(67-67)relay/common/relay_info.go (1)
Alias(510-510)
🪛 LanguageTool
README.fr.md
[typographical] ~237-~237: Caractère d’apostrophe incorrect.
Context: ...s pouvez également ajouter les suffixes -low, -medium ou -high aux modèles Gemin...
(APOS_INCORRECT)
🔇 Additional comments (18)
web/src/i18n/locales/ru.json (1)
2020-2020: Translation update correctly reflects new suffix groups.The Russian translation on line 2020 has been appropriately updated to include
-low/-medium/-highsuffixes alongside the existing-thinking,-thinking-бюджетные-цифры, and-nothinkingsuffixes. The grammar and punctuation (using "и" for conjunction) are correct, and the translation accurately conveys the expanded suffix support consistent with the PR's objective to add effort-level suffixes to Gemini model name parsing.web/src/i18n/locales/fr.json (1)
2009-2009: Localization update properly extends French description for new Gemini effort-level suffixes.The French translation correctly extends the existing suffix description to include support for the new
-low,-medium, and-higheffort-level suffixes. The format and terminology align with other language localizations mentioned in the PR summary.README.md (1)
242-242: Documentation of new Gemini effort-level suffix support looks good.The addition accurately describes the new capability and correctly notes that the effort-level suffixes eliminate the need for separate thinking-budget suffixes. The language is clear and consistent with other sections.
README.ja.md (1)
246-246: Japanese documentation of new Gemini effort-level suffix support is clear and accurate.The addition correctly explains the new capability in Japanese and maintains consistency with the English, Chinese, and French documentation. The phrasing accurately conveys that effort-level suffixes eliminate the need for separate thinking-budget parameters.
web/src/i18n/locales/vi.json (1)
2200-2200: Vietnamese translation update for effort-level suffix support is accurate.The addition correctly extends the Vietnamese translation to include the new -low/-medium/-high suffixes. The phrasing "và -low/-medium/-high" (and -low/-medium/-high) is grammatically correct and consistent with the pattern of updates across other language locales.
web/src/i18n/locales/ja.json (1)
1906-1910: JA translations for reasoning suffixes and sync-channel selection look goodThe updated suffix description correctly reflects support for
-thinking,-thinking-予算数値,-nothinking, and-low/-medium/-high, and “同期チャネルを選択” matches the source string and existing terminology for channels in this locale.setting/model_setting/global.go (1)
35-35: Comment update correctly reflects expanded set of reasoning suffixesThe doc comment now mentioning
thinking/-nothinking/-low/-high/-mediummatches how this flag is used to control suffix preservation for configured models; implementation remains consistent with the documented behavior.dto/gemini.go (1)
141-175: ThinkingLevel as string with snake_case support is reasonable; please verify external payload expectationsSwitching
GeminiThinkingConfig.ThinkingLevel(and the aux field) fromjson.RawMessagetostring, plus the customUnmarshalJSONthat accepts boththinkingLevelandthinking_level, makes the field easier to use with the new-low/-medium/-highsemantics and keeps the code paths straightforward.The only behavioral change to watch for is that non-string JSON values for
thinkingLevel(e.g., numbers or objects, if any clients ever sent them) will now fail to unmarshal instead of being accepted as opaque JSON. If your API surface guarantees this is always a string, this is fine; otherwise it’s worth double-checking docs and any known producers before merging.web/src/i18n/locales/zh.json (1)
1987-1987: LGTM! Translation update aligns with new suffix support.The Chinese translation correctly documents the extended suffix support (-low, -medium, -high) alongside existing -thinking and -nothinking suffixes.
setting/reasoning/suffix.go (2)
9-9: LGTM! Clear suffix definition.The exported
EffortSuffixesvariable provides a centralized list of supported thinking effort levels. The variable is appropriately exported for use across packages.
11-20: LGTM! Clean suffix extraction logic.The function correctly:
- Searches for effort-level suffixes using
lo.Find- Returns the base model name and extracted level
- Handles the no-match case appropriately
The implementation assumes model names won't naturally end with
-high,-medium, or-lowas part of their identifier (which is reasonable given current Gemini naming patterns).README.en.md (1)
241-241: LGTM! Clear documentation of new suffix feature.The documentation accurately describes the new effort-level suffix support for Gemini models, making it clear to users that they can append
-low,-medium, or-highwithout needing explicit thinking-budget parameters.setting/ratio_setting/model_ratio.go (2)
10-10: LGTM! Required import for suffix utilities.The import of the reasoning package is necessary for the new suffix-stripping logic in
FormatMatchingModelName.
825-827: LGTM! Correct placement of effort suffix normalization.The suffix stripping logic is correctly placed:
- After gemini-2.5 thinking-budget wildcard handling (lines 817-823)
- Before gpt-4-gizmo wildcard handling (lines 829-834)
This ordering ensures that:
- Models like
gemini-2.5-flash-highare normalized togemini-2.5-flash- Thinking-budget patterns (e.g.,
-thinking-1024) take precedence over effort suffixes- The normalized names can be matched against default ratio/price entries
relay/channel/gemini/adaptor.go (1)
140-141: LGTM! Consistent suffix handling for effort levels.The new else-if branch correctly:
- Detects and strips effort-level suffixes using
parseThinkingLevelSuffix- Updates
UpstreamModelNameto the base model name for the upstream API call- Follows the same pattern as existing suffix handling (-thinking, -nothinking)
- Is appropriately placed as the final suffix check in the conditional chain
relay/channel/gemini/relay-gemini.go (3)
22-22: LGTM! Required import for reasoning utilities.The import is necessary for the new
parseThinkingLevelSuffixhelper function.
125-131: LGTM! Clean wrapper for suffix extraction.The helper function appropriately wraps
reasoning.TrimEffortSuffix, converting the 3-value return to a 2-value return. Callers can checklevel != ""to determine if a suffix was found, which is slightly more concise than checking a boolean.
189-194: LGTM! Correct integration of effort-level suffix handling.The new else-if branch appropriately:
- Detects effort-level suffixes using
parseThinkingLevelSuffix- Configures
ThinkingConfigwith the extracted level ("high", "medium", or "low")- Sets
IncludeThoughts: trueto enable thinking output- Propagates the effort level to
info.ReasoningEffortfor downstream useThis implementation treats
ThinkingLevelas an alternative toThinkingBudget, allowing users to specify effort levels via model name suffixes rather than explicit budget values.
| - `gemini-2.5-flash-nothinking` - Désactiver le mode de pensée | ||
| - `gemini-2.5-pro-thinking` - Activer le mode de pensée | ||
| - `gemini-2.5-pro-thinking-128` - Activer le mode de pensée avec budget de pensée de 128 tokens | ||
| - Vous pouvez également ajouter les suffixes `-low`, `-medium` ou `-high` aux modèles Gemini pour fixer le niveau d’effort de raisonnement (sans suffixe de budget supplémentaire). |
There was a problem hiding this comment.
Fix the apostrophe character in the French text.
The static analysis tool flagged an incorrect apostrophe character on this line. Please verify and correct it to use the proper Unicode apostrophe (') instead of a straight quote character.
🧰 Tools
🪛 LanguageTool
[typographical] ~237-~237: Caractère d’apostrophe incorrect.
Context: ...s pouvez également ajouter les suffixes -low, -medium ou -high aux modèles Gemin...
(APOS_INCORRECT)
🤖 Prompt for AI Agents
In README.fr.md around line 237, the French text uses an incorrect straight
quote character for the apostrophe; replace the incorrect character with the
proper typographic apostrophe (U+2019, ’) so the sentence reads correctly (e.g.,
change "d’effort" to use the U+2019 apostrophe), saving the file with UTF-8
encoding.
…king-level feat: gemini 3 thinking level gemini-3-pro-preview-high
…king-level feat: gemini 3 thinking level gemini-3-pro-preview-high
…king-level feat: gemini 3 thinking level gemini-3-pro-preview-high
Summary by CodeRabbit
New Features
Documentation
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.