-
-
Notifications
You must be signed in to change notification settings - Fork 3k
fix: normalize web_search_preview for codex responses #2223
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 1 commit
be2dd60
8f421de
793840c
d1df70d
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 |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ func ConvertOpenAIResponsesRequestToCodex(modelName string, inputRawJSON []byte, | |
|
|
||
| // Convert role "system" to "developer" in input array to comply with Codex API requirements. | ||
| rawJSON = convertSystemRoleToDeveloper(rawJSON) | ||
| rawJSON = normalizeCodexBuiltinTools(rawJSON) | ||
|
|
||
| return rawJSON | ||
| } | ||
|
|
@@ -82,3 +83,26 @@ func convertSystemRoleToDeveloper(rawJSON []byte) []byte { | |
|
|
||
| return result | ||
| } | ||
|
|
||
| // normalizeCodexBuiltinTools rewrites legacy/preview built-in tool variants to the | ||
| // stable names expected by the current Codex upstream. | ||
| func normalizeCodexBuiltinTools(rawJSON []byte) []byte { | ||
| result := rawJSON | ||
|
|
||
| tools := gjson.GetBytes(result, "tools") | ||
| if tools.IsArray() { | ||
| toolArray := tools.Array() | ||
| for i := 0; i < len(toolArray); i++ { | ||
| typePath := fmt.Sprintf("tools.%d.type", i) | ||
| if gjson.GetBytes(result, typePath).String() == "web_search_preview" { | ||
| result, _ = sjson.SetBytes(result, typePath, "web_search") | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| if gjson.GetBytes(result, "tool_choice.type").String() == "web_search_preview" { | ||
| result, _ = sjson.SetBytes(result, "tool_choice.type", "web_search") | ||
|
||
| } | ||
|
|
||
| return result | ||
| } | ||
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
sjson.SetBytesfunction can return an error, which is currently ignored. While the transformation might be expected to always succeed for valid JSON, explicitly handling potential errors (e.g., logging them or returning the originalrawJSONif an error occurs) would make the function more robust against unexpected input structures. This could prevent silent failures where the normalization doesn't happen as intended.