From 6a4d3eb2698a2fee500e1833be1cd05a05868906 Mon Sep 17 00:00:00 2001 From: Brandon Hancock Date: Thu, 9 Jan 2025 12:44:22 -0500 Subject: [PATCH] add back in support for add_image --- src/crewai/crew.py | 2 +- src/crewai/tools/tool_usage.py | 12 ++++++++++++ src/crewai/translations/en.json | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/crewai/crew.py b/src/crewai/crew.py index 2f0c68862..5df5f59d7 100644 --- a/src/crewai/crew.py +++ b/src/crewai/crew.py @@ -47,7 +47,7 @@ from crewai.utilities.formatter import ( aggregate_raw_outputs_from_task_outputs, aggregate_raw_outputs_from_tasks, ) -from crewai.utilities.llm_utils import create_llm # Ensure this import is present +from crewai.utilities.llm_utils import create_llm from crewai.utilities.planning_handler import CrewPlanner from crewai.utilities.task_output_storage_handler import TaskOutputStorageHandler from crewai.utilities.training_handler import CrewTrainingHandler diff --git a/src/crewai/tools/tool_usage.py b/src/crewai/tools/tool_usage.py index d818cf3ae..a08410dd6 100644 --- a/src/crewai/tools/tool_usage.py +++ b/src/crewai/tools/tool_usage.py @@ -114,6 +114,18 @@ 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 + try: + result = self._use(tool_string=tool_string, tool=tool, calling=calling) + return result + + except Exception as e: + error = getattr(e, "message", str(e)) + self.task.increment_tools_errors() + if self.agent.verbose: + self._printer.print(content=f"\n\n{error}\n", color="red") + return error + return f"{self._use(tool_string=tool_string, tool=tool, calling=calling)}" def _use( diff --git a/src/crewai/translations/en.json b/src/crewai/translations/en.json index a67b4e21b..8b1ca0700 100644 --- a/src/crewai/translations/en.json +++ b/src/crewai/translations/en.json @@ -9,7 +9,7 @@ "task": "\nCurrent Task: {input}\n\nBegin! This is VERY important to you, use the tools available and give your best Final Answer, your job depends on it!\n\nThought:", "memory": "\n\n# Useful context: \n{memory}", "role_playing": "You are {role}. {backstory}\nYour personal goal is: {goal}", - "tools": "\nYou ONLY have access to the following tools, and should NEVER make up tools that are not listed here:\n\n{tools}\n\nIMPORTANT: Use the following format in your response:\n\n```\nThought: you should always think about what to do\nAction: the action to take, only one name of [{tool_names}], just the name, exactly as it's written.\nAction Input: the input to the action, just a simple JSON object, enclosed in curly braces, using \" to wrap keys and values.\nObservation: the result of the action\n```\n\nOnce all necessary information is gathered return the following format:\n\n```\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n```", + "tools": "\nYou ONLY have access to the following tools, and should NEVER make up tools that are not listed here:\n\n{tools}\n\nIMPORTANT: Use the following format in your response:\n\n```\nThought: you should always think about what to do\nAction: the action to take, only one name of [{tool_names}], just the name, exactly as it's written.\nAction Input: the input to the action, just a simple JSON object, enclosed in curly braces, using \" to wrap keys and values.\nObservation: the result of the action\n```\n\nOnce all necessary information is gathered, return the following format:\n\n```\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n```", "no_tools": "\nTo give my best complete final answer to the task respond using the exact following format:\n\nThought: I now can give a great answer\nFinal Answer: Your final answer must be the great and the most complete as possible, it must be outcome described.\n\nI MUST use these formats, my job depends on it!", "format": "I MUST either use a tool (use one at time) OR give my best final answer not both at the same time. When responding, I must use the following format:\n\n```\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action, dictionary enclosed in curly braces\nObservation: the result of the action\n```\nThis Thought/Action/Action Input/Result can repeat N times. Once I know the final answer, I must return the following format:\n\n```\nThought: I now can give a great answer\nFinal Answer: Your final answer must be the great and the most complete as possible, it must be outcome described\n\n```", "final_answer_format": "If you don't need to use any more tools, you must give your best complete final answer, make sure it satisfies the expected criteria, use the EXACT format below:\n\n```\nThought: I now can give a great answer\nFinal Answer: my best complete final answer to the task.\n\n```",