Skip to content

feat: gemini 3 thinking level gemini-3-pro-preview-high - #2344

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/gemini-thinking-level
Dec 2, 2025
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/gemini-thinking-level

Conversation

@seefs001

@seefs001 seefs001 commented Dec 1, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added support for reasoning effort control via model name suffixes (-low, -medium, -high) for Gemini models, eliminating the need for separate configuration parameters.
  • Documentation

    • Updated README files and UI translations across multiple languages to document the new reasoning effort suffix capability.
  • Refactor

    • Refactored internal handling of reasoning configuration for improved suffix processing.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 1, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This 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 json.RawMessage to string, integrates suffix parsing into the request relay pipeline, normalizes model names during ratio matching, and updates multilingual documentation and UI strings to reflect the new capability.

Changes

Cohort / File(s) Summary
New Reasoning Suffix Support
setting/reasoning/suffix.go
Introduces TrimEffortSuffix() function and EffortSuffixes variable to detect and extract effort-level suffixes (-low, -medium, -high) from model names.
Gemini DTO and Channel Updates
dto/gemini.go, relay/channel/gemini/relay-gemini.go, relay/channel/gemini/adaptor.go
Changes ThinkingLevel field type from json.RawMessage to string. Adds parseThinkingLevelSuffix() helper and extends ThinkingAdaptor control flow to detect and configure thinking levels from model name suffixes. Updates adaptor to handle suffix-based thinking level parsing.
Model Name Normalization
setting/model_setting/global.go, setting/ratio_setting/model_ratio.go
Updates ShouldPreserveThinkingSuffix comment to include new suffixes. Applies TrimEffortSuffix() in FormatMatchingModelName for consistent model name matching before ratio lookup.
Documentation and Internationalization
README.md, README.en.md, README.fr.md, README.ja.md, web/src/i18n/locales/... (en.json, fr.json, ja.json, ru.json, vi.json, zh.json)
Updates README files and all locale files to document that Gemini model names can be suffixed with -low/-medium/-high to control reasoning effort without needing additional thinking-budget parameters.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Type change in dto/gemini.go: Verify that changing ThinkingLevel from json.RawMessage to string correctly handles JSON unmarshalling for all input formats.
  • Suffix extraction logic: Ensure TrimEffortSuffix() correctly identifies and strips suffixes across all callsites without unintended side effects.
  • Control flow branching: Review interaction between the new parseThinkingLevelSuffix path and existing -thinking/-nothinking handling paths in relay-gemini.go to confirm no conflicts or missed cases.
  • Model name normalization: Confirm that stripping effort suffixes in FormatMatchingModelName before ratio matching doesn't break existing price-lookup patterns.

Possibly related PRs

Suggested reviewers

  • xyfacai

Poem

🐰 A Gemini hops with newfound grace,
Wearing suffixes (-low, -medium, -high) in place,
No more budget strings to encode,
The reasoning effort flows down the code,
One name, one effort, one clear way ahead!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly refers to the main feature: support for Gemini 3 thinking levels via suffixes like -high, -medium, -low, which is comprehensively implemented across code and documentation.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

GetTools is using strings.HasSuffix(string(r.Tools), "[") to decide whether tools is 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 wording

The 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 / -high suffixes” reads more naturally, but the current wording is acceptable.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36a739e and b6a02d8.

📒 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.go
  • README.ja.md
  • relay/channel/gemini/relay-gemini.go
  • relay/channel/gemini/adaptor.go
  • README.en.md
  • setting/ratio_setting/model_ratio.go
  • README.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.md
  • relay/channel/gemini/relay-gemini.go
  • relay/channel/gemini/adaptor.go
  • README.en.md
  • setting/ratio_setting/model_ratio.go
  • README.md
  • dto/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/-high suffixes alongside the existing -thinking, -thinking-бюджетные-цифры, and -nothinking suffixes. 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 -high effort-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 good

The 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 suffixes

The doc comment now mentioning thinking/-nothinking/-low/-high/-medium matches 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 expectations

Switching GeminiThinkingConfig.ThinkingLevel (and the aux field) from json.RawMessage to string, plus the custom UnmarshalJSON that accepts both thinkingLevel and thinking_level, makes the field easier to use with the new -low/-medium/-high semantics 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 EffortSuffixes variable 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 -low as 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 -high without 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:

  1. After gemini-2.5 thinking-budget wildcard handling (lines 817-823)
  2. Before gpt-4-gizmo wildcard handling (lines 829-834)

This ordering ensures that:

  • Models like gemini-2.5-flash-high are normalized to gemini-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 UpstreamModelName to 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 parseThinkingLevelSuffix helper 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 check level != "" 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 ThinkingConfig with the extracted level ("high", "medium", or "low")
  • Sets IncludeThoughts: true to enable thinking output
  • Propagates the effort level to info.ReasoningEffort for downstream use

This implementation treats ThinkingLevel as an alternative to ThinkingBudget, allowing users to specify effort levels via model name suffixes rather than explicit budget values.

Comment thread README.fr.md
- `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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

@Calcium-Ion
Calcium-Ion merged commit ffc45a7 into QuantumNous:main Dec 2, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Feb 6, 2026
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…king-level

feat: gemini 3 thinking level gemini-3-pro-preview-high
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…king-level

feat: gemini 3 thinking level gemini-3-pro-preview-high
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…king-level

feat: gemini 3 thinking level gemini-3-pro-preview-high
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants