Skip to content

Commit

Permalink
Correct tools
Browse files Browse the repository at this point in the history
  • Loading branch information
aymeric-roucher committed Jul 8, 2024
1 parent 42cd4ab commit 50cad81
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 140 deletions.
15 changes: 9 additions & 6 deletions src/transformers/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def add_tool(self, tool: Tool):
The tool to add to the toolbox.
"""
if tool.name in self._tools:
raise KeyError(f"Error: tool {tool.name} already exists in the toolbox.")
raise KeyError(f"Error: tool '{tool.name}' already exists in the toolbox.")
self._tools[tool.name] = tool

def remove_tool(self, tool_name: str):
Expand Down Expand Up @@ -621,6 +621,7 @@ def run(self, task: str, return_generated_code: bool = False, **kwargs):
output = self.python_evaluator(
code_action,
available_tools,
custom_tools={},
state=self.state,
authorized_imports=self.authorized_imports,
)
Expand Down Expand Up @@ -976,11 +977,9 @@ def __init__(
self.python_evaluator = evaluate_python_code
self.additional_authorized_imports = additional_authorized_imports if additional_authorized_imports else []
self.authorized_imports = list(set(LIST_SAFE_MODULES) | set(self.additional_authorized_imports))
print(self.authorized_imports)
self.system_prompt = self.system_prompt.replace("<<authorized_imports>>", str(self.authorized_imports))
self.available_tools = {
**BASE_PYTHON_TOOLS.copy(),
**self.toolbox.tools,
} # This list can be augmented by the code agent creating some new functions
self.custom_tools = {}

def step(self):
"""
Expand Down Expand Up @@ -1032,7 +1031,11 @@ def step(self):
try:
result = self.python_evaluator(
code_action,
tools=self.available_tools,
tools={
**BASE_PYTHON_TOOLS.copy(),
**self.toolbox.tools,
},
custom_tools=self.custom_tools,
state=self.state,
authorized_imports=self.authorized_imports,
)
Expand Down
Loading

0 comments on commit 50cad81

Please sign in to comment.