Improve code with type hints, error handling, and additional tests

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

View File

@@ -171,3 +171,28 @@ class TestInternalCrewStructuredTool:
assert function_dict["function"]["description"] == "A test tool"
assert "properties" in function_dict["function"]["parameters"]
assert "test_field" in function_dict["function"]["parameters"]["properties"]
def test_to_openai_function_edge_cases(self):
"""Test edge cases for to_openai_function conversion."""
class EmptySchema(BaseModel):
pass
def empty_func() -> None:
pass
tool = CrewStructuredTool(
name="empty_tool",
description="A tool with empty schema",
args_schema=EmptySchema,
func=empty_func
)
function_dict = tool.to_openai_function()
assert function_dict["type"] == "function"
assert function_dict["function"]["name"] == "empty_tool"
# Check that parameters contains the expected fields
params = function_dict["function"]["parameters"]
assert params["title"] == "EmptySchema"
assert params["type"] == "object"
assert "properties" in params # Empty schema still has a properties field