-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fix(openai-compat): drop top_k for active Claude thinking #5767
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/openai-compat-claude-top-k
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.
+128
−0
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
94 changes: 94 additions & 0 deletions
94
internal/runtime/executor/openai_compat_executor_sampling_test.go
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,94 @@ | ||
| package executor | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| sdktranslator "github.com/router-for-me/CLIProxyAPI/v7/sdk/translator" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|
|
||
| func TestNormalizeOpenAICompatClaudeSampling(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| from sdktranslator.Format | ||
| source string | ||
| translated string | ||
| wantTopK bool | ||
| }{ | ||
| { | ||
| name: "claude adaptive thinking drops top_k", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"thinking":{"type":"adaptive"},"top_k":40}`, | ||
| translated: `{"reasoning_effort":"max","temperature":1,"top_k":40}`, | ||
| }, | ||
| { | ||
| name: "claude enabled thinking drops top_k", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"thinking":{"type":"enabled","budget_tokens":1024},"top_k":40}`, | ||
| translated: `{"reasoning_effort":"low","top_k":40}`, | ||
| }, | ||
| { | ||
| name: "claude effort activates thinking after translation and drops top_k", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"output_config":{"effort":"max"},"top_k":40}`, | ||
| translated: `{"reasoning_effort":"max","top_k":40}`, | ||
| }, | ||
| { | ||
| name: "translated reasoning effort drops top_k", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"messages":[],"top_k":40}`, | ||
| translated: `{"reasoning_effort":"high","top_k":40}`, | ||
| }, | ||
| { | ||
| name: "claude auto thinking drops top_k", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"thinking":{"type":"auto"},"top_k":40}`, | ||
| translated: `{"top_k":40}`, | ||
| }, | ||
| { | ||
| name: "claude reasoning effort drops top_k", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"reasoning":{"effort":"high"},"top_k":40}`, | ||
| translated: `{"top_k":40}`, | ||
| }, | ||
| { | ||
| name: "explicit none effort keeps top_k", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"output_config":{"effort":"none"},"top_k":40}`, | ||
| translated: `{"reasoning_effort":"none","top_k":40}`, | ||
| wantTopK: true, | ||
| }, | ||
| { | ||
| name: "translated active effort overrides source disabled sentinel", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"thinking":{"type":"disabled"},"top_k":40}`, | ||
| translated: `{"reasoning_effort":"high","top_k":40}`, | ||
| }, | ||
| { | ||
| name: "claude without thinking keeps top_k", | ||
| from: sdktranslator.FormatClaude, | ||
| source: `{"messages":[]}`, | ||
| translated: `{"top_k":40}`, | ||
| wantTopK: true, | ||
| }, | ||
| { | ||
| name: "non-claude source keeps top_k", | ||
| from: sdktranslator.FormatOpenAI, | ||
| source: `{"thinking":{"type":"adaptive"}}`, | ||
| translated: `{"top_k":40}`, | ||
| wantTopK: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := normalizeOpenAICompatClaudeSampling([]byte(tt.translated), []byte(tt.source), tt.from) | ||
| if exists := gjson.GetBytes(got, "top_k").Exists(); exists != tt.wantTopK { | ||
| t.Fatalf("top_k exists = %v, want %v; body=%s", exists, tt.wantTopK, got) | ||
| } | ||
| if temperature := gjson.GetBytes(got, "temperature"); temperature.Exists() && temperature.Int() != 1 { | ||
| t.Fatalf("temperature changed unexpectedly: body=%s", got) | ||
| } | ||
| }) | ||
| } | ||
| } |
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 Claude request initially enables thinking but a model suffix such as
(none)or a payload override disables it,ApplyRequestThinkingand the override stage produce a final non-thinking request, yet this switch still marks thinking active from the pre-override source and deletestop_k. This silently changes a valid sampling configuration even though the upstream-invalid combination no longer exists; determine activity from the finalized canonical/transformed body so the established suffix and override precedence is preserved.AGENTS.md reference: AGENTS.md:L29-L29
Useful? React with 👍 / 👎.