feat(ratio-setting): add compatibility for gemma-4 model suffix handling - #4063
feat(ratio-setting): add compatibility for gemma-4 model suffix handling#4063sxjeru wants to merge 3 commits into
Conversation
WalkthroughA new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
Pull request overview
This PR extends the model-name normalization logic used by ratio/price lookups to handle Gemma 4 “reasoning effort” suffixes (e.g., -minimal, -high) by trimming them to the base model name, improving compatibility with upstream model naming variants.
Changes:
- Add
setting/reasoningdependency to reuse the shared effort-suffix parsing logic. - Update
FormatMatchingModelNameto trim Gemma 4 effort suffixes (viareasoning.TrimEffortSuffix) so ratio matching uses the base model name.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
这个修改的意义是? |
|
贵项目当前已支持 本 pr 应当能让 gemma 4 也支持控制思考参数。 |
|
你这个pr的修改并不能支持后缀控制。 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
setting/ratio_setting/model_ratio.go (1)
726-739: ⚡ Quick winAdd table-driven tests for adapter on/off and suffix trimming cases.
This path is config-gated and easy to regress; a small test matrix would lock behavior down.
✅ Proposed test diff
+// setting/ratio_setting/model_ratio_test.go +package ratio_setting + +import ( + "testing" + + "github.com/QuantumNous/new-api/setting/model_setting" +) + +func TestNormalizeGemma4EffortModelName(t *testing.T) { + gs := model_setting.GetGeminiSettings() + orig := gs.ThinkingAdapterEnabled + defer func() { gs.ThinkingAdapterEnabled = orig }() + + tests := []struct { + name string + enabled bool + input string + expected string + }{ + {"adapter off keeps suffix", false, "gemma-4-26b-it-minimal", "gemma-4-26b-it-minimal"}, + {"adapter on trims suffix", true, "gemma-4-26b-it-minimal", "gemma-4-26b-it"}, + {"adapter on non-effort unchanged", true, "gemma-4-26b-it", "gemma-4-26b-it"}, + {"non-gemma unchanged", true, "gemini-2.5-flash", "gemini-2.5-flash"}, + } + + for _, tt := range tests { + gs.ThinkingAdapterEnabled = tt.enabled + if got := NormalizeGemma4EffortModelName(tt.input); got != tt.expected { + t.Fatalf("%s: got %q, want %q", tt.name, got, tt.expected) + } + } +}Also applies to: 752-752
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@setting/ratio_setting/model_ratio.go` around lines 726 - 739, Add table-driven unit tests for NormalizeGemma4EffortModelName covering combinations of ThinkingAdapterEnabled true/false and model name variants (no gemma prefix, gemma-4 with no suffix, gemma-4 with effort suffixes like -minimal/-high) to ensure suffix trimming only occurs when adapter is enabled; use subtests or a loop with cases that assert expected output from NormalizeGemma4EffortModelName given each input and toggle model_setting.GetGeminiSettings().ThinkingAdapterEnabled accordingly. Also add the same matrix tests for the related function referenced near line 752 (the other Normalize* function that uses reasoning.TrimEffortSuffix) to prevent regressions. Ensure tests restore any global settings after each case to avoid cross-test pollution.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@setting/ratio_setting/model_ratio.go`:
- Around line 726-739: Add table-driven unit tests for
NormalizeGemma4EffortModelName covering combinations of ThinkingAdapterEnabled
true/false and model name variants (no gemma prefix, gemma-4 with no suffix,
gemma-4 with effort suffixes like -minimal/-high) to ensure suffix trimming only
occurs when adapter is enabled; use subtests or a loop with cases that assert
expected output from NormalizeGemma4EffortModelName given each input and toggle
model_setting.GetGeminiSettings().ThinkingAdapterEnabled accordingly. Also add
the same matrix tests for the related function referenced near line 752 (the
other Normalize* function that uses reasoning.TrimEffortSuffix) to prevent
regressions. Ensure tests restore any global settings after each case to avoid
cross-test pollution.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 13eb6fae-a17b-4fd6-b6df-a3f1a381f3fa
📒 Files selected for processing (1)
setting/ratio_setting/model_ratio.go
51fdfc5 to
2b6f1df
Compare

根据 AIS 和相关文档,Gemma 4 已支持通过
thinkingLevel控制思考开关。即使 newapi 支持
gemma-4-26b-a4b-it-minimal。Summary by CodeRabbit