From 9f737274b78c84f509cd8b740752444b5fa09722 Mon Sep 17 00:00:00 2001 From: Erik Peterson Date: Sun, 18 Jun 2023 20:30:08 -0700 Subject: [PATCH] Fix issues with execute_python_code responses (#4738) Co-authored-by: merwanehamadi --- autogpt/commands/execute_code.py | 10 +++++----- autogpt/json_utils/utilities.py | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.py index 663800ef..0b0f731c 100644 --- a/autogpt/commands/execute_code.py +++ b/autogpt/commands/execute_code.py @@ -32,13 +32,13 @@ DENYLIST_CONTROL = "denylist" }, }, ) -def execute_python_code(code: str, basename: str, agent: Agent) -> str: +def execute_python_code(code: str, name: str, agent: Agent) -> str: """Create and execute a Python file in a Docker container and return the STDOUT of the executed code. If there is any data that needs to be captured use a print statement Args: code (str): The Python code to run - basename (str): A name to be given to the Python file + name (str): A name to be given to the Python file Returns: str: The STDOUT captured from the code when it ran @@ -47,10 +47,10 @@ def execute_python_code(code: str, basename: str, agent: Agent) -> str: directory = os.path.join(agent.config.workspace_path, ai_name, "executed_code") os.makedirs(directory, exist_ok=True) - if not basename.endswith(".py"): - basename = basename + ".py" + if not name.endswith(".py"): + name = name + ".py" - path = os.path.join(directory, basename) + path = os.path.join(directory, name) try: with open(path, "w+", encoding="utf-8") as f: diff --git a/autogpt/json_utils/utilities.py b/autogpt/json_utils/utilities.py index 62f3b3ca..835542a0 100644 --- a/autogpt/json_utils/utilities.py +++ b/autogpt/json_utils/utilities.py @@ -22,7 +22,8 @@ def extract_json_from_response(response_content: str) -> dict: try: return ast.literal_eval(response_content) except BaseException as e: - logger.error(f"Error parsing JSON response with literal_eval {e}") + logger.info(f"Error parsing JSON response with literal_eval {e}") + logger.debug(f"Invalid JSON received in response: {response_content}") # TODO: How to raise an error here without causing the program to exit? return {}