Fix tests

This commit is contained in:
Baptiste Jamin 2026-01-05 12:23:49 +01:00
parent a565013165
commit a9a62a07d6
2 changed files with 17 additions and 5 deletions

View File

@ -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

View File

@ -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"}},
},
},