mirror of
https://github.com/ollama/ollama.git
synced 2025-11-11 14:56:45 +01:00
tools: return empty arguments object instead of null (#11113)
This commit is contained in:
@@ -115,11 +115,10 @@ func (p *Parser) findTag() (int, bool) {
|
|||||||
// parseToolCall finds the next complete tool call in the buffer
|
// parseToolCall finds the next complete tool call in the buffer
|
||||||
// incrementing n and advancing the buffer.
|
// incrementing n and advancing the buffer.
|
||||||
func (p *Parser) parseToolCall() *api.ToolCall {
|
func (p *Parser) parseToolCall() *api.ToolCall {
|
||||||
var args map[string]any
|
|
||||||
var tool *api.Tool
|
var tool *api.Tool
|
||||||
var end int = len(p.buffer)
|
var end int = len(p.buffer)
|
||||||
|
|
||||||
var i int
|
var i int
|
||||||
|
|
||||||
// find tool name
|
// find tool name
|
||||||
for _, t := range p.tools {
|
for _, t := range p.tools {
|
||||||
n := t.Function.Name
|
n := t.Function.Name
|
||||||
@@ -136,6 +135,7 @@ func (p *Parser) parseToolCall() *api.ToolCall {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// only look for arguments if the tool has parameters
|
// only look for arguments if the tool has parameters
|
||||||
|
args := map[string]any{}
|
||||||
if len(tool.Function.Parameters.Properties) > 0 {
|
if len(tool.Function.Parameters.Properties) > 0 {
|
||||||
if args, i = p.findArguments(*tool); args == nil {
|
if args, i = p.findArguments(*tool); args == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ func TestParser(t *testing.T) {
|
|||||||
Function: api.ToolCallFunction{
|
Function: api.ToolCallFunction{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Name: "say_hello",
|
Name: "say_hello",
|
||||||
|
Arguments: api.ToolCallFunctionArguments{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -267,6 +268,7 @@ func TestParser(t *testing.T) {
|
|||||||
Function: api.ToolCallFunction{
|
Function: api.ToolCallFunction{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Name: "say_hello",
|
Name: "say_hello",
|
||||||
|
Arguments: api.ToolCallFunctionArguments{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -415,6 +417,7 @@ func TestParser(t *testing.T) {
|
|||||||
Function: api.ToolCallFunction{
|
Function: api.ToolCallFunction{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Name: "say_hello",
|
Name: "say_hello",
|
||||||
|
Arguments: api.ToolCallFunctionArguments{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -443,6 +446,7 @@ func TestParser(t *testing.T) {
|
|||||||
Function: api.ToolCallFunction{
|
Function: api.ToolCallFunction{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Name: "say_hello",
|
Name: "say_hello",
|
||||||
|
Arguments: api.ToolCallFunctionArguments{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -579,6 +583,7 @@ func TestParser(t *testing.T) {
|
|||||||
Function: api.ToolCallFunction{
|
Function: api.ToolCallFunction{
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Name: "say_hello",
|
Name: "say_hello",
|
||||||
|
Arguments: api.ToolCallFunctionArguments{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user