mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-10 01:34:22 +01:00
Clean up logging output
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -239,8 +239,6 @@ def create_chat_completion(
|
||||
messages=messages,
|
||||
**kwargs,
|
||||
)
|
||||
if not hasattr(completion, "error"):
|
||||
logger.debug(f"Response: {completion}")
|
||||
return completion
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user