mirror of
https://github.com/ollama/ollama.git
synced 2025-11-13 05:06:52 +01:00
Merge pull request #12621 from ollama/drifkin/any-of
qwen3-coder: support anyOf when parsing tool calls
This commit is contained in:
@@ -276,7 +276,14 @@ func parseToolCall(raw qwenEventRawToolCall, tools []api.Tool) (api.ToolCall, er
|
|||||||
var paramType api.PropertyType
|
var paramType api.PropertyType
|
||||||
if matchedTool != nil && matchedTool.Function.Parameters.Properties != nil {
|
if matchedTool != nil && matchedTool.Function.Parameters.Properties != nil {
|
||||||
if prop, ok := matchedTool.Function.Parameters.Properties[parameter.Name]; ok {
|
if prop, ok := matchedTool.Function.Parameters.Properties[parameter.Name]; ok {
|
||||||
paramType = prop.Type
|
// Handle anyOf by collecting all types from the union
|
||||||
|
if len(prop.AnyOf) > 0 {
|
||||||
|
for _, anyOfProp := range prop.AnyOf {
|
||||||
|
paramType = append(paramType, anyOfProp.Type...)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
paramType = prop.Type
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -977,6 +977,21 @@ func TestQwenToolCallValueParsing(t *testing.T) {
|
|||||||
raw: "123",
|
raw: "123",
|
||||||
want: 123, // Integer has higher precedence than string
|
want: 123, // Integer has higher precedence than string
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "anyOf array or string - with array of objects",
|
||||||
|
paramType: api.PropertyType{"array", "string"},
|
||||||
|
raw: `[{"content": "task 1", "status": "pending", "priority": "high", "id": "1"}, {"content": "task 2", "status": "completed", "priority": "low", "id": "2"}]`,
|
||||||
|
want: []any{
|
||||||
|
map[string]any{"content": "task 1", "status": "pending", "priority": "high", "id": "1"},
|
||||||
|
map[string]any{"content": "task 2", "status": "completed", "priority": "low", "id": "2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "anyOf array or string - with plain string",
|
||||||
|
paramType: api.PropertyType{"array", "string"},
|
||||||
|
raw: "Error: could not load data",
|
||||||
|
want: "Error: could not load data",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
|||||||
Reference in New Issue
Block a user