f"The code blob you used is invalid: due to the following error: {e}. This means that the regex pattern {pattern} was not respected. Make sure to correct its formatting. Code blob was: {code_blob}"
f"""
The code blob you used is invalid: due to the following error: {e}
This means that the regex pattern {pattern} was not respected: make sure to include code with the correct pattern, for instance:
}# This list can be augmented by the code agent creating some new functions
defstep(self):
defstep(self):
"""
"""
...
@@ -911,7 +1053,11 @@ class ReactCodeAgent(ReactAgent):
...
@@ -911,7 +1053,11 @@ class ReactCodeAgent(ReactAgent):
try:
try:
result=self.python_evaluator(
result=self.python_evaluator(
code_action,
code_action,
tools=self.available_tools,
static_tools={
**BASE_PYTHON_TOOLS.copy(),
**self.toolbox.tools,
},
custom_tools=self.custom_tools,
state=self.state,
state=self.state,
authorized_imports=self.authorized_imports,
authorized_imports=self.authorized_imports,
)
)
...
@@ -920,7 +1066,7 @@ class ReactCodeAgent(ReactAgent):
...
@@ -920,7 +1066,7 @@ class ReactCodeAgent(ReactAgent):
self.logger.log(32,information)
self.logger.log(32,information)
current_step_logs["observation"]=information
current_step_logs["observation"]=information
exceptExceptionase:
exceptExceptionase:
error_msg=f"Failed while trying to execute the code below:\n{CustomFormatter.reset+code_action+CustomFormatter.reset}\nThis failed due to the following error:\n{str(e)}"
error_msg=f"Code execution failed due to the following error:\n{str(e)}"
if"'dict' object has no attribute 'read'"instr(e):
if"'dict' object has no attribute 'read'"instr(e):
error_msg+="\nYou get this error because you passed a dict as input for one of the arguments instead of a string."
error_msg+="\nYou get this error because you passed a dict as input for one of the arguments instead of a string."
A dictionary mapping variable names to values. The `state` is updated if need be when the evaluation
A dictionary mapping variable names to values. The `state` is updated if need be when the evaluation
encounters assignements.
encounters assignements.
tools (`Dict[str, Callable]`):
static_tools (`Dict[str, Callable]`):
The functions that may be called during the evaluation. Any call to another function will fail with an
Functions that may be called during the evaluation. Trying to change one of these static_tools will raise an error.
`InterpreterError`.
custom_tools (`Dict[str, Callable]`):
Functions that may be called during the evaluation. These static_tools can be overwritten.
authorized_imports (`List[str]`):
authorized_imports (`List[str]`):
The list of modules that can be imported by the code. By default, only a few safe modules are allowed.
The list of modules that can be imported by the code. By default, only a few safe modules are allowed.
Add more at your own risk!
Add more at your own risk!
"""
"""
globalOPERATIONS_COUNT
ifOPERATIONS_COUNT>=MAX_OPERATIONS:
raiseInterpreterError(
f"Reached the max number of operations of {MAX_OPERATIONS}. Maybe there is an infinite loop somewhere in the code, or you're just asking too many calculations."
)
OPERATIONS_COUNT+=1
ifisinstance(expression,ast.Assign):
ifisinstance(expression,ast.Assign):
# Assignement -> we evaluate the assignment which should update the state
# Assignement -> we evaluate the assignment which should update the state
# We return the variable assigned as it may be used to determine the final result.
# We return the variable assigned as it may be used to determine the final result.