mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-08 02:15:27 +08:00
- Claude 工具定义兼容 input_schema 与 function.parameters - tool_calls 解析增加 thinking 回退与大小写无关工具名匹配 - 补充 claude/util 相关回归测试
30 lines
849 B
Go
30 lines
849 B
Go
package claude
|
|
|
|
import "testing"
|
|
|
|
func TestBuildMessageResponseDetectsToolCallsFromThinkingFallback(t *testing.T) {
|
|
resp := BuildMessageResponse(
|
|
"msg_1",
|
|
"claude-sonnet-4-5",
|
|
[]any{map[string]any{"role": "user", "content": "hi"}},
|
|
`{"tool_calls":[{"name":"search","input":{"q":"go"}}]}`,
|
|
"",
|
|
[]string{"search"},
|
|
)
|
|
|
|
if resp["stop_reason"] != "tool_use" {
|
|
t.Fatalf("expected stop_reason=tool_use, got=%#v", resp["stop_reason"])
|
|
}
|
|
content, _ := resp["content"].([]map[string]any)
|
|
if len(content) < 2 {
|
|
t.Fatalf("expected thinking + tool_use content blocks, got=%#v", resp["content"])
|
|
}
|
|
last := content[len(content)-1]
|
|
if last["type"] != "tool_use" {
|
|
t.Fatalf("expected last content block tool_use, got=%#v", last["type"])
|
|
}
|
|
if last["name"] != "search" {
|
|
t.Fatalf("expected tool name search, got=%#v", last["name"])
|
|
}
|
|
}
|