mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
Update main.py
Add separation between code blocks.
This commit is contained in:
@@ -27,17 +27,24 @@ def print_to_console(
|
|||||||
max_typing_speed=0.01):
|
max_typing_speed=0.01):
|
||||||
"""Prints text to the console with a typing effect"""
|
"""Prints text to the console with a typing effect"""
|
||||||
global cfg
|
global cfg
|
||||||
|
|
||||||
if speak_text and cfg.speak_mode:
|
if speak_text and cfg.speak_mode:
|
||||||
speak.say_text(f"{title}. {content}")
|
speak.say_text(f"{title}. {content}")
|
||||||
|
|
||||||
print(title_color + title + " " + Style.RESET_ALL, end="")
|
print(title_color + title + " " + Style.RESET_ALL, end="")
|
||||||
|
|
||||||
if content:
|
if content:
|
||||||
|
|
||||||
if isinstance(content, list):
|
if isinstance(content, list):
|
||||||
content = " ".join(content)
|
content = " ".join(content)
|
||||||
words = content.split()
|
words = content.split()
|
||||||
|
|
||||||
for i, word in enumerate(words):
|
for i, word in enumerate(words):
|
||||||
print(word, end="", flush=True)
|
print(word, end="", flush=True)
|
||||||
|
|
||||||
if i < len(words) - 1:
|
if i < len(words) - 1:
|
||||||
print(" ", end="", flush=True)
|
print(" ", end="", flush=True)
|
||||||
|
|
||||||
typing_speed = random.uniform(min_typing_speed, max_typing_speed)
|
typing_speed = random.uniform(min_typing_speed, max_typing_speed)
|
||||||
time.sleep(typing_speed)
|
time.sleep(typing_speed)
|
||||||
# type faster after each word
|
# type faster after each word
|
||||||
@@ -73,6 +80,7 @@ def print_assistant_thoughts(assistant_reply):
|
|||||||
if assistant_thoughts_plan:
|
if assistant_thoughts_plan:
|
||||||
print_to_console("PLAN:", Fore.YELLOW, "")
|
print_to_console("PLAN:", Fore.YELLOW, "")
|
||||||
# If it's a list, join it into a string
|
# If it's a list, join it into a string
|
||||||
|
|
||||||
if isinstance(assistant_thoughts_plan, list):
|
if isinstance(assistant_thoughts_plan, list):
|
||||||
assistant_thoughts_plan = "\n".join(assistant_thoughts_plan)
|
assistant_thoughts_plan = "\n".join(assistant_thoughts_plan)
|
||||||
elif isinstance(assistant_thoughts_plan, dict):
|
elif isinstance(assistant_thoughts_plan, dict):
|
||||||
@@ -80,6 +88,7 @@ def print_assistant_thoughts(assistant_reply):
|
|||||||
|
|
||||||
# Split the input_string using the newline character and dashes
|
# Split the input_string using the newline character and dashes
|
||||||
lines = assistant_thoughts_plan.split('\n')
|
lines = assistant_thoughts_plan.split('\n')
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = line.lstrip("- ")
|
line = line.lstrip("- ")
|
||||||
print_to_console("- ", Fore.GREEN, line.strip())
|
print_to_console("- ", Fore.GREEN, line.strip())
|
||||||
@@ -114,11 +123,13 @@ def load_variables(config_file="config.yaml"):
|
|||||||
# Prompt the user for input if config file is missing or empty values
|
# Prompt the user for input if config file is missing or empty values
|
||||||
if not ai_name:
|
if not ai_name:
|
||||||
ai_name = input("Name your AI: ")
|
ai_name = input("Name your AI: ")
|
||||||
|
|
||||||
if ai_name == "":
|
if ai_name == "":
|
||||||
ai_name = "Entrepreneur-GPT"
|
ai_name = "Entrepreneur-GPT"
|
||||||
|
|
||||||
if not ai_role:
|
if not ai_role:
|
||||||
ai_role = input(f"{ai_name} is: ")
|
ai_role = input(f"{ai_name} is: ")
|
||||||
|
|
||||||
if ai_role == "":
|
if ai_role == "":
|
||||||
ai_role = "an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth."
|
ai_role = "an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth."
|
||||||
|
|
||||||
@@ -127,16 +138,20 @@ def load_variables(config_file="config.yaml"):
|
|||||||
print("For example: \nIncrease net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'")
|
print("For example: \nIncrease net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'")
|
||||||
print("Enter nothing to load defaults, enter nothing when finished.")
|
print("Enter nothing to load defaults, enter nothing when finished.")
|
||||||
ai_goals = []
|
ai_goals = []
|
||||||
|
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
ai_goal = input(f"Goal {i+1}: ")
|
ai_goal = input(f"Goal {i+1}: ")
|
||||||
|
|
||||||
if ai_goal == "":
|
if ai_goal == "":
|
||||||
break
|
break
|
||||||
ai_goals.append(ai_goal)
|
ai_goals.append(ai_goal)
|
||||||
|
|
||||||
if len(ai_goals) == 0:
|
if len(ai_goals) == 0:
|
||||||
ai_goals = ["Increase net worth", "Grow Twitter Account", "Develop and manage multiple businesses autonomously"]
|
ai_goals = ["Increase net worth", "Grow Twitter Account", "Develop and manage multiple businesses autonomously"]
|
||||||
|
|
||||||
# Save variables to yaml file
|
# Save variables to yaml file
|
||||||
config = {"ai_name": ai_name, "ai_role": ai_role, "ai_goals": ai_goals}
|
config = {"ai_name": ai_name, "ai_role": ai_role, "ai_goals": ai_goals}
|
||||||
|
|
||||||
with open(config_file, "w") as file:
|
with open(config_file, "w") as file:
|
||||||
documents = yaml.dump(config, file)
|
documents = yaml.dump(config, file)
|
||||||
|
|
||||||
@@ -145,6 +160,7 @@ def load_variables(config_file="config.yaml"):
|
|||||||
|
|
||||||
# Construct full prompt
|
# Construct full prompt
|
||||||
full_prompt = f"You are {ai_name}, {ai_role}\n{prompt_start}\n\nGOALS:\n\n"
|
full_prompt = f"You are {ai_name}, {ai_role}\n{prompt_start}\n\nGOALS:\n\n"
|
||||||
|
|
||||||
for i, goal in enumerate(ai_goals):
|
for i, goal in enumerate(ai_goals):
|
||||||
full_prompt += f"{i+1}. {goal}\n"
|
full_prompt += f"{i+1}. {goal}\n"
|
||||||
|
|
||||||
@@ -155,6 +171,7 @@ def load_variables(config_file="config.yaml"):
|
|||||||
def construct_prompt():
|
def construct_prompt():
|
||||||
"""Construct the prompt for the AI to respond to"""
|
"""Construct the prompt for the AI to respond to"""
|
||||||
config = AIConfig.load()
|
config = AIConfig.load()
|
||||||
|
|
||||||
if config.ai_name:
|
if config.ai_name:
|
||||||
print_to_console(
|
print_to_console(
|
||||||
f"Welcome back! ",
|
f"Welcome back! ",
|
||||||
@@ -162,10 +179,11 @@ def construct_prompt():
|
|||||||
f"Would you like me to return to being {config.ai_name}?",
|
f"Would you like me to return to being {config.ai_name}?",
|
||||||
speak_text=True)
|
speak_text=True)
|
||||||
should_continue = input(f"""Continue with the last settings?
|
should_continue = input(f"""Continue with the last settings?
|
||||||
Name: {config.ai_name}
|
Name: {config.ai_name}
|
||||||
Role: {config.ai_role}
|
Role: {config.ai_role}
|
||||||
Goals: {config.ai_goals}
|
Goals: {config.ai_goals}
|
||||||
Continue (y/n): """)
|
Continue (y/n): """)
|
||||||
|
|
||||||
if should_continue.lower() == "n":
|
if should_continue.lower() == "n":
|
||||||
config = AIConfig()
|
config = AIConfig()
|
||||||
|
|
||||||
@@ -196,7 +214,9 @@ def prompt_user():
|
|||||||
"Name your AI: ",
|
"Name your AI: ",
|
||||||
Fore.GREEN,
|
Fore.GREEN,
|
||||||
"For example, 'Entrepreneur-GPT'")
|
"For example, 'Entrepreneur-GPT'")
|
||||||
|
|
||||||
ai_name = input("AI Name: ")
|
ai_name = input("AI Name: ")
|
||||||
|
|
||||||
if ai_name == "":
|
if ai_name == "":
|
||||||
ai_name = "Entrepreneur-GPT"
|
ai_name = "Entrepreneur-GPT"
|
||||||
|
|
||||||
@@ -212,6 +232,7 @@ def prompt_user():
|
|||||||
Fore.GREEN,
|
Fore.GREEN,
|
||||||
"For example, 'an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.'")
|
"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 = input(f"{ai_name} is: ")
|
||||||
|
|
||||||
if ai_role == "":
|
if ai_role == "":
|
||||||
ai_role = "an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth."
|
ai_role = "an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth."
|
||||||
|
|
||||||
@@ -220,13 +241,18 @@ def prompt_user():
|
|||||||
"Enter up to 5 goals for your AI: ",
|
"Enter up to 5 goals for your AI: ",
|
||||||
Fore.GREEN,
|
Fore.GREEN,
|
||||||
"For example: \nIncrease net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'")
|
"For example: \nIncrease net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'")
|
||||||
|
|
||||||
print("Enter nothing to load defaults, enter nothing when finished.", flush=True)
|
print("Enter nothing to load defaults, enter nothing when finished.", flush=True)
|
||||||
ai_goals = []
|
ai_goals = []
|
||||||
|
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
ai_goal = input(f"{Fore.LIGHTBLUE_EX}Goal{Style.RESET_ALL} {i+1}: ")
|
ai_goal = input(f"{Fore.LIGHTBLUE_EX}Goal{Style.RESET_ALL} {i+1}: ")
|
||||||
|
|
||||||
if ai_goal == "":
|
if ai_goal == "":
|
||||||
break
|
break
|
||||||
|
|
||||||
ai_goals.append(ai_goal)
|
ai_goals.append(ai_goal)
|
||||||
|
|
||||||
if len(ai_goals) == 0:
|
if len(ai_goals) == 0:
|
||||||
ai_goals = ["Increase net worth", "Grow Twitter Account",
|
ai_goals = ["Increase net worth", "Grow Twitter Account",
|
||||||
"Develop and manage multiple businesses autonomously"]
|
"Develop and manage multiple businesses autonomously"]
|
||||||
@@ -234,6 +260,7 @@ def prompt_user():
|
|||||||
config = AIConfig(ai_name, ai_role, ai_goals)
|
config = AIConfig(ai_name, ai_role, ai_goals)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
"""Parses the arguments passed to the script"""
|
"""Parses the arguments passed to the script"""
|
||||||
global cfg
|
global cfg
|
||||||
@@ -307,11 +334,11 @@ while True:
|
|||||||
"NEXT ACTION: ",
|
"NEXT ACTION: ",
|
||||||
Fore.CYAN,
|
Fore.CYAN,
|
||||||
f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}")
|
f"COMMAND = {Fore.CYAN}{command_name}{Style.RESET_ALL} ARGUMENTS = {Fore.CYAN}{arguments}{Style.RESET_ALL}")
|
||||||
print(
|
print("Enter 'y' to authorise command or 'n' to exit program...", flush=True)
|
||||||
"Enter 'y' to authorise command or 'n' to exit program...",
|
|
||||||
flush=True)
|
|
||||||
while True:
|
while True:
|
||||||
console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL)
|
console_input = input(Fore.MAGENTA + "Input:" + Style.RESET_ALL)
|
||||||
|
|
||||||
if console_input.lower() == "y":
|
if console_input.lower() == "y":
|
||||||
user_input = "GENERATE NEXT COMMAND JSON"
|
user_input = "GENERATE NEXT COMMAND JSON"
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user