AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Fix PLAIN_OUTPUT for normal execution (#4904)
Reinier van der Leer35b072f7e886
diff --git a/autogpt/logs.py b/autogpt/logs.pyindex 535cce3223..7ff805428c 100644--- a/autogpt/logs.py+++ b/autogpt/logs.py@@ -7,7 +7,7 @@ import randomimport reimport timefrom logging import LogRecord-from typing import TYPE_CHECKING, Any+from typing import TYPE_CHECKING, Any, Optionalfrom 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] = Noneself.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:diff --git a/autogpt/main.py b/autogpt/main.pyindex 26e8e331f8..73d5ea9881 100644--- a/autogpt/main.py+++ b/autogpt/main.py@@ -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 = speakconfig = ConfigBuilder.build_config_from_env()# HACK: This is a hack to allow the config into the logger without having to pass it around everywherediff --git a/tests/conftest.py b/tests/conftest.pyindex f2ca5904ea..14f6af786b 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -10,7 +10,6 @@ from autogpt.agent.agent import Agentfrom autogpt.config import AIConfig, Config, ConfigBuilderfrom autogpt.config.ai_config import AIConfigfrom autogpt.llm.api_manager import ApiManager-from autogpt.logs import TypingConsoleHandlerfrom autogpt.memory.vector import get_memoryfrom autogpt.models.command_registry import CommandRegistryfrom autogpt.prompts.prompt import DEFAULT_TRIGGERING_PROMPT@@ -81,18 +80,6 @@ def api_manager() -> ApiManager:return ApiManager()[email protected](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.fixturedef agent(config: Config, workspace: Workspace) -> Agent:ai_config = AIConfig(