AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Fix issues with execute_python_code responses (#4738)
Erik Peterson9f737274b78c
diff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.pyindex 663800ef5b..0b0f731c91 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 theexecuted code. If there is any data that needs to be captured use a print statementArgs: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 fileReturns: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.pyindex 62f3b3cab1..835542a030 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 {}