Skip to content

fix(gemini): handle minimal reasoning effort budget - #2460

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/gemini-flash-minial
Dec 26, 2025
Merged

fix(gemini): handle minimal reasoning effort budget#2460
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/gemini-flash-minial

Conversation

@seefs001

@seefs001 seefs001 commented Dec 18, 2025

Copy link
Copy Markdown
Collaborator

#2525

  • Add minimal case to clampThinkingBudgetByEffort to avoid defaulting to full thinking budget

Summary by CodeRabbit

  • New Features

    • Added a new "minimal" thinking budget tier for Gemini models, reducing computational resources to 5% of base budget.
  • Refactor

    • Updated model name suffix handling to recognize and process the new minimal tier option alongside existing effort levels.

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

  - Add minimal case to clampThinkingBudgetByEffort to avoid defaulting to full thinking budget
@coderabbitai

coderabbitai Bot commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes consolidate reasoning effort suffix handling by replacing a local Gemini adapter function with a centralized reasoning.TrimEffortSuffix function that now supports a new "-minimal" effort level. This refactoring affects how upstream model names are parsed to extract effort levels.

Changes

Cohort / File(s) Summary
Gemini adapter refactoring to use centralized suffix parsing
relay/channel/gemini/adaptor.go, relay/channel/gemini/relay-gemini.go
Replaced local parseThinkingLevelSuffix helper function with centralized reasoning.TrimEffortSuffix. Updated adaptor.go to use the new three-value return signature (with ok flag). Removed duplicate helper from relay-gemini.go and simplified ThinkingAdaptor logic to derive ThinkingLevel via the centralized function. Added "minimal" thinking budget tier (5% of base budget).
Reasoning effort suffix extension
setting/reasoning/suffix.go
Added "-minimal" to EffortSuffixes slice, extending recognized suffixes from ["-high", "-medium", "-low"] to ["-high", "-medium", "-low", "-minimal"] and updating TrimEffortSuffix signature to include an ok boolean return value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–12 minutes

  • Verify the new ok flag is handled correctly in both adaptor.go and relay-gemini.go
  • Confirm the minimal budget calculation (5% reduction) is appropriate
  • Ensure the centralized reasoning.TrimEffortSuffix behavior matches prior local function behavior and works consistently across callers

Possibly related PRs

Poem

🐰 Suffixes now dance in a common home,
No more parsing scattered and alone,
Minimal thinking joins the choir so sweet,
Reasoning levels now centralized and neat! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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
Title check ✅ Passed The title clearly and concisely describes the main change: adding support for minimal reasoning effort budget in the Gemini adapter, which aligns with the PR's primary objective.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
relay/channel/gemini/relay-gemini.go (1)

106-114: Latent logic bug: is25FlashLite branch gets overwritten.

The if is25FlashLite block on lines 107-108 sets maxBudget, but then the subsequent if isNew25Pro ... else block on lines 110-114 unconditionally overwrites it (unless isNew25Pro is true). Currently this works by coincidence because flash25LiteMaxBudget == flash25MaxBudget, but if these constants ever diverge, the flash-lite budget will be incorrect.

Apply this diff to use proper else if chaining:

-	maxBudget := 0
-	if is25FlashLite {
-		maxBudget = flash25LiteMaxBudget
-	}
-	if isNew25Pro {
-		maxBudget = pro25MaxBudget
-	} else {
-		maxBudget = flash25MaxBudget
-	}
+	var maxBudget int
+	if is25FlashLite {
+		maxBudget = flash25LiteMaxBudget
+	} else if isNew25Pro {
+		maxBudget = pro25MaxBudget
+	} else {
+		maxBudget = flash25MaxBudget
+	}
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b35ae9f and da24a16.

📒 Files selected for processing (3)
  • relay/channel/gemini/adaptor.go (2 hunks)
  • relay/channel/gemini/relay-gemini.go (3 hunks)
  • setting/reasoning/suffix.go (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 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:

  • relay/channel/gemini/relay-gemini.go
  • relay/channel/gemini/adaptor.go
📚 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:

  • relay/channel/gemini/relay-gemini.go
  • relay/channel/gemini/adaptor.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 (2)
relay/channel/gemini/relay-gemini.go (1)
setting/reasoning/suffix.go (1)
  • TrimEffortSuffix (12-20)
relay/channel/gemini/adaptor.go (1)
setting/reasoning/suffix.go (1)
  • TrimEffortSuffix (12-20)
🔇 Additional comments (5)
setting/reasoning/suffix.go (1)

9-9: LGTM!

The addition of "-minimal" to EffortSuffixes is straightforward and aligns with the new minimal effort level support.

relay/channel/gemini/adaptor.go (2)

16-16: LGTM!

Correctly imports the centralized reasoning package for suffix handling.


141-143: LGTM!

The refactor to use reasoning.TrimEffortSuffix consolidates the suffix parsing logic. The condition properly checks the ok return value before using baseModel.

relay/channel/gemini/relay-gemini.go (2)

101-101: LGTM!

The "minimal" effort level at 5% of max tokens is appropriately documented and implemented. The resulting budget values (e.g., ~1228 tokens for flash models) will still be valid after clamping.

Also applies to: 122-123


184-190: LGTM!

The refactor to use reasoning.TrimEffortSuffix correctly extracts the effort level and sets both ThinkingConfig.ThinkingLevel and info.ReasoningEffort. This now supports the new "-minimal" suffix via the centralized suffix handling.

@Calcium-Ion
Calcium-Ion merged commit 654bb10 into QuantumNous:main Dec 26, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…h-minial

fix(gemini): handle minimal reasoning effort budget
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