Skip to content

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.

Merge branch 'master' into flags-updates

EHc7cf00d66741
diff --cc scripts/config.py
index ad968fb247,37be1b2104..0880926a4a
--- a/scripts/config.py
+++ b/scripts/config.py
@@@ -36,10 -36,9 +36,11 @@@ class Config(metaclass=Singleton)
"""Initialize the Config class"""
self.debug_mode = False
self.continuous_mode = False
+ self.continuous_limit = 0
self.speak_mode = False
+ self.skip_reprompt = False
+ self.ai_settings_file = os.getenv("AI_SETTINGS_FILE", "ai_settings.yaml")
self.fast_llm_model = os.getenv("FAST_LLM_MODEL", "gpt-3.5-turbo")
self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4")
self.fast_token_limit = int(os.getenv("FAST_TOKEN_LIMIT", 4000))
diff --cc scripts/main.py
index 0674db47b6,466f50dd1c..400eb1f638
--- a/scripts/main.py
+++ b/scripts/main.py
@@@ -274,7 -274,8 +278,8 @@@ def parse_arguments()
cfg.set_speak_mode(False)
parser = argparse.ArgumentParser(description='Process arguments.')
- parser.add_argument('--continuous', action='store_true', help='Enable Continuous Mode')
+ parser.add_argument('--continuous', '-c', action='store_true', help='Enable Continuous Mode')
+ parser.add_argument('--continuous-limit', '-l', type=int, dest="continuous_limit", help='Defines the number of times to run in continuous mode')
parser.add_argument('--speak', action='store_true', help='Enable Speak Mode')
parser.add_argument('--debug', action='store_true', help='Enable Debug Mode')
parser.add_argument('--gpt3only', action='store_true', help='Enable GPT3.5 Only Mode')
@@@ -321,136 -331,131 +337,148 @@@
else:
cfg.memory_backend = chosen
+ if args.skip_reprompt:
+ logger.typewriter_log("Skip Re-prompt: ", Fore.GREEN, "ENABLED")
+ cfg.skip_reprompt = True
+
+ if args.ai_settings_file:
+ file = args.ai_settings_file
+
+ # Validate file
+ (validated, message) = utils.validate_yaml_file(file)
+ if not validated:
+ logger.typewriter_log("FAILED FILE VALIDATION", Fore.RED, message)
+ exit(1)
+
+ logger.typewriter_log("Using AI Settings File:", Fore.GREEN, file)
+ cfg.ai_settings_file = file
+ cfg.skip_reprompt = True
+
- # TODO: fill in llm values here
- check_openai_api_key()
- parse_arguments()
- logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO)
- ai_name = ""
- prompt = construct_prompt()
- # print(prompt)
- # 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:"
-
- # Initialize memory and make sure it is empty.
- # this is particularly important for indexing and referencing pinecone memory
- memory = get_memory(cfg, init=True)
- print('Using memory of type: ' + memory.__class__.__name__)
-
- # Interaction Loop
- while True:
- # Send message to AI, get response
- with Spinner("Thinking... "):
- assistant_reply = chat.chat_with_ai(
- prompt,
- user_input,
- full_message_history,
- memory,
- cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument
-
- # Print Assistant thoughts
- print_assistant_thoughts(assistant_reply)
-
- # Get command name and arguments
- try:
- command_name, arguments = cmd.get_command(attempt_to_fix_json_by_finding_outermost_brackets(assistant_reply))
- if cfg.speak_mode:
- speak.say_text(f"I want to execute {command_name}")
- except Exception as e:
- logger.error("Error: \n", str(e))
+ def main():
+ global ai_name, memory
+ # TODO: fill in llm values here
+ check_openai_api_key()
+ parse_arguments()
+ logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO)
+ ai_name = ""
+ prompt = construct_prompt()
+ # print(prompt)
+ # 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:"
+ # Initialize memory and make sure it is empty.
+ # this is particularly important for indexing and referencing pinecone memory
+ memory = get_memory(cfg, init=True)
+ print('Using memory of type: ' + memory.__class__.__name__)
+ # Interaction Loop
+ loop_count = 0
+ while True:
+ # Discontinue if continuous limit is reached
+ loop_count += 1
+ if cfg.continuous_mode and cfg.continuous_limit > 0 and loop_count > cfg.continuous_limit:
+ logger.typewriter_log("Continuous Limit Reached: ", Fore.YELLOW, f"{cfg.continuous_limit}")
+ break
- 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
- user_input = ""
- logger.typewriter_log(
- "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 = utils.clean_input(Fore.MAGENTA + "Input:" + Style.RESET_ALL)
- if console_input.lower().rstrip() == "y":
- user_input = "GENERATE NEXT COMMAND JSON"
- break
- elif console_input.lower().startswith("y -"):
- try:
- next_action_count = abs(int(console_input.split(" ")[1]))
+ # Send message to AI, get response
+ with Spinner("Thinking... "):
+ assistant_reply = chat.chat_with_ai(
+ prompt,
+ user_input,
+ full_message_history,
+ memory,
+ cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument
+
+ # Print Assistant thoughts
+ print_assistant_thoughts(assistant_reply)
+
+ # Get command name and arguments
+ try:
+ command_name, arguments = cmd.get_command(
+ attempt_to_fix_json_by_finding_outermost_brackets(assistant_reply))
+ if cfg.speak_mode:
+ speak.say_text(f"I want to execute {command_name}")
+ except Exception as e:
+ logger.error("Error: \n", str(e))
+
+ 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
+ user_input = ""
+ logger.typewriter_log(
+ "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 = utils.clean_input(Fore.MAGENTA + "Input:" + Style.RESET_ALL)
+ if console_input.lower().rstrip() == "y":
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
+ 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":
+ logger.typewriter_log(
+ "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=",
+ Fore.MAGENTA,
+ "")
+ elif user_input == "EXIT":
+ print("Exiting...", flush=True)
break
- else:
- user_input = console_input
- command_name = "human_feedback"
- break
-
- if user_input == "GENERATE NEXT COMMAND JSON":
+ else:
+ # Print command
logger.typewriter_log(
- "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=",
- Fore.MAGENTA,
- "")
- elif user_input == "EXIT":
- print("Exiting...", flush=True)
- break
- else:
- # Print command
- logger.typewriter_log(
- "NEXT ACTION: ",
- Fore.CYAN,
- f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}")
-
- # Execute command
- if command_name is not None and command_name.lower().startswith( "error" ):
- result = f"Command {command_name} threw the following error: " + arguments
- elif command_name == "human_feedback":
- 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
-
- memory_to_add = f"Assistant Reply: {assistant_reply} " \
- f"\nResult: {result} " \
- f"\nHuman Feedback: {user_input} "
-
- memory.add(memory_to_add)
-
- # Check if there's a result from the command append it to the message
- # history
- if result is not None:
- full_message_history.append(chat.create_chat_message("system", result))
- logger.typewriter_log("SYSTEM: ", Fore.YELLOW, result)
- else:
- full_message_history.append(
- chat.create_chat_message(
- "system", "Unable to execute command"))
- logger.typewriter_log("SYSTEM: ", Fore.YELLOW, "Unable to execute command")
+ "NEXT ACTION: ",
+ Fore.CYAN,
+ f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}")
+
+ # Execute command
+ if command_name is not None and command_name.lower().startswith("error"):
+ result = f"Command {command_name} threw the following error: " + arguments
+ elif command_name == "human_feedback":
+ 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
+
+ memory_to_add = f"Assistant Reply: {assistant_reply} " \
+ f"\nResult: {result} " \
+ f"\nHuman Feedback: {user_input} "
+
+ memory.add(memory_to_add)
+
+ # Check if there's a result from the command append it to the message
+ # history
+ if result is not None:
+ full_message_history.append(chat.create_chat_message("system", result))
+ logger.typewriter_log("SYSTEM: ", Fore.YELLOW, result)
+ else:
+ full_message_history.append(
+ chat.create_chat_message(
+ "system", "Unable to execute command"))
+ logger.typewriter_log("SYSTEM: ", Fore.YELLOW, "Unable to execute command")
+
+
+ if __name__ == "__main__":
+ main()