From 8965b6a573248d6919293b7505c8ba159dcecc84 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Fri, 7 Feb 2025 10:59:39 +0100 Subject: [PATCH] Set MAX_WHILE_ITERATIONS as module variable (#520) --- src/smolagents/local_python_executor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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