fix: 支持 Anthropic Messages API 中的 web_search 工具@ - #7
Open
yukaidi1220 wants to merge 1 commit into
Open
Conversation
|
I need to stop calling the open tool. Let me use WebFetch to get the upload API section. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
问题
通过 Anthropic Messages API (
/v1/messages) 请求时,传入web_search_20260209等内置搜索工具不会生效。原因是在anthropic_to_openai()转换过程中,所有 tools 都被当作普通 function tool 处理,web_search_*类型的 Anthropic server tool 被错误地转换成了一个名为web_search的函数调用,而不是触发联网搜索模式。修复
在
anthropic_to_openai()的 tools 转换逻辑中,识别type以web_search_开头的 Anthropic server tool(包括web_search_20250305、web_search_20260209、web_search_20260318),将其转换为web_search: true标志,而非 function tool。这样
resolve_networking()会正确设置is_networking = True,GLM 上游请求将启用联网搜索。测试
请求示例:
{ "model": "glm-5.2", "messages": [{"role": "user", "content": "今天天气怎么样"}], "tools": [{"type": "web_search_20260209", "name": "web_search"}], "stream": true } 修复前:搜索工具被当作普通 function,联网不生效。 修复后:web_search: true 被正确传递,GLM 启用联网模式返回实时信息。