From 79e428aff8712dcf8590618aca391565c9a52666 Mon Sep 17 00:00:00 2001 From: theCyberTech <84775494+theCyberTech@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:04:47 +0800 Subject: [PATCH] refactor: improve code readability and update model schema access in tool_usage.py - Reformatted the OPENAI_BIGGER_MODELS list for better readability. - Updated the method for accessing the model schema in ToolUsage class to use model_json_schema() instead of schema(). - Enhanced conditional formatting for clarity in the add_image tool check. These changes aim to enhance maintainability and clarity of the code. --- src/crewai/tools/tool_usage.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/crewai/tools/tool_usage.py b/src/crewai/tools/tool_usage.py index 532587ced..e0b7abd76 100644 --- a/src/crewai/tools/tool_usage.py +++ b/src/crewai/tools/tool_usage.py @@ -19,7 +19,15 @@ try: import agentops # type: ignore except ImportError: agentops = None -OPENAI_BIGGER_MODELS = ["gpt-4", "gpt-4o", "o1-preview", "o1-mini", "o1", "o3", "o3-mini"] +OPENAI_BIGGER_MODELS = [ + "gpt-4", + "gpt-4o", + "o1-preview", + "o1-mini", + "o1", + "o3", + "o3-mini", +] class ToolUsageErrorException(Exception): @@ -104,7 +112,10 @@ class ToolUsage: self._printer.print(content=f"\n\n{error}\n", color="red") return error - if isinstance(tool, CrewStructuredTool) and tool.name == self._i18n.tools("add_image")["name"]: # type: ignore + if ( + isinstance(tool, CrewStructuredTool) + and tool.name == self._i18n.tools("add_image")["name"] + ): # type: ignore try: result = self._use(tool_string=tool_string, tool=tool, calling=calling) return result @@ -169,7 +180,7 @@ class ToolUsage: if calling.arguments: try: - acceptable_args = tool.args_schema.schema()["properties"].keys() # type: ignore # Item "None" of "type[BaseModel] | None" has no attribute "schema" + acceptable_args = tool.args_schema.model_json_schema()["properties"].keys() # type: ignore # Item "None" of "type[BaseModel] | None" has no attribute "schema" arguments = { k: v for k, v in calling.arguments.items()