From c1be8a74038bf47aecd77df04b1b08716ab63e82 Mon Sep 17 00:00:00 2001 From: russellocean Date: Wed, 5 Apr 2023 00:56:15 -0400 Subject: [PATCH 1/3] Implement custom continuous task count with 'y -n' --- scripts/main.py | 61 +++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index 93124234e6cd..492df20b062a 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -277,6 +277,7 @@ def parse_arguments(): # Initialize variables full_message_history = [] result = None +next_action_count = 0 # Make a constant: user_input = "Determine which next command to use, and respond using the format specified above:" @@ -291,7 +292,6 @@ def parse_arguments(): mem.permanent_memory, cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument - # print("assistant reply: "+assistant_reply) # Print Assistant thoughts print_assistant_thoughts(assistant_reply) @@ -301,36 +301,45 @@ def parse_arguments(): except Exception as e: print_to_console("Error: \n", Fore.RED, str(e)) - if not cfg.continuous_mode: + if not cfg.continuous_mode or next_action_count > 0: ### GET USER AUTHORIZATION TO EXECUTE COMMAND ### # Get key press: Prompt the user to press enter to continue or escape # to exit - user_input = "" - print_to_console( - "NEXT ACTION: ", - Fore.CYAN, - f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") - print( - f"Enter 'y' to authorise command or 'n' to exit program, or enter feedback for {ai_name}...", - flush=True) - while True: - console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) - if console_input.lower() == "y": - user_input = "GENERATE NEXT COMMAND JSON" - break - elif console_input.lower() == "n": - user_input = "EXIT" - break - else: - user_input = console_input - command_name = "human_feedback" - break + if next_action_count == 0: + user_input = "" + print_to_console( + "NEXT ACTION: ", + Fore.CYAN, + f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") + print( + f"Enter 'y' to authorise command, 'y -n' to run n continuous commands, 'n' to exit program, or enter feedback for {ai_name}...", + flush=True) + while True: + console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) + if console_input.lower() == "y": + user_input = "GENERATE NEXT COMMAND JSON" + break + elif console_input.lower().startswith("y -"): + try: + next_action_count = abs(int(console_input.split(" ")[1])) + user_input = "GENERATE NEXT COMMAND JSON" + except ValueError: + print("Invalid input format. Please enter 'y -n' where n is the number of continuous tasks.") + continue + break + elif console_input.lower() == "n": + user_input = "EXIT" + break + else: + user_input = console_input + command_name = "human_feedback" + break if user_input == "GENERATE NEXT COMMAND JSON": print_to_console( - "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=", - Fore.MAGENTA, - "") + "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=", + Fore.MAGENTA, + "") elif user_input == "EXIT": print("Exiting...", flush=True) break @@ -348,6 +357,8 @@ def parse_arguments(): result = f"Human feedback: {user_input}" else: result = f"Command {command_name} returned: {cmd.execute_command(command_name, arguments)}" + if next_action_count > 0: + next_action_count -= 1 # Check if there's a result from the command append it to the message # history From c8c8f5b11e4f6c1d7297434996dd5159cb313d59 Mon Sep 17 00:00:00 2001 From: russellocean Date: Wed, 5 Apr 2023 10:19:56 -0400 Subject: [PATCH 2/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to @Gerqus Co-authored-by: Paweł Pieniacki --- scripts/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index 492df20b062a..f7692757d071 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -301,7 +301,7 @@ def parse_arguments(): except Exception as e: print_to_console("Error: \n", Fore.RED, str(e)) - if not cfg.continuous_mode or next_action_count > 0: + if not cfg.continuous_mode and next_action_count === 0: ### GET USER AUTHORIZATION TO EXECUTE COMMAND ### # Get key press: Prompt the user to press enter to continue or escape # to exit @@ -312,7 +312,7 @@ def parse_arguments(): Fore.CYAN, f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") print( - f"Enter 'y' to authorise command, 'y -n' to run n continuous commands, 'n' to exit program, or enter feedback for {ai_name}...", + f"Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for {ai_name}...", flush=True) while True: console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) From c8a927d3ec35cc01feadad470eacb617902b6987 Mon Sep 17 00:00:00 2001 From: russellocean Date: Wed, 5 Apr 2023 10:28:50 -0400 Subject: [PATCH 3/3] Syntax Error, Revert formatting errors, remove 308 --- scripts/main.py | 63 ++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index f7692757d071..7f1f24b1e8ab 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -301,45 +301,44 @@ def parse_arguments(): except Exception as e: print_to_console("Error: \n", Fore.RED, str(e)) - if not cfg.continuous_mode and next_action_count === 0: + if not cfg.continuous_mode and next_action_count == 0: ### GET USER AUTHORIZATION TO EXECUTE COMMAND ### # Get key press: Prompt the user to press enter to continue or escape # to exit - if next_action_count == 0: - user_input = "" - print_to_console( - "NEXT ACTION: ", - Fore.CYAN, - f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") - print( - f"Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for {ai_name}...", - flush=True) - while True: - console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) - if console_input.lower() == "y": + user_input = "" + print_to_console( + "NEXT ACTION: ", + Fore.CYAN, + f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}") + print( + f"Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for {ai_name}...", + flush=True) + while True: + console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) + if console_input.lower() == "y": + user_input = "GENERATE NEXT COMMAND JSON" + break + elif console_input.lower().startswith("y -"): + try: + next_action_count = abs(int(console_input.split(" ")[1])) user_input = "GENERATE NEXT COMMAND JSON" - break - elif console_input.lower().startswith("y -"): - try: - next_action_count = abs(int(console_input.split(" ")[1])) - user_input = "GENERATE NEXT COMMAND JSON" - except ValueError: - print("Invalid input format. Please enter 'y -n' where n is the number of continuous tasks.") - continue - break - elif console_input.lower() == "n": - user_input = "EXIT" - break - else: - user_input = console_input - command_name = "human_feedback" - break + except ValueError: + print("Invalid input format. Please enter 'y -n' where n is the number of continuous tasks.") + continue + break + elif console_input.lower() == "n": + user_input = "EXIT" + break + else: + user_input = console_input + command_name = "human_feedback" + break if user_input == "GENERATE NEXT COMMAND JSON": print_to_console( - "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=", - Fore.MAGENTA, - "") + "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=", + Fore.MAGENTA, + "") elif user_input == "EXIT": print("Exiting...", flush=True) break