diff --git a/autogpt/app/main.py b/autogpt/app/main.py index 1fdabd50..312bdfa8 100644 --- a/autogpt/app/main.py +++ b/autogpt/app/main.py @@ -213,7 +213,7 @@ def run_interaction_loop( ai_config = agent.ai_config logger = logging.getLogger(__name__) - logger.debug(f"{ai_config.ai_name} System Prompt: {agent.system_prompt}") + logger.debug(f"{ai_config.ai_name} System Prompt:\n{agent.system_prompt}") cycle_budget = cycles_remaining = _get_cycle_budget( config.continuous_mode, config.continuous_limit diff --git a/autogpt/llm/providers/openai.py b/autogpt/llm/providers/openai.py index 12dcf044..ec9dbb11 100644 --- a/autogpt/llm/providers/openai.py +++ b/autogpt/llm/providers/openai.py @@ -239,8 +239,6 @@ def create_chat_completion( messages=messages, **kwargs, ) - if not hasattr(completion, "error"): - logger.debug(f"Response: {completion}") return completion diff --git a/autogpt/logs/__init__.py b/autogpt/logs/__init__.py index 803e1b50..9c46d1e5 100644 --- a/autogpt/logs/__init__.py +++ b/autogpt/logs/__init__.py @@ -1,4 +1,4 @@ -from .helpers import log_json, user_friendly_output +from .helpers import user_friendly_output from .log_cycle import ( CURRENT_CONTEXT_FILE_NAME, FULL_MESSAGE_HISTORY_FILE_NAME, diff --git a/autogpt/logs/config.py b/autogpt/logs/config.py index 5d4ffd28..b0118be0 100644 --- a/autogpt/logs/config.py +++ b/autogpt/logs/config.py @@ -7,6 +7,7 @@ from pathlib import Path from typing import TYPE_CHECKING from auto_gpt_plugin_template import AutoGPTPluginTemplate +from openai.util import logger as openai_logger if TYPE_CHECKING: from autogpt.config import Config @@ -84,14 +85,15 @@ def configure_logging(config: Config, log_dir: Path = LOG_DIR) -> None: typing_console_handler if not config.plain_output else console_handler ) user_friendly_output_logger.addHandler(TTSHandler(config)) - user_friendly_output_logger.addHandler(activity_log_handler) - user_friendly_output_logger.addHandler(error_log_handler) user_friendly_output_logger.setLevel(logging.DEBUG) + # JSON logger with better formatting json_logger = logging.getLogger("JSON_LOGGER") - json_logger.addHandler(activity_log_handler) - json_logger.addHandler(error_log_handler) json_logger.setLevel(logging.DEBUG) + json_logger.propagate = False + + # Disable debug logging from OpenAI library + openai_logger.setLevel(logging.INFO) def configure_chat_plugins(config: Config) -> None: diff --git a/autogpt/logs/helpers.py b/autogpt/logs/helpers.py index 2b4766a4..e0c90b52 100644 --- a/autogpt/logs/helpers.py +++ b/autogpt/logs/helpers.py @@ -1,11 +1,9 @@ import logging -from pathlib import Path from typing import Any, Optional from colorama import Fore from .config import USER_FRIENDLY_OUTPUT_LOGGER, _chat_plugins -from .handlers import JsonFileHandler def user_friendly_output( @@ -55,16 +53,3 @@ def request_user_double_check(additionalText: Optional[str] = None) -> None: user_friendly_output( additionalText, level=logging.WARN, title="DOUBLE CHECK CONFIGURATION" ) - - -def log_json(data: Any, file_name: str | Path, log_dir: Path) -> None: - logger = logging.getLogger("JSON_LOGGER") - - # Create a handler for JSON files - json_file_path = log_dir / file_name - json_data_handler = JsonFileHandler(json_file_path) - - # Log the JSON data using the custom file handler - logger.addHandler(json_data_handler) - logger.debug(data) - logger.removeHandler(json_data_handler) diff --git a/autogpt/logs/log_cycle.py b/autogpt/logs/log_cycle.py index b7395c07..bb821d3c 100644 --- a/autogpt/logs/log_cycle.py +++ b/autogpt/logs/log_cycle.py @@ -3,8 +3,6 @@ import os from pathlib import Path from typing import Any, Dict, Union -from autogpt.logs.helpers import log_json - from .config import LOG_DIR DEFAULT_PREFIX = "agent" @@ -78,5 +76,7 @@ class LogCycleHandler: json_data = json.dumps(data, ensure_ascii=False, indent=4) log_file_path = cycle_log_dir / f"{self.log_count_within_cycle}_{file_name}" - log_json(json_data, log_file_path, LOG_DIR) + with open(log_file_path, "w", encoding="utf-8") as f: + f.write(json_data + "\n") + self.log_count_within_cycle += 1