diff --git a/src/smolagents/local_python_executor.py b/src/smolagents/local_python_executor.py index 5efa620..346f0fe 100644 --- a/src/smolagents/local_python_executor.py +++ b/src/smolagents/local_python_executor.py @@ -52,6 +52,7 @@ ERRORS = { DEFAULT_MAX_LEN_OUTPUT = 50000 MAX_OPERATIONS = 10000000 +MAX_WHILE_ITERATIONS = 1000000 def custom_print(*args): @@ -241,7 +242,6 @@ def evaluate_while( custom_tools: Dict[str, Callable], authorized_imports: List[str], ) -> None: - max_iterations = 1000000 iterations = 0 while evaluate_ast(while_loop.test, state, static_tools, custom_tools, authorized_imports): for node in while_loop.body: @@ -252,8 +252,8 @@ def evaluate_while( except ContinueException: break iterations += 1 - if iterations > max_iterations: - raise InterpreterError(f"Maximum number of {max_iterations} iterations in While loop exceeded") + if iterations > MAX_WHILE_ITERATIONS: + raise InterpreterError(f"Maximum number of {MAX_WHILE_ITERATIONS} iterations in While loop exceeded") return None