Fix Gemini API additionalProperties error (issue #2457)

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-03-24 11:32:29 +00:00
parent ed1f009c64
commit 3060c6f919
3 changed files with 61 additions and 2 deletions

View File

@@ -25,7 +25,7 @@ def schema_class():
return TestSchema
class InternalCrewStructuredTool:
class TestInternalCrewStructuredTool:
def test_initialization(self, basic_function, schema_class):
"""Test basic initialization of CrewStructuredTool"""
tool = CrewStructuredTool(
@@ -144,3 +144,30 @@ class InternalCrewStructuredTool:
{"required_param": "test", "optional_param": "custom", "nullable_param": 42}
)
assert result == "test custom 42"
def test_to_openai_function_no_additional_properties(self):
"""Test that the to_openai_function method doesn't include additionalProperties."""
class TestSchema(BaseModel):
test_field: str = Field(..., description="A test field")
def test_func(test_field: str) -> str:
"""Test function that returns the input."""
return f"Test function received: {test_field}"
tool = CrewStructuredTool(
name="test_tool",
description="A test tool",
args_schema=TestSchema,
func=test_func
)
function_dict = tool.to_openai_function()
assert "additionalProperties" not in function_dict["function"]["parameters"]
# Verify other properties are correct
assert function_dict["type"] == "function"
assert function_dict["function"]["name"] == "test_tool"
assert function_dict["function"]["description"] == "A test tool"
assert "properties" in function_dict["function"]["parameters"]
assert "test_field" in function_dict["function"]["parameters"]["properties"]