mirror of
https://github.com/ollama/ollama.git
synced 2025-11-10 20:37:52 +01:00
tools: parse tool calls that don't conform to ("name": name, "arguments": args} (#12738)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user