Unverified Commit c4c5a4a0 authored by Parth Sareen's avatar Parth Sareen Committed by GitHub
Browse files

types: send index for tool calls (#12625)

parent 3dcfd5f6
...@@ -204,7 +204,7 @@ type ToolCall struct { ...@@ -204,7 +204,7 @@ type ToolCall struct {
} }
type ToolCallFunction struct { type ToolCallFunction struct {
Index int `json:"index,omitempty"` Index int `json:"index"`
Name string `json:"name"` Name string `json:"name"`
Arguments ToolCallFunctionArguments `json:"arguments"` Arguments ToolCallFunctionArguments `json:"arguments"`
} }
......
...@@ -298,6 +298,30 @@ func TestToolFunction_UnmarshalJSON(t *testing.T) { ...@@ -298,6 +298,30 @@ func TestToolFunction_UnmarshalJSON(t *testing.T) {
} }
} }
func TestToolCallFunction_IndexAlwaysMarshals(t *testing.T) {
fn := ToolCallFunction{
Name: "echo",
Arguments: ToolCallFunctionArguments{"message": "hi"},
}
data, err := json.Marshal(fn)
require.NoError(t, err)
raw := map[string]any{}
require.NoError(t, json.Unmarshal(data, &raw))
require.Contains(t, raw, "index")
assert.Equal(t, float64(0), raw["index"])
fn.Index = 3
data, err = json.Marshal(fn)
require.NoError(t, err)
raw = map[string]any{}
require.NoError(t, json.Unmarshal(data, &raw))
require.Contains(t, raw, "index")
assert.Equal(t, float64(3), raw["index"])
}
func TestPropertyType_UnmarshalJSON(t *testing.T) { func TestPropertyType_UnmarshalJSON(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment