Fix PLAIN_OUTPUT for normal execution (#4904)

This commit is contained in:
Reinier van der Leer
2023-07-07 06:53:44 +02:00
committed by GitHub
parent 3b7e1014f6
commit 35b072f7e8
3 changed files with 14 additions and 18 deletions

View File

@@ -7,7 +7,7 @@ import random
import re
import time
from logging import LogRecord
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Optional
from colorama import Fore, Style
@@ -85,16 +85,26 @@ class Logger(metaclass=Singleton):
self.json_logger.addHandler(error_handler)
self.json_logger.setLevel(logging.DEBUG)
self.speak_mode = False
self.config = None
self._config: Optional[Config] = None
self.chat_plugins = []
@property
def config(self) -> Config | None:
return self._config
@config.setter
def config(self, config: Config):
self._config = config
if config.plain_output:
self.typing_logger.removeHandler(self.typing_console_handler)
self.typing_logger.addHandler(self.console_handler)
def typewriter_log(
self, title="", title_color="", content="", speak_text=False, level=logging.INFO
):
from autogpt.speech import say_text
if speak_text and self.speak_mode:
if speak_text and self.config and self.config.speak_mode:
say_text(f"{title}. {content}", self.config)
for plugin in self.chat_plugins:

View File

@@ -55,7 +55,6 @@ def run_auto_gpt(
):
# Configure logging before we do anything else.
logger.set_level(logging.DEBUG if debug else logging.INFO)
logger.speak_mode = speak
config = ConfigBuilder.build_config_from_env()
# HACK: This is a hack to allow the config into the logger without having to pass it around everywhere

View File

@@ -10,7 +10,6 @@ from autogpt.agent.agent import Agent
from autogpt.config import AIConfig, Config, ConfigBuilder
from autogpt.config.ai_config import AIConfig
from autogpt.llm.api_manager import ApiManager
from autogpt.logs import TypingConsoleHandler
from autogpt.memory.vector import get_memory
from autogpt.models.command_registry import CommandRegistry
from autogpt.prompts.prompt import DEFAULT_TRIGGERING_PROMPT
@@ -81,18 +80,6 @@ def api_manager() -> ApiManager:
return ApiManager()
@pytest.fixture(autouse=True)
def patch_emit(monkeypatch):
# convert plain_output to a boolean
if bool(os.environ.get("PLAIN_OUTPUT")):
def quick_emit(self, record: str):
print(self.format(record))
monkeypatch.setattr(TypingConsoleHandler, "emit", quick_emit)
@pytest.fixture
def agent(config: Config, workspace: Workspace) -> Agent:
ai_config = AIConfig(