-
-
Notifications
You must be signed in to change notification settings - Fork 652
fix(translator): preserve built-in tools (web_search) to Responses API #553
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package test | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The added tests are a great start for verifying the new functionality. To make them more robust and prevent future regressions, consider expanding them to cover scenarios with mixed tool types. For both |
||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| _ "github.com/router-for-me/CLIProxyAPI/v6/internal/translator" | ||
|
|
||
| sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|
|
||
| func TestOpenAIToCodex_PreservesBuiltinTools(t *testing.T) { | ||
| in := []byte(`{ | ||
| "model":"gpt-5", | ||
| "messages":[{"role":"user","content":"hi"}], | ||
| "tools":[{"type":"web_search","search_context_size":"high"}], | ||
| "tool_choice":{"type":"web_search"} | ||
| }`) | ||
|
|
||
| out := sdktranslator.TranslateRequest(sdktranslator.FormatOpenAI, sdktranslator.FormatCodex, "gpt-5", in, false) | ||
|
|
||
| if got := gjson.GetBytes(out, "tools.#").Int(); got != 1 { | ||
| t.Fatalf("expected 1 tool, got %d: %s", got, string(out)) | ||
| } | ||
| if got := gjson.GetBytes(out, "tools.0.type").String(); got != "web_search" { | ||
| t.Fatalf("expected tools[0].type=web_search, got %q: %s", got, string(out)) | ||
| } | ||
| if got := gjson.GetBytes(out, "tools.0.search_context_size").String(); got != "high" { | ||
| t.Fatalf("expected tools[0].search_context_size=high, got %q: %s", got, string(out)) | ||
| } | ||
| if got := gjson.GetBytes(out, "tool_choice.type").String(); got != "web_search" { | ||
| t.Fatalf("expected tool_choice.type=web_search, got %q: %s", got, string(out)) | ||
| } | ||
| } | ||
|
|
||
| func TestOpenAIResponsesToOpenAI_PreservesBuiltinTools(t *testing.T) { | ||
| in := []byte(`{ | ||
| "model":"gpt-5", | ||
| "input":[{"role":"user","content":[{"type":"input_text","text":"hi"}]}], | ||
| "tools":[{"type":"web_search","search_context_size":"low"}] | ||
| }`) | ||
|
|
||
| out := sdktranslator.TranslateRequest(sdktranslator.FormatOpenAIResponse, sdktranslator.FormatOpenAI, "gpt-5", in, false) | ||
|
|
||
| if got := gjson.GetBytes(out, "tools.#").Int(); got != 1 { | ||
| t.Fatalf("expected 1 tool, got %d: %s", got, string(out)) | ||
| } | ||
| if got := gjson.GetBytes(out, "tools.0.type").String(); got != "web_search" { | ||
| t.Fatalf("expected tools[0].type=web_search, got %q: %s", got, string(out)) | ||
| } | ||
| if got := gjson.GetBytes(out, "tools.0.search_context_size").String(); got != "low" { | ||
| t.Fatalf("expected tools[0].search_context_size=low, got %q: %s", got, string(out)) | ||
| } | ||
| } | ||
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.
This logic for shortening a tool name appears to be duplicated in a few places in this file (e.g., for handling
tool_callsaround line 208 andtoolsaround line 292). To improve maintainability and reduce code duplication, consider extracting this into a helper function. This would also ensure consistent handling of tool name shortening across different parts of the request translation.