From ef65174df23fb2efb499a18d7071348cc0ec58da Mon Sep 17 00:00:00 2001 From: Tom Sheffler Date: Wed, 9 Apr 2025 17:45:49 -0700 Subject: [PATCH] types: include the 'items' and '$defs' fields to properly handle "array" types (#10091) --------- Co-authored-by: Parth Sareen --- api/types.go | 4 ++++ openai/openai_test.go | 4 ++++ server/routes_generate_test.go | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/api/types.go b/api/types.go index 4e8486acf..53a9593e5 100644 --- a/api/types.go +++ b/api/types.go @@ -163,6 +163,7 @@ func (t *ToolCallFunctionArguments) String() string { type Tool struct { Type string `json:"type"` + Items any `json:"items,omitempty"` Function ToolFunction `json:"function"` } @@ -213,9 +214,12 @@ type ToolFunction struct { Description string `json:"description"` Parameters struct { Type string `json:"type"` + Defs any `json:"$defs,omitempty"` + Items any `json:"items,omitempty"` Required []string `json:"required"` Properties map[string]struct { Type PropertyType `json:"type"` + Items any `json:"items,omitempty"` Description string `json:"description"` Enum []any `json:"enum,omitempty"` } `json:"properties"` diff --git a/openai/openai_test.go b/openai/openai_test.go index 46fce7c8d..a24093ad7 100644 --- a/openai/openai_test.go +++ b/openai/openai_test.go @@ -281,9 +281,12 @@ func TestChatMiddleware(t *testing.T) { Description: "Get the current weather", Parameters: struct { Type string `json:"type"` + Defs any `json:"$defs,omitempty"` + Items any `json:"items,omitempty"` Required []string `json:"required"` Properties map[string]struct { Type api.PropertyType `json:"type"` + Items any `json:"items,omitempty"` Description string `json:"description"` Enum []any `json:"enum,omitempty"` } `json:"properties"` @@ -292,6 +295,7 @@ func TestChatMiddleware(t *testing.T) { Required: []string{"location"}, Properties: map[string]struct { Type api.PropertyType `json:"type"` + Items any `json:"items,omitempty"` Description string `json:"description"` Enum []any `json:"enum,omitempty"` }{ diff --git a/server/routes_generate_test.go b/server/routes_generate_test.go index 00a50cc3d..56121d41b 100644 --- a/server/routes_generate_test.go +++ b/server/routes_generate_test.go @@ -370,9 +370,12 @@ func TestGenerateChat(t *testing.T) { Description: "Get the current weather", Parameters: struct { Type string `json:"type"` + Defs any `json:"$defs,omitempty"` + Items any `json:"items,omitempty"` Required []string `json:"required"` Properties map[string]struct { Type api.PropertyType `json:"type"` + Items any `json:"items,omitempty"` Description string `json:"description"` Enum []any `json:"enum,omitempty"` } `json:"properties"` @@ -381,6 +384,7 @@ func TestGenerateChat(t *testing.T) { Required: []string{"location"}, Properties: map[string]struct { Type api.PropertyType `json:"type"` + Items any `json:"items,omitempty"` Description string `json:"description"` Enum []any `json:"enum,omitempty"` }{ @@ -467,9 +471,12 @@ func TestGenerateChat(t *testing.T) { Description: "Get the current weather", Parameters: struct { Type string `json:"type"` + Defs any `json:"$defs,omitempty"` + Items any `json:"items,omitempty"` Required []string `json:"required"` Properties map[string]struct { Type api.PropertyType `json:"type"` + Items any `json:"items,omitempty"` Description string `json:"description"` Enum []any `json:"enum,omitempty"` } `json:"properties"` @@ -478,6 +485,7 @@ func TestGenerateChat(t *testing.T) { Required: []string{"location"}, Properties: map[string]struct { Type api.PropertyType `json:"type"` + Items any `json:"items,omitempty"` Description string `json:"description"` Enum []any `json:"enum,omitempty"` }{