Merge pull request #574 from richbeales/master
update print_to_console to log to a text filepull/688/head^2
commit
5cd48d51ee
|
@ -16,9 +16,18 @@ from ai_config import AIConfig
|
||||||
import traceback
|
import traceback
|
||||||
import yaml
|
import yaml
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
cfg = Config()
|
cfg = Config()
|
||||||
|
|
||||||
|
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 check_openai_api_key():
|
def check_openai_api_key():
|
||||||
"""Check if the OpenAI API key is set in config.py or as an environment variable."""
|
"""Check if the OpenAI API key is set in config.py or as an environment variable."""
|
||||||
if not cfg.openai_api_key:
|
if not cfg.openai_api_key:
|
||||||
|
@ -29,7 +38,6 @@ def check_openai_api_key():
|
||||||
print("You can get your key from https://beta.openai.com/account/api-keys")
|
print("You can get your key from https://beta.openai.com/account/api-keys")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def print_to_console(
|
def print_to_console(
|
||||||
title,
|
title,
|
||||||
title_color,
|
title_color,
|
||||||
|
@ -39,10 +47,12 @@ 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
|
||||||
|
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()
|
||||||
|
@ -295,6 +305,7 @@ def parse_arguments():
|
||||||
# TODO: fill in llm values here
|
# TODO: fill in llm values here
|
||||||
check_openai_api_key()
|
check_openai_api_key()
|
||||||
cfg = Config()
|
cfg = Config()
|
||||||
|
logger = configure_logging()
|
||||||
parse_arguments()
|
parse_arguments()
|
||||||
ai_name = ""
|
ai_name = ""
|
||||||
prompt = construct_prompt()
|
prompt = construct_prompt()
|
||||||
|
|
Loading…
Reference in New Issue