-
-
Notifications
You must be signed in to change notification settings - Fork 729
feat(channel): OpenAI 兼容渠道支持双向推理字段改名开关 #626
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
lianginx
wants to merge
1
commit into
tbphp:main
Choose a base branch
from
lianginx:feat/reasoning-alias
base: main
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.
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
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
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
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,79 @@ | ||
| package channel | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestOpenAICompatibleReasoningAliasParamsNormalizeBothDirections(t *testing.T) { | ||
| registry := NewRegistry() | ||
| cases := []struct { | ||
| name string | ||
| raw string | ||
| key string | ||
| want string | ||
| wantOK bool | ||
| }{ | ||
| { | ||
| name: "request canonical rename direction", | ||
| raw: `{"base_url":"https://example.com/v1","request_reasoning_alias":"reasoning_content_to_reasoning"}`, | ||
| key: "request_reasoning_alias", | ||
| want: "reasoning_content_to_reasoning", | ||
| wantOK: true, | ||
| }, | ||
| { | ||
| name: "request empty stays omitted", | ||
| raw: `{"base_url":"https://example.com/v1","request_reasoning_alias":" "}`, | ||
| key: "request_reasoning_alias", | ||
| want: "", | ||
| wantOK: false, | ||
| }, | ||
| { | ||
| name: "response duplicate accepted", | ||
| raw: `{"base_url":"https://example.com/v1","reasoning_content_alias":"duplicate"}`, | ||
| key: "reasoning_content_alias", | ||
| want: "duplicate", | ||
| wantOK: true, | ||
| }, | ||
| { | ||
| name: "response off kept explicit", | ||
| raw: `{"base_url":"https://example.com/v1","reasoning_content_alias":"off"}`, | ||
| key: "reasoning_content_alias", | ||
| want: "off", | ||
| wantOK: true, | ||
| }, | ||
| } | ||
| for _, test := range cases { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| params, err := registry.ValidateParams(OpenAICompatible, json.RawMessage(test.raw)) | ||
| if err != nil { | ||
| t.Fatalf("ValidateParams error = %v", err) | ||
| } | ||
| got, ok := params.Value(test.key) | ||
| if ok != test.wantOK || got != test.want { | ||
| t.Fatalf("Value(%s) = %q, %t; want %q, %t", test.key, got, ok, test.want, test.wantOK) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestOpenAICompatibleReasoningAliasParamsRejectJunk(t *testing.T) { | ||
| registry := NewRegistry() | ||
| for _, raw := range []string{ | ||
| `{"base_url":"https://example.com/v1","reasoning_content_alias":"maybe"}`, | ||
| `{"base_url":"https://example.com/v1","reasoning_content_alias":"true"}`, | ||
| `{"base_url":"https://example.com/v1","reasoning_content_alias":"reasoning_to_content"}`, | ||
| `{"base_url":"https://example.com/v1","request_reasoning_alias":"content_to_reasoning"}`, | ||
| `{"base_url":"https://example.com/v1","request_reasoning_alias":"duplicate"}`, | ||
| `{"base_url":"https://example.com/v1","request_reasoning_alias":"true"}`, | ||
| `{"base_url":"https://example.com/v1","request_reasoning_alias":"false"}`, | ||
| `{"base_url":"https://example.com/v1","request_reasoning_alias":true}`, | ||
| `{"base_url":"https://example.com/v1","reasoning_content_alias":"reasoning_content_to_reasoningx"}`, | ||
| `{"base_url":"https://example.com/v1","reasoning_content_alias":true}`, | ||
| `{"base_url":"https://example.com/v1","request_reasoning_alias":{"mode":"off"}}`, | ||
| } { | ||
| if _, err := registry.ValidateParams(OpenAICompatible, json.RawMessage(raw)); err == nil { | ||
| t.Fatalf("ValidateParams(%s) error = nil", raw) | ||
| } | ||
| } | ||
| } |
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
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
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: tbphp/gpt-load
Length of output: 14890
🏁 Script executed:
Repository: tbphp/gpt-load
Length of output: 2918
🤖 get_repo_knowledge executed:
get_repo_knowledge tbphp/gpt-load /tmp/coderabbit-repo-knowledge/tbphp-gpt-load-62eb2efe/learningsLength of output: 727
🏁 Script executed:
Repository: tbphp/gpt-load
Length of output: 50371
🏁 Script executed:
Repository: tbphp/gpt-load
Length of output: 50370
🏁 Script executed:
Repository: tbphp/gpt-load
Length of output: 50371
在加载持久化组参数时迁移历史布尔值。
如果启用的历史组参数包含
reasoning_content_alias: true或false,internal/state/loader/loader.go会将row.Params原样传入GroupConfig.Params。随后internal/state/snapshot.go调用Registry.ValidateParams,该验证器要求每个字段值为 JSON 字符串,因此会在执行normalizeReasoningAliasOption前返回must be a string。请在验证前按既定映射转换历史布尔值,并添加加载路径的回归测试。