From 41f5cd6b389d4999c081691577b6d90087371780 Mon Sep 17 00:00:00 2001 From: Sma Das Date: Sun, 9 Apr 2023 20:53:32 -0400 Subject: [PATCH 1/4] Created `utils.py` --- scripts/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 scripts/utils.py diff --git a/scripts/utils.py b/scripts/utils.py new file mode 100644 index 0000000000..bab9ac9684 --- /dev/null +++ b/scripts/utils.py @@ -0,0 +1,6 @@ +def clean_input(prompt: str=''): + try: + return input(prompt) + except KeyboardInterrupt: + exit(0) + From 9ef82275cad16080e313767fb4e8e424a371efe2 Mon Sep 17 00:00:00 2001 From: Sma Das Date: Sun, 9 Apr 2023 20:55:38 -0400 Subject: [PATCH 2/4] Updated `main.py` to use `clean_input` --- scripts/main.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index f96afeb163..038ed2db83 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -1,6 +1,7 @@ import json import random import commands as cmd +import utils from memory import get_memory import data import chat @@ -119,12 +120,12 @@ def load_variables(config_file="config.yaml"): # Prompt the user for input if config file is missing or empty values if not ai_name: - ai_name = input("Name your AI: ") + ai_name = utils.clean_input("Name your AI: ") if ai_name == "": ai_name = "Entrepreneur-GPT" if not ai_role: - ai_role = input(f"{ai_name} is: ") + ai_role = utils.clean_input(f"{ai_name} is: ") if ai_role == "": ai_role = "an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth." @@ -134,7 +135,7 @@ def load_variables(config_file="config.yaml"): print("Enter nothing to load defaults, enter nothing when finished.") ai_goals = [] for i in range(5): - ai_goal = input(f"Goal {i+1}: ") + ai_goal = utils.clean_input(f"Goal {i+1}: ") if ai_goal == "": break ai_goals.append(ai_goal) @@ -166,7 +167,7 @@ def construct_prompt(): Fore.GREEN, f"Would you like me to return to being {config.ai_name}?", speak_text=True) - should_continue = input(f"""Continue with the last settings? + should_continue = utils.clean_input(f"""Continue with the last settings? Name: {config.ai_name} Role: {config.ai_role} Goals: {config.ai_goals} @@ -200,7 +201,7 @@ def prompt_user(): "Name your AI: ", Fore.GREEN, "For example, 'Entrepreneur-GPT'") - ai_name = input("AI Name: ") + ai_name = utils.clean_input("AI Name: ") if ai_name == "": ai_name = "Entrepreneur-GPT" @@ -215,7 +216,7 @@ def prompt_user(): "Describe your AI's role: ", Fore.GREEN, "For example, 'an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.'") - ai_role = input(f"{ai_name} is: ") + ai_role = utils.clean_input(f"{ai_name} is: ") if ai_role == "": ai_role = "an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth." @@ -227,7 +228,7 @@ def prompt_user(): print("Enter nothing to load defaults, enter nothing when finished.", flush=True) ai_goals = [] for i in range(5): - ai_goal = input(f"{Fore.LIGHTBLUE_EX}Goal{Style.RESET_ALL} {i+1}: ") + ai_goal = utils.clean_input(f"{Fore.LIGHTBLUE_EX}Goal{Style.RESET_ALL} {i+1}: ") if ai_goal == "": break ai_goals.append(ai_goal) @@ -323,7 +324,7 @@ while True: 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) + console_input = utils.clean_input(Fore.MAGENTA + "Input:" + Style.RESET_ALL) if console_input.lower() == "y": user_input = "GENERATE NEXT COMMAND JSON" break From cd07115a39fa30f28c4f85ad4c776a2cfb817260 Mon Sep 17 00:00:00 2001 From: Sma Das Date: Mon, 10 Apr 2023 11:29:15 -0400 Subject: [PATCH 3/4] Removed trailing whitespace --- scripts/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/main.py b/scripts/main.py index bd1c088d20..71e72cd4c3 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -138,7 +138,7 @@ def load_variables(config_file="config.yaml"): if ai_name == "": ai_name = "Entrepreneur-GPT" - if not ai_role: + if not ai_role: ai_role = utils.clean_input(f"{ai_name} is: ") if ai_role == "": ai_role = "an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth." @@ -182,7 +182,7 @@ def construct_prompt(): Fore.GREEN, f"Would you like me to return to being {config.ai_name}?", speak_text=True) - should_continue = utils.clean_input(f"""Continue with the last settings? + should_continue = utils.clean_input(f"""Continue with the last settings? Name: {config.ai_name} Role: {config.ai_role} Goals: {config.ai_goals} @@ -282,7 +282,7 @@ def parse_arguments(): if args.debug: print_to_console("Debug Mode: ", Fore.GREEN, "ENABLED") - cfg.set_debug_mode(True) + cfg.set_debug_mode(True) if args.gpt3only: print_to_console("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED") From 5c1c3f9c7e9be6cfec4cca255123f81756ba0d10 Mon Sep 17 00:00:00 2001 From: Sma Das Date: Mon, 10 Apr 2023 11:31:43 -0400 Subject: [PATCH 4/4] Added exit message on `KeyboardInterrupt` --- scripts/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/utils.py b/scripts/utils.py index bab9ac9684..5039796fbd 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -2,5 +2,7 @@ def clean_input(prompt: str=''): try: return input(prompt) except KeyboardInterrupt: + print("You interrupted Auto-GPT") + print("Quitting...") exit(0)