NayukiChiba
8353fe1608
fix(anthropic): Anthropic API tool_choice schema conversion (#8328)
* fix(anthropic): 修复 Anthropic API tool_choice 格式转换及参数支持
- 将 tool_choice 从简单的 auto/required 逻辑改为遵循 Anthropic API 规范,支持 auto/any/none/tool 四种原生值
- 兼容 OpenAI 风格的 tool_choice="required",自动映射为 {"type": "any"}
- 允许直接传入 dict 类型的 tool_choice 以实现指定工具调用
- 更新 text_chat 和 stream_chat 入口的参数类型标注,扩大可接收的 tool_choice 类型
- 新增 tool_choice 格式转换的单元测试,覆盖各类输入场景
Closes #8319
* Clean up test cases and remove unused mocks
Removed unused mock classes and tests for tool_choice conversion.
* fix(anthropic): 修复 Anthropic API tool_choice="tool" 参数处理及重构格式转换逻辑
- 提取静态方法 _normalize_tool_choice 统一处理 tool_choice 格式转换,消除重复代码
- 处理字符串 "tool" 值时,因无法指定具体工具名而回退为 auto 并记录警告,避免无效请求
- 在 _query 和 _stream_query 中采用默认值 auto 并应用规范化逻辑,确保一致性
* test(anthropic): 添加空工具集时跳过工具参数设置的测试
- 新增 _EmptyToolSet 模拟类,模拟无工具场景
- 新增测试用例 test_tool_choice_empty_tool_list_skips_tool_choice
- 验证当 ToolSet 存在但工具列表为空时,请求不包含 tools 和 tool_choice 参数
- 完善边缘情况测试覆盖,确保与现有逻辑一致
* style: ruff 格式化一下
---------
Co-authored-by: Weilong Liao <37870767+Soulter@users.noreply.github.com>
2026-05-30 13:44:45 +08:00
..
2026-05-19 09:38:55 +08:00
2026-05-04 20:15:21 +08:00
2026-04-19 14:18:16 +08:00
2026-05-29 00:54:36 +08:00
2026-02-23 23:35:15 +08:00
2026-05-30 13:44:45 +08:00
2026-05-12 23:46:57 +08:00
2026-04-08 11:35:59 +08:00
2026-03-14 23:41:28 +08:00
2026-05-14 01:13:46 +08:00
2026-05-21 21:37:10 +08:00
2026-02-19 01:26:04 +08:00
2026-05-03 16:37:36 +08:00
2026-05-03 16:37:36 +08:00
2026-04-11 17:01:54 +08:00
2026-05-03 22:11:24 +08:00
2026-04-13 12:47:27 +09:00
2026-05-29 01:02:51 +08:00
2026-04-13 12:47:27 +09:00
2026-04-13 12:47:27 +09:00
2026-05-15 18:43:21 +08:00
2026-05-12 23:57:16 +08:00
2026-05-20 14:38:16 +08:00
2026-03-29 00:03:05 +08:00
2026-03-28 21:31:52 +09:00
2026-05-12 23:46:57 +08:00
2026-05-15 13:00:26 +08:00
2026-04-11 17:01:54 +08:00
2026-03-11 23:58:28 +09:00
2026-05-14 09:00:16 +08:00
2026-04-06 18:27:28 +08:00
2026-05-27 21:36:22 +08:00
2026-02-11 17:14:47 +08:00
2026-04-11 17:01:54 +08:00
2026-04-30 10:53:34 +08:00
2026-04-10 17:08:10 +09:00
2026-04-28 21:10:19 +09:00
2026-05-11 16:36:03 +08:00
2026-05-13 14:38:11 +08:00
2026-02-12 23:42:29 +09:00
2026-03-07 21:42:56 +09:00
2026-04-29 10:26:20 +08:00
2026-03-22 14:23:21 +08:00
2026-05-03 16:37:36 +08:00
2026-03-01 00:06:04 +08:00
2026-03-23 09:33:37 +08:00
2026-04-12 13:42:51 +08:00
2026-02-12 01:04:48 +08:00
2026-04-22 11:38:40 +08:00
2026-05-07 09:41:45 +09:00
2026-05-15 13:00:26 +08:00
2026-03-21 20:44:36 +08:00