Skip to content

fix(adaptor): fix reasoning suffix not processing in vertex adapter - #2388

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
FirstMelody:main
Dec 8, 2025
Merged

seefs001 merged 1 commit into
QuantumNous:mainfrom
FirstMelody:main

Conversation

@FirstMelody

@FirstMelody FirstMelody commented Dec 7, 2025 •

Copy link
Copy Markdown

暂时写了一个改动,应该是可以 Fixes #2386 暂未测试 测试完成后再跟进评论

Summary by CodeRabbit

  • Improvements
    • Enhanced model variant handling to properly recognize and process different model configuration types, improving request accuracy for specialized model versions.

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

@coderabbitai

coderabbitai Bot commented Dec 7, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds effort-based suffix stripping to the Vertex channel adapter's Gemini model name handling using reasoning.TrimEffortSuffix() to normalize model names and extract thinking budget parameters before constructing upstream requests.

Changes

Cohort / File(s) Summary
Vertex Adaptor Enhancement
relay/channel/vertex/adaptor.go
Adds reasoning package import and integrates reasoning.TrimEffortSuffix() to strip effort-based suffixes (e.g., -low, -medium, -high) from Gemini model names, extracting base model and budget level for proper upstream URL construction

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Areas requiring attention:

  • Verify that reasoning.TrimEffortSuffix() correctly parses and returns base model and level values for all supported suffix formats
  • Confirm the logic properly handles edge cases (empty suffixes, malformed inputs, models without suffixes)
  • Ensure normalized model names are correctly propagated to downstream URL construction

Possibly related PRs

Poem

🐰 A suffix stripped with reasoning's might,
Vertex channels now parse Gemini right,
No more 404s in the night! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing reasoning suffix handling in the Vertex adapter, which directly aligns with the changeset.
Linked Issues check ✅ Passed The code change adds reasoning suffix trimming to the Vertex adapter, directly addressing issue #2386's requirement to handle model suffixes in the Vertex channel like the Gemini adapter does.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing reasoning suffix handling in the Vertex adapter as required by issue #2386; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b9f6a5 and 121746a.

📒 Files selected for processing (1)
  • relay/channel/vertex/adaptor.go (2 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-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/vertex/adaptor.go
📚 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/vertex/adaptor.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/vertex/adaptor.go
🧬 Code graph analysis (1)
relay/channel/vertex/adaptor.go (1)
setting/reasoning/suffix.go (1)
  • TrimEffortSuffix (12-20)
🔇 Additional comments (2)
relay/channel/vertex/adaptor.go (2)

20-20: LGTM!

The import is correctly added and necessary for the effort suffix handling logic.


185-187: The effort suffix handling is correct and safe—no downstream issues found.

The implementation properly strips effort suffixes (-high, -medium, -low) from model names without conflicting with existing thinking-related patterns. The Gemini adapter correctly uses OriginModelName for its thinking configuration logic, and the extracted level value is intentionally not stored here (reasoning effort is handled separately via the ReasoningEffort request field).

The condition level != "" is redundant since ok == true guarantees level is non-empty based on the TrimEffortSuffix implementation, which always returns a non-empty level string when a suffix match is found.


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.

@FirstMelody

Copy link
Copy Markdown
Author

时间受限 仅单元测试发现对有-thinking-关键词的模型可能会有错误截断问题 这个问题同样存在于 Gemini Adapter 考虑到与本PR无关 不再变动

@FirstMelody

Copy link
Copy Markdown
Author
83a6f55f9d6420e5719c1ecf46f0eb1a 修复有效

@seefs001
seefs001 merged commit 7b108a6 into QuantumNous:main Dec 8, 2025
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
fix(adaptor): fix reasoning suffix not processing in vertex adapter
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
fix(adaptor): fix reasoning suffix not processing in vertex adapter
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
fix(adaptor): fix reasoning suffix not processing in vertex adapter
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.

[报告问题] Vertex渠道没有thinking_budget替换

2 participants