-
-
Notifications
You must be signed in to change notification settings - Fork 661
fix(translator): preserve built-in tools (web_search) to Responses API #552
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
Closed
XInTheDark
wants to merge
3
commits into
router-for-me:main
from
XInTheDark:fix/builtin-tools-web-search
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -45,6 +45,10 @@ usage-statistics-enabled: false | |
| # Proxy URL. Supports socks5/http/https protocols. Example: socks5://user:[email protected]:1080/ | ||
| proxy-url: "" | ||
|
|
||
| # When true, prepend a default assistant message to /v1/chat/completions requests. | ||
| # Intended for compatibility with copilot-api, where this workaround may avoid rate limiting. | ||
| copilot-unlimited-mode: false | ||
|
|
||
| # Number of times to retry a request. Retries will occur if the HTTP response code is 403, 408, 500, 502, 503, or 504. | ||
| request-retry: 3 | ||
|
|
||
|
|
||
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,84 @@ | ||
| package openai | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers" | ||
| "github.com/router-for-me/CLIProxyAPI/v6/sdk/config" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|
|
||
| func TestPrependAssistantMessage_PrependsForMessagesArray(t *testing.T) { | ||
| in := []byte(`{"model":"gpt-test","messages":[{"role":"user","content":"hi"}]}`) | ||
|
|
||
| out := prependAssistantMessage(in) | ||
| if bytes.Equal(out, in) { | ||
| t.Fatalf("expected payload to change") | ||
| } | ||
|
|
||
| if got := gjson.GetBytes(out, "messages.0.role").String(); got != "assistant" { | ||
| t.Fatalf("messages[0].role = %q, want %q", got, "assistant") | ||
| } | ||
| if got := gjson.GetBytes(out, "messages.0.content").String(); got != "You are helpful assistant" { | ||
| t.Fatalf("messages[0].content = %q, want %q", got, "You are helpful assistant") | ||
| } | ||
| if got := gjson.GetBytes(out, "messages.1.role").String(); got != "user" { | ||
| t.Fatalf("messages[1].role = %q, want %q", got, "user") | ||
| } | ||
| if got := gjson.GetBytes(out, "messages.1.content").String(); got != "hi" { | ||
| t.Fatalf("messages[1].content = %q, want %q", got, "hi") | ||
| } | ||
| if got := gjson.GetBytes(out, "model").String(); got != "gpt-test" { | ||
| t.Fatalf("model = %q, want %q", got, "gpt-test") | ||
| } | ||
|
|
||
| out2 := prependAssistantMessage(out) | ||
| if got, want := len(gjson.GetBytes(out2, "messages").Array()), 2; got != want { | ||
| t.Fatalf("messages length after second prepend = %d, want %d", got, want) | ||
| } | ||
| } | ||
|
|
||
| func TestPrependAssistantMessage_IdempotentWhenAssistantFirst(t *testing.T) { | ||
| in := []byte(`{"messages":[{"role":"assistant","content":"already"},{"role":"user","content":"hi"}]}`) | ||
| out := prependAssistantMessage(in) | ||
| if !bytes.Equal(out, in) { | ||
| t.Fatalf("expected payload to remain unchanged when assistant is already first") | ||
| } | ||
| } | ||
|
|
||
| func TestPrependAssistantMessage_NoMessages_NoChange(t *testing.T) { | ||
| in := []byte(`{"model":"gpt-test"}`) | ||
| out := prependAssistantMessage(in) | ||
| if !bytes.Equal(out, in) { | ||
| t.Fatalf("expected payload to remain unchanged when messages is missing") | ||
| } | ||
| } | ||
|
|
||
| func TestApplyCopilotUnlimitedModeIfEnabled_Guards(t *testing.T) { | ||
| in := []byte(`{"messages":[{"role":"user","content":"hi"}]}`) | ||
|
|
||
| var nilHandler *OpenAIAPIHandler | ||
| if out := nilHandler.applyCopilotUnlimitedModeIfEnabled(in); !bytes.Equal(out, in) { | ||
| t.Fatalf("expected nil handler to return original payload") | ||
| } | ||
|
|
||
| disabled := &OpenAIAPIHandler{ | ||
| BaseAPIHandler: &handlers.BaseAPIHandler{ | ||
| Cfg: &config.SDKConfig{CopilotUnlimitedMode: false}, | ||
| }, | ||
| } | ||
| if out := disabled.applyCopilotUnlimitedModeIfEnabled(in); !bytes.Equal(out, in) { | ||
| t.Fatalf("expected disabled mode to return original payload") | ||
| } | ||
|
|
||
| enabled := &OpenAIAPIHandler{ | ||
| BaseAPIHandler: &handlers.BaseAPIHandler{ | ||
| Cfg: &config.SDKConfig{CopilotUnlimitedMode: true}, | ||
| }, | ||
| } | ||
| out := enabled.applyCopilotUnlimitedModeIfEnabled(in) | ||
| if got := gjson.GetBytes(out, "messages.0.role").String(); got != "assistant" { | ||
| t.Fatalf("messages[0].role = %q, want %q", got, "assistant") | ||
| } | ||
| } |
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.
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.
The error from
sjson.SetRawBytesis silently ignored. While an error here is unlikely, it's good practice to log it for debugging purposes. This would help identify potential issues if the inputrawJSONis malformed in an unexpected way.You will need to import
log "github.com/sirupsen/logrus"to apply this suggestion, which appears to be the standard logger for this project.