refactor(logger): rename the typewriter log function from 'log' to 'typewriter_log'

This commit is contained in:
Fabrice Hong
2023-04-12 14:43:32 +02:00
parent 862d44ea39
commit 158c576a87
2 changed files with 28 additions and 28 deletions

View File

@@ -68,7 +68,7 @@ class Logger(metaclass=Singleton):
self.logger.addHandler(error_handler) self.logger.addHandler(error_handler)
self.logger.setLevel(logging.DEBUG) self.logger.setLevel(logging.DEBUG)
def log( def typewriter_log(
self, self,
title='', title='',
title_color='', title_color='',
@@ -92,7 +92,7 @@ class Logger(metaclass=Singleton):
title='', title='',
title_color='', title_color='',
): ):
self._logs(title, title_color, message, logging.DEBUG) self._log(title, title_color, message, logging.DEBUG)
def warn( def warn(
self, self,
@@ -100,16 +100,16 @@ class Logger(metaclass=Singleton):
title='', title='',
title_color='', title_color='',
): ):
self._logs(title, title_color, message, logging.WARN) self._log(title, title_color, message, logging.WARN)
def error( def error(
self, self,
title, title,
message='' message=''
): ):
self._logs(title, Fore.RED, message, logging.ERROR) self._log(title, Fore.RED, message, logging.ERROR)
def _logs( def _log(
self, self,
title='', title='',
title_color='', title_color='',

View File

@@ -92,11 +92,11 @@ def print_assistant_thoughts(assistant_reply):
assistant_thoughts_criticism = assistant_thoughts.get("criticism") assistant_thoughts_criticism = assistant_thoughts.get("criticism")
assistant_thoughts_speak = assistant_thoughts.get("speak") assistant_thoughts_speak = assistant_thoughts.get("speak")
logger.log(f"{ai_name.upper()} THOUGHTS:", Fore.YELLOW, assistant_thoughts_text) logger.typewriter_log(f"{ai_name.upper()} THOUGHTS:", Fore.YELLOW, assistant_thoughts_text)
logger.log("REASONING:", Fore.YELLOW, assistant_thoughts_reasoning) logger.typewriter_log("REASONING:", Fore.YELLOW, assistant_thoughts_reasoning)
if assistant_thoughts_plan: if assistant_thoughts_plan:
logger.log("PLAN:", Fore.YELLOW, "") logger.typewriter_log("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)
@@ -107,9 +107,9 @@ def print_assistant_thoughts(assistant_reply):
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("- ")
logger.log("- ", Fore.GREEN, line.strip()) logger.typewriter_log("- ", Fore.GREEN, line.strip())
logger.log("CRITICISM:", Fore.YELLOW, assistant_thoughts_criticism) logger.typewriter_log("CRITICISM:", Fore.YELLOW, assistant_thoughts_criticism)
# Speak the assistant's thoughts # Speak the assistant's thoughts
if cfg.speak_mode and assistant_thoughts_speak: if cfg.speak_mode and assistant_thoughts_speak:
speak.say_text(assistant_thoughts_speak) speak.say_text(assistant_thoughts_speak)
@@ -184,7 +184,7 @@ 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:
logger.log( logger.typewriter_log(
f"Welcome back! ", f"Welcome back! ",
Fore.GREEN, Fore.GREEN,
f"Would you like me to return to being {config.ai_name}?", f"Would you like me to return to being {config.ai_name}?",
@@ -213,14 +213,14 @@ def prompt_user():
"""Prompt the user for input""" """Prompt the user for input"""
ai_name = "" ai_name = ""
# Construct the prompt # Construct the prompt
logger.log( logger.typewriter_log(
"Welcome to Auto-GPT! ", "Welcome to Auto-GPT! ",
Fore.GREEN, Fore.GREEN,
"Enter the name of your AI and its role below. Entering nothing will load defaults.", "Enter the name of your AI and its role below. Entering nothing will load defaults.",
speak_text=True) speak_text=True)
# Get AI Name from User # Get AI Name from User
logger.log( logger.typewriter_log(
"Name your AI: ", "Name your AI: ",
Fore.GREEN, Fore.GREEN,
"For example, 'Entrepreneur-GPT'") "For example, 'Entrepreneur-GPT'")
@@ -228,14 +228,14 @@ def prompt_user():
if ai_name == "": if ai_name == "":
ai_name = "Entrepreneur-GPT" ai_name = "Entrepreneur-GPT"
logger.log( logger.typewriter_log(
f"{ai_name} here!", f"{ai_name} here!",
Fore.LIGHTBLUE_EX, Fore.LIGHTBLUE_EX,
"I am at your service.", "I am at your service.",
speak_text=True) speak_text=True)
# Get AI Role from User # Get AI Role from User
logger.log( logger.typewriter_log(
"Describe your AI's role: ", "Describe your AI's role: ",
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.'")
@@ -244,7 +244,7 @@ def prompt_user():
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."
# Enter up to 5 goals for the AI # Enter up to 5 goals for the AI
logger.log( logger.typewriter_log(
"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'")
@@ -278,31 +278,31 @@ def parse_arguments():
args = parser.parse_args() args = parser.parse_args()
if args.debug: if args.debug:
logger.log("Debug Mode: ", Fore.GREEN, "ENABLED") logger.typewriter_log("Debug Mode: ", Fore.GREEN, "ENABLED")
cfg.set_debug_mode(True) cfg.set_debug_mode(True)
if args.continuous: if args.continuous:
logger.log("Continuous Mode: ", Fore.RED, "ENABLED") logger.typewriter_log("Continuous Mode: ", Fore.RED, "ENABLED")
logger.log( logger.typewriter_log(
"WARNING: ", "WARNING: ",
Fore.RED, Fore.RED,
"Continuous mode is not recommended. It is potentially dangerous and may cause your AI to run forever or carry out actions you would not usually authorise. Use at your own risk.") "Continuous mode is not recommended. It is potentially dangerous and may cause your AI to run forever or carry out actions you would not usually authorise. Use at your own risk.")
cfg.set_continuous_mode(True) cfg.set_continuous_mode(True)
if args.speak: if args.speak:
logger.log("Speak Mode: ", Fore.GREEN, "ENABLED") logger.typewriter_log("Speak Mode: ", Fore.GREEN, "ENABLED")
cfg.set_speak_mode(True) cfg.set_speak_mode(True)
if args.gpt3only: if args.gpt3only:
logger.log("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED") logger.typewriter_log("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED")
cfg.set_smart_llm_model(cfg.fast_llm_model) cfg.set_smart_llm_model(cfg.fast_llm_model)
if args.gpt4only: if args.gpt4only:
logger.log("GPT4 Only Mode: ", Fore.GREEN, "ENABLED") logger.typewriter_log("GPT4 Only Mode: ", Fore.GREEN, "ENABLED")
cfg.set_fast_llm_model(cfg.smart_llm_model) cfg.set_fast_llm_model(cfg.smart_llm_model)
if args.debug: if args.debug:
logger.log("Debug Mode: ", Fore.GREEN, "ENABLED") logger.typewriter_log("Debug Mode: ", Fore.GREEN, "ENABLED")
cfg.set_debug_mode(True) cfg.set_debug_mode(True)
@@ -353,7 +353,7 @@ while True:
# Get key press: Prompt the user to press enter to continue or escape # Get key press: Prompt the user to press enter to continue or escape
# to exit # to exit
user_input = "" user_input = ""
logger.log( logger.typewriter_log(
"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}")
@@ -382,7 +382,7 @@ while True:
break break
if user_input == "GENERATE NEXT COMMAND JSON": if user_input == "GENERATE NEXT COMMAND JSON":
logger.log( logger.typewriter_log(
"-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=", "-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=",
Fore.MAGENTA, Fore.MAGENTA,
"") "")
@@ -391,7 +391,7 @@ while True:
break break
else: else:
# Print command # Print command
logger.log( logger.typewriter_log(
"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}")
@@ -416,9 +416,9 @@ while True:
# history # history
if result is not None: if result is not None:
full_message_history.append(chat.create_chat_message("system", result)) full_message_history.append(chat.create_chat_message("system", result))
logger.log("SYSTEM: ", Fore.YELLOW, result) logger.typewriter_log("SYSTEM: ", Fore.YELLOW, result)
else: else:
full_message_history.append( full_message_history.append(
chat.create_chat_message( chat.create_chat_message(
"system", "Unable to execute command")) "system", "Unable to execute command"))
logger.log("SYSTEM: ", Fore.YELLOW, "Unable to execute command") logger.typewriter_log("SYSTEM: ", Fore.YELLOW, "Unable to execute command")