fix: 适配claude code调度openai账号的websearch功能

This commit is contained in:
shaw
2026-03-07 11:27:00 +08:00
parent c0c322ba16
commit 6411645ffc
3 changed files with 102 additions and 6 deletions

View File

@@ -325,16 +325,22 @@ func extractAnthropicTextFromBlocks(blocks []AnthropicContentBlock) string {
}
// convertAnthropicToolsToResponses maps Anthropic tool definitions to
// Responses API function tools (input_schema → parameters).
// Responses API tools. Server-side tools like web_search are mapped to their
// OpenAI equivalents; regular tools become function tools.
func convertAnthropicToolsToResponses(tools []AnthropicTool) []ResponsesTool {
out := make([]ResponsesTool, len(tools))
for i, t := range tools {
out[i] = ResponsesTool{
var out []ResponsesTool
for _, t := range tools {
// Anthropic server tools like "web_search_20250305" → OpenAI {"type":"web_search"}
if strings.HasPrefix(t.Type, "web_search") {
out = append(out, ResponsesTool{Type: "web_search"})
continue
}
out = append(out, ResponsesTool{
Type: "function",
Name: t.Name,
Description: t.Description,
Parameters: t.InputSchema,
}
})
}
return out
}