-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fix(thinking): normalize disabled level-only models #5768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smartershining
wants to merge
1
commit into
router-for-me:dev
Choose a base branch
from
smartershining:fix/thinking-disabled-level-only
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package openai | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/router-for-me/CLIProxyAPI/v7/internal/registry" | ||
| "github.com/router-for-me/CLIProxyAPI/v7/internal/thinking" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|
|
||
| func TestApplyLevelFallbackAfterDisabledThinking(t *testing.T) { | ||
| model := ®istry.ModelInfo{ | ||
| ID: "openrouter-3o", | ||
| Thinking: ®istry.ThinkingSupport{ | ||
| Levels: []string{"max", "xhigh", "high", "medium", "low"}, | ||
| }, | ||
| } | ||
| config, err := thinking.ValidateConfig( | ||
| thinking.ThinkingConfig{Mode: thinking.ModeNone}, model, "claude", "openai", false, | ||
| ) | ||
| if err != nil { | ||
| t.Fatalf("ValidateConfig() error = %v", err) | ||
| } | ||
| body, err := NewApplier().Apply( | ||
| []byte(`{"messages":[{"role":"user","content":"hi"}]}`), *config, model, | ||
| ) | ||
| if err != nil { | ||
| t.Fatalf("Apply() error = %v", err) | ||
| } | ||
| if got := gjson.GetBytes(body, "reasoning_effort").String(); got != "low" { | ||
| t.Fatalf("reasoning_effort = %q, want low; body=%s", got, body) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package thinking | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/router-for-me/CLIProxyAPI/v7/internal/registry" | ||
| log "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| func TestValidateConfigDisabledLevelOnlyUsesLowestWithoutBudgetWarning(t *testing.T) { | ||
| previousOutput := log.StandardLogger().Out | ||
| previousLevel := log.GetLevel() | ||
| var output bytes.Buffer | ||
| log.SetOutput(&output) | ||
| log.SetLevel(log.WarnLevel) | ||
| t.Cleanup(func() { | ||
| log.SetOutput(previousOutput) | ||
| log.SetLevel(previousLevel) | ||
| }) | ||
|
|
||
| model := ®istry.ModelInfo{ | ||
| ID: "openrouter-3o", | ||
| Thinking: ®istry.ThinkingSupport{ | ||
| Levels: []string{"max", "xhigh", "high", "medium", "low"}, | ||
| }, | ||
| } | ||
| got, err := ValidateConfig(ThinkingConfig{Mode: ModeNone}, model, "claude", "openai", false) | ||
| if err != nil { | ||
| t.Fatalf("ValidateConfig() error = %v", err) | ||
| } | ||
| if got.Mode != ModeLevel || got.Budget != 0 || got.Level != LevelLow { | ||
| t.Fatalf("ValidateConfig() = %+v, want ModeLevel low with zero budget", got) | ||
| } | ||
| if strings.Contains(output.String(), "budget zero not allowed") { | ||
| t.Fatalf("disabled level-only thinking emitted a misleading warning: %s", output.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestValidateConfigDisabledHybridKeepsBudgetFallback(t *testing.T) { | ||
| model := ®istry.ModelInfo{ | ||
| ID: "hybrid-model", | ||
| Thinking: ®istry.ThinkingSupport{ | ||
| Min: 1024, Max: 32768, Levels: []string{"low", "high"}, | ||
| }, | ||
| } | ||
| got, err := ValidateConfig(ThinkingConfig{Mode: ModeNone}, model, "claude", "gemini", false) | ||
| if err != nil { | ||
| t.Fatalf("ValidateConfig() error = %v", err) | ||
| } | ||
| if got.Mode != ModeNone || got.Budget != 1024 || got.Level != LevelLow { | ||
| t.Fatalf("ValidateConfig() = %+v, want prior hybrid fallback budget 1024 and level low", got) | ||
| } | ||
| } | ||
|
|
||
| func TestValidateConfigDisabledLevelOnlyKeepsSupportedNoneWithoutBudgetWarning(t *testing.T) { | ||
| previousOutput := log.StandardLogger().Out | ||
| previousLevel := log.GetLevel() | ||
| var output bytes.Buffer | ||
| log.SetOutput(&output) | ||
| log.SetLevel(log.WarnLevel) | ||
| t.Cleanup(func() { | ||
| log.SetOutput(previousOutput) | ||
| log.SetLevel(previousLevel) | ||
| }) | ||
|
|
||
| model := ®istry.ModelInfo{ | ||
| ID: "level-model-with-none", | ||
| Thinking: ®istry.ThinkingSupport{ | ||
| Levels: []string{"high", "none", "low"}, | ||
| }, | ||
| } | ||
| got, err := ValidateConfig(ThinkingConfig{Mode: ModeNone}, model, "claude", "openai", false) | ||
| if err != nil { | ||
| t.Fatalf("ValidateConfig() error = %v", err) | ||
| } | ||
| if got.Mode != ModeNone || got.Budget != 0 || got.Level != "" { | ||
| t.Fatalf("ValidateConfig() = %+v, want unchanged disabled mode", got) | ||
| } | ||
| if strings.Contains(output.String(), "budget zero not allowed") { | ||
| t.Fatalf("supported disabled thinking emitted a misleading warning: %s", output.String()) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a configured level-only model advertises only a provider-specific effort such as
Levels: []string{"ultra"},clampLevel(LevelMinimal, ...)ignores every unrecognized level and returnsminimal, even though that value is not supported. Because this fallback is generated after level validation, the provider applier sends the invalid effort upstream; preserve an advertised fallback or validate the generated level before returning.AGENTS.md reference: AGENTS.md:L25-L29
Useful? React with 👍 / 👎.