update print_to_console to log to a text file

Uses python logging module to output progress to a text file log.txt
This commit is contained in:
Richard Beales
2023-04-09 10:06:30 +01:00
committed by GitHub
parent 97711584c3
commit b87d126e32

View File

@@ -16,7 +16,15 @@ from ai_config import AIConfig
import traceback import traceback
import yaml import yaml
import argparse import argparse
import logging
def configure_logging():
logging.basicConfig(filename='log.txt',
filemode='a',
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
datefmt='%H:%M:%S',
level=logging.DEBUG)
return logging.getLogger('AutoGPT')
def print_to_console( def print_to_console(
title, title,
@@ -26,10 +34,12 @@ def print_to_console(
min_typing_speed=0.05, min_typing_speed=0.05,
max_typing_speed=0.01): max_typing_speed=0.01):
global cfg global cfg
global logger
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:
logger.info(title + ': ' + content)
if isinstance(content, list): if isinstance(content, list):
content = " ".join(content) content = " ".join(content)
words = content.split() words = content.split()
@@ -270,6 +280,7 @@ def parse_arguments():
# TODO: fill in llm values here # TODO: fill in llm values here
cfg = Config() cfg = Config()
logger = configure_logging()
parse_arguments() parse_arguments()
ai_name = "" ai_name = ""
prompt = construct_prompt() prompt = construct_prompt()
@@ -355,7 +366,7 @@ while True:
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}")
# Execute command # Execute command
if command_name.lower() == "error": if command_name.lower().startswith( "error" ):
result = f"Command {command_name} threw the following error: " + arguments result = f"Command {command_name} threw the following error: " + arguments
elif command_name == "human_feedback": elif command_name == "human_feedback":
result = f"Human feedback: {user_input}" result = f"Human feedback: {user_input}"
@@ -381,3 +392,4 @@ while True:
"system", "Unable to execute command")) "system", "Unable to execute command"))
print_to_console("SYSTEM: ", Fore.YELLOW, "Unable to execute command") print_to_console("SYSTEM: ", Fore.YELLOW, "Unable to execute command")