Skip to content

A programming framework for agentic AI

encode timeout msg in bytes (#1078)

Chi Wangc5dfb03f0ee0
diff --git a/flaml/autogen/code_utils.py b/flaml/autogen/code_utils.py
index be52b2e5b..009979fba 100644
--- a/flaml/autogen/code_utils.py
+++ b/flaml/autogen/code_utils.py
@@ -13,6 +13,7 @@ from flaml.autogen import oai, DEFAULT_MODEL, FAST_MODEL
CODE_BLOCK_PATTERN = r"```(\w*)\n(.*?)\n```"
WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extensions")
UNKNOWN = "unknown"
+TIMEOUT_MSG = bytes("Timeout", "utf-8")
def infer_lang(code):
@@ -180,7 +181,6 @@ def execute_code(
filepath = os.path.join(work_dir, filename)
file_dir = os.path.dirname(filepath)
os.makedirs(file_dir, exist_ok=True)
-
if code is not None:
with open(filepath, "w") as fout:
fout.write(code)
@@ -202,7 +202,7 @@ def execute_code(
except TimeoutError:
if original_filename is None:
os.remove(filepath)
- return 1, "Timeout", None
+ return 1, TIMEOUT_MSG, None
if original_filename is None:
os.remove(filepath)
return result.returncode, result.stderr if result.returncode else result.stdout, None
@@ -260,7 +260,7 @@ def execute_code(
container.remove()
if original_filename is None:
os.remove(filepath)
- return 1, "Timeout", image
+ return 1, TIMEOUT_MSG, image
# try:
# container.wait(timeout=timeout)
# except (ReadTimeout, ConnectionError):
diff --git a/flaml/version.py b/flaml/version.py
index 0cda2d108..0ddcee847 100644
--- a/flaml/version.py
+++ b/flaml/version.py
@@ -1 +1 @@
-__version__ = "2.0.0rc1"
+__version__ = "2.0.0rc2"
diff --git a/test/autogen/test_code.py b/test/autogen/test_code.py
index e3becba13..a484c90db 100644
--- a/test/autogen/test_code.py
+++ b/test/autogen/test_code.py
@@ -74,9 +74,9 @@ def test_execute_code():
assert exit_code, msg
# execute code which takes a long time
exit_code, error, image = execute_code("import time; time.sleep(2)", timeout=1)
- assert exit_code and error == "Timeout"
+ assert exit_code and error.decode() == "Timeout"
exit_code, error, image = execute_code("import time; time.sleep(2)", timeout=1, use_docker=False)
- assert exit_code and error == "Timeout" and image is None
+ assert exit_code and error.decode() == "Timeout" and image is None
if __name__ == "__main__":