mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
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.
This commit is contained in:
@@ -19,7 +19,15 @@ try:
|
|||||||
import agentops # type: ignore
|
import agentops # type: ignore
|
||||||
except ImportError:
|
except ImportError:
|
||||||
agentops = None
|
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):
|
class ToolUsageErrorException(Exception):
|
||||||
@@ -104,7 +112,10 @@ class ToolUsage:
|
|||||||
self._printer.print(content=f"\n\n{error}\n", color="red")
|
self._printer.print(content=f"\n\n{error}\n", color="red")
|
||||||
return error
|
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:
|
try:
|
||||||
result = self._use(tool_string=tool_string, tool=tool, calling=calling)
|
result = self._use(tool_string=tool_string, tool=tool, calling=calling)
|
||||||
return result
|
return result
|
||||||
@@ -169,7 +180,7 @@ class ToolUsage:
|
|||||||
|
|
||||||
if calling.arguments:
|
if calling.arguments:
|
||||||
try:
|
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 = {
|
arguments = {
|
||||||
k: v
|
k: v
|
||||||
for k, v in calling.arguments.items()
|
for k, v in calling.arguments.items()
|
||||||
|
|||||||
Reference in New Issue
Block a user