diff --git a/openai/openai.go b/openai/openai.go index 6a1b54928..9d0f95e0c 100644 --- a/openai/openai.go +++ b/openai/openai.go @@ -156,7 +156,19 @@ func (tc *ToolChoice) IsRequired() bool { // IsAuto returns true if tool_choice is "auto" or not specified func (tc *ToolChoice) IsAuto() bool { - return tc == nil || tc.Mode == "" || tc.Mode == "auto" + if tc == nil { + return true + } + // If there's an object, check if it's allowed_tools with auto mode + if tc.Object != nil { + // allowed_tools with "auto" mode is still considered auto + if tc.Object.Type == "allowed_tools" && (tc.Object.Mode == "" || tc.Object.Mode == "auto") { + return true + } + // Any other object (forced function, allowed_tools with required) is not auto + return false + } + return tc.Mode == "" || tc.Mode == "auto" } // IsForcedFunction returns true if a specific function is forced diff --git a/openai/openai_test.go b/openai/openai_test.go index b551058e6..850a017d8 100644 --- a/openai/openai_test.go +++ b/openai/openai_test.go @@ -646,7 +646,7 @@ func TestApplyToolChoice(t *testing.T) { Description: "Get weather", Parameters: api.ToolFunctionParameters{ Type: "object", - Properties: map[string]api.Property{ + Properties: map[string]api.ToolProperty{ "location": {Type: []string{"string"}}, }, Required: []string{"location"}, @@ -660,7 +660,7 @@ func TestApplyToolChoice(t *testing.T) { Description: "Search the web", Parameters: api.ToolFunctionParameters{ Type: "object", - Properties: map[string]api.Property{ + Properties: map[string]api.ToolProperty{ "query": {Type: []string{"string"}}, }, Required: []string{"query"}, @@ -806,7 +806,7 @@ func TestFromChatRequest_WithToolChoice(t *testing.T) { Description: "Get weather", Parameters: api.ToolFunctionParameters{ Type: "object", - Properties: map[string]api.Property{ + Properties: map[string]api.ToolProperty{ "location": {Type: []string{"string"}}, }, }, @@ -819,7 +819,7 @@ func TestFromChatRequest_WithToolChoice(t *testing.T) { Description: "Search", Parameters: api.ToolFunctionParameters{ Type: "object", - Properties: map[string]api.Property{ + Properties: map[string]api.ToolProperty{ "query": {Type: []string{"string"}}, }, },