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.
Handles errors in get_command without terminating program.
Torantulino82459f72aa2d
diff --git a/AutonomousAI/commands.py b/AutonomousAI/commands.pyindex cd74e28d65..dabdd992cd 100644--- a/AutonomousAI/commands.py+++ b/AutonomousAI/commands.py@@ -17,10 +17,10 @@ def get_command(response):return command_name, argumentsexcept json.decoder.JSONDecodeError:- return "Error: Invalid JSON"+ return "Error:", "Invalid JSON"# All other errors, return "Error: + error message"except Exception as e:- return "Error: " + str(e)+ return "Error:", str(e)def execute_command(command_name, arguments):try:diff --git a/AutonomousAI/main.py b/AutonomousAI/main.pyindex ed6512cb22..1f4b3f69de 100644--- a/AutonomousAI/main.py+++ b/AutonomousAI/main.py@@ -133,8 +133,12 @@ while True:print_assistant_thoughts(assistant_reply)# Get command name and arguments- command_name, arguments = cmd.get_command(assistant_reply)-+ try:+ command_name, arguments = cmd.get_command(assistant_reply)+ except Exception as e:+ print_to_console("Error: \n", Fore.RED, str(e))++if not continuous_mode:### GET USER AUTHORIZATION TO EXECUTE COMMAND #### Get key press: Prompt the user to press enter to continue or escape to exit@@ -162,8 +166,10 @@ while True:print_to_console("NEXT ACTION: ", Fore.CYAN, f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}")# Exectute command- result = cmd.execute_command(command_name, arguments)-+ if command_name.lower() != "error":+ result = cmd.execute_command(command_name, arguments)+ else:+ result ="Error: " + arguments# Check if there's a result from the command append it to the message historyif result != None: