Move misc printing functions from app.main to app.utils

This commit is contained in:
Reinier van der Leer
2023-10-08 09:54:55 -07:00
parent 34352afd53
commit 12656646ae
2 changed files with 45 additions and 43 deletions

View File

@@ -19,10 +19,11 @@ from autogpt.app.setup import interactive_ai_profile_setup
from autogpt.app.spinner import Spinner
from autogpt.app.utils import (
clean_input,
get_current_git_branch,
get_latest_bulletin,
get_legal_warning,
markdown_to_ansi_style,
print_git_branch_info,
print_motd,
print_python_version_info,
)
from autogpt.commands import COMMAND_CATEGORIES
from autogpt.config import (
@@ -173,47 +174,6 @@ async def run_auto_gpt(
await run_interaction_loop(agent)
def print_motd(config: Config, logger: logging.Logger):
motd, is_new_motd = get_latest_bulletin()
if motd:
motd = markdown_to_ansi_style(motd)
for motd_line in motd.split("\n"):
logger.info(
extra={
"title": "NEWS:",
"title_color": Fore.GREEN,
"preserve_color": True,
},
msg=motd_line,
)
if is_new_motd and not config.chat_messages_enabled:
input(
Fore.MAGENTA
+ Style.BRIGHT
+ "NEWS: Bulletin was updated! Press Enter to continue..."
+ Style.RESET_ALL
)
def print_git_branch_info(logger: logging.Logger):
git_branch = get_current_git_branch()
if git_branch and git_branch != "stable":
logger.warn(
f"You are running on `{git_branch}` branch"
" - this is not a supported branch."
)
def print_python_version_info(logger: logging.Logger):
if sys.version_info < (3, 10):
logger.error(
"WARNING: You are running on an older version of Python. "
"Some people have observed problems with certain "
"parts of AutoGPT with this version. "
"Please consider upgrading to Python 3.10 or higher.",
)
def _configure_openai_provider(config: Config) -> OpenAIProvider:
"""Create a configured OpenAIProvider object.

View File

@@ -1,6 +1,7 @@
import logging
import os
import re
import sys
import requests
from colorama import Fore, Style
@@ -146,3 +147,44 @@ behalf. You acknowledge that using the System could expose you to potential liab
By using the System, you agree to indemnify, defend, and hold harmless the Project Parties from and against any and all claims, liabilities, damages, losses, or expenses (including reasonable attorneys' fees and costs) arising out of or in connection with your use of the System, including, without limitation, any actions taken by the System on your behalf, any failure to properly supervise or monitor the System, and any resulting harm or unintended consequences.
"""
return legal_text
def print_motd(config: Config, logger: logging.Logger):
motd, is_new_motd = get_latest_bulletin()
if motd:
motd = markdown_to_ansi_style(motd)
for motd_line in motd.split("\n"):
logger.info(
extra={
"title": "NEWS:",
"title_color": Fore.GREEN,
"preserve_color": True,
},
msg=motd_line,
)
if is_new_motd and not config.chat_messages_enabled:
input(
Fore.MAGENTA
+ Style.BRIGHT
+ "NEWS: Bulletin was updated! Press Enter to continue..."
+ Style.RESET_ALL
)
def print_git_branch_info(logger: logging.Logger):
git_branch = get_current_git_branch()
if git_branch and git_branch != "stable":
logger.warn(
f"You are running on `{git_branch}` branch"
" - this is not a supported branch."
)
def print_python_version_info(logger: logging.Logger):
if sys.version_info < (3, 10):
logger.error(
"WARNING: You are running on an older version of Python. "
"Some people have observed problems with certain "
"parts of AutoGPT with this version. "
"Please consider upgrading to Python 3.10 or higher.",
)