tools: parse tool calls that don't conform to ("name": name, "arguments": args} (#12738)

This commit is contained in:
frob
2025-10-22 20:34:27 +02:00
committed by GitHub
parent e0ead1adee
commit 0334e67ffd
2 changed files with 39 additions and 17 deletions

View File

@@ -1033,6 +1033,7 @@ func TestFindArguments(t *testing.T) {
name string
buffer []byte
want map[string]any
tool string
}{
{
name: "empty string",
@@ -1290,11 +1291,29 @@ func TestFindArguments(t *testing.T) {
"location": "San Francisco, CA",
},
},
{
name: "simple tool call",
tool: "get_temperature",
buffer: []byte(`{"get_temperature": {"format": "fahrenheit", "location": "San Francisco, CA"}}`),
want: map[string]any{
"format": "fahrenheit",
"location": "San Francisco, CA",
},
},
{
name: "stringified simple tool call",
tool: "get_temperature",
buffer: []byte(`{"get_temperature": "{\"format\": \"fahrenheit\", \"location\": \"San Francisco, CA\"}"}`),
want: map[string]any{
"format": "fahrenheit",
"location": "San Francisco, CA",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, _ := findArguments(tt.buffer)
got, _ := findArguments(&api.Tool{Function: api.ToolFunction{Name: tt.tool}}, tt.buffer)
if diff := cmp.Diff(got, tt.want); diff != "" {
t.Errorf("scanArguments() args mismatch (-got +want):\n%s", diff)