Skip to content

Commit

Permalink
Clean up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Aug 22, 2023
1 parent 3fe2246 commit 4e761b4
Show file tree
Hide file tree
Showing 49 changed files with 611 additions and 488 deletions.
4 changes: 3 additions & 1 deletion autogpt/agents/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import logging
import time
from datetime import datetime
from typing import TYPE_CHECKING, Optional
Expand All @@ -21,7 +22,6 @@
from autogpt.llm.api_manager import ApiManager
from autogpt.llm.base import Message
from autogpt.llm.utils import count_string_tokens
from autogpt.logs import logger
from autogpt.logs.log_cycle import (
CURRENT_CONTEXT_FILE_NAME,
FULL_MESSAGE_HISTORY_FILE_NAME,
Expand All @@ -41,6 +41,8 @@

from .base import BaseAgent

logger = logging.getLogger(__name__)


class Agent(BaseAgent):
"""Agent class for interacting with Auto-GPT."""
Expand Down
5 changes: 3 additions & 2 deletions autogpt/agents/base.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from __future__ import annotations

import logging
import re
from abc import ABCMeta, abstractmethod
from typing import TYPE_CHECKING, Any, Literal, Optional

if TYPE_CHECKING:
from autogpt.config import AIConfig, Config

from autogpt.models.command_registry import CommandRegistry

from autogpt.agents.utils.exceptions import InvalidAgentResponseError
from autogpt.llm.base import ChatModelResponse, ChatSequence, Message
from autogpt.llm.providers.openai import OPEN_AI_CHAT_MODELS, get_openai_command_specs
from autogpt.llm.utils import count_message_tokens, create_chat_completion
from autogpt.logs import logger
from autogpt.memory.message_history import MessageHistory
from autogpt.models.agent_actions import ActionResult
from autogpt.prompts.prompt import DEFAULT_TRIGGERING_PROMPT

logger = logging.getLogger(__name__)

CommandName = str
CommandArgs = dict[str, str]
AgentThoughts = dict[str, Any]
Expand Down
4 changes: 3 additions & 1 deletion autogpt/agents/planning_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
import re
from datetime import datetime
from typing import TYPE_CHECKING, Literal, Optional
Expand All @@ -14,7 +15,6 @@
from autogpt.json_utils.utilities import extract_dict_from_response, validate_dict
from autogpt.llm.base import Message
from autogpt.llm.utils import count_string_tokens
from autogpt.logs import logger
from autogpt.logs.log_cycle import (
CURRENT_CONTEXT_FILE_NAME,
NEXT_ACTION_FILE_NAME,
Expand All @@ -35,6 +35,8 @@
from .base import BaseAgent
from .utils.context import AgentContext

logger = logging.getLogger(__name__)


class PlanningAgent(BaseAgent):
"""Agent class for interacting with Auto-GPT."""
Expand Down
74 changes: 35 additions & 39 deletions autogpt/app/configurator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Configurator module."""
from __future__ import annotations

import logging
from typing import Literal

import click
Expand All @@ -10,9 +11,11 @@
from autogpt.config import Config
from autogpt.config.config import GPT_3_MODEL, GPT_4_MODEL
from autogpt.llm.api_manager import ApiManager
from autogpt.logs import logger
from autogpt.logs.helpers import print_attribute, request_user_double_check
from autogpt.memory.vector import get_supported_memory_backends

logger = logging.getLogger(__name__)


def create_config(
config: Config,
Expand Down Expand Up @@ -52,37 +55,33 @@ def create_config(
config.speak_mode = False

if debug:
logger.typewriter_log("Debug Mode: ", Fore.GREEN, "ENABLED")
print_attribute("Debug mode", "ENABLED")
config.debug_mode = True

if continuous:
logger.typewriter_log("Continuous Mode: ", Fore.RED, "ENABLED")
logger.typewriter_log(
"WARNING: ",
Fore.RED,
print_attribute("Continuous Mode", "ENABLED", title_color=Fore.YELLOW)
logger.warning(
"Continuous mode is not recommended. It is potentially dangerous and may"
" cause your AI to run forever or carry out actions you would not usually"
" authorise. Use at your own risk.",
)
config.continuous_mode = True

if continuous_limit:
logger.typewriter_log(
"Continuous Limit: ", Fore.GREEN, f"{continuous_limit}"
)
print_attribute("Continuous Limit", continuous_limit)
config.continuous_limit = continuous_limit

# Check if continuous limit is used without continuous mode
if continuous_limit and not continuous:
raise click.UsageError("--continuous-limit can only be used with --continuous")

if speak:
logger.typewriter_log("Speak Mode: ", Fore.GREEN, "ENABLED")
print_attribute("Speak Mode", "ENABLED")
config.speak_mode = True

# Set the default LLM models
if gpt3only:
logger.typewriter_log("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED")
print_attribute("GPT3.5 Only Mode", "ENABLED")
# --gpt3only should always use gpt-3.5-turbo, despite user's FAST_LLM config
config.fast_llm = GPT_3_MODEL
config.smart_llm = GPT_3_MODEL
Expand All @@ -91,7 +90,7 @@ def create_config(
and check_model(GPT_4_MODEL, model_type="smart_llm", config=config)
== GPT_4_MODEL
):
logger.typewriter_log("GPT4 Only Mode: ", Fore.GREEN, "ENABLED")
print_attribute("GPT4 Only Mode", "ENABLED")
# --gpt4only should always use gpt-4, despite user's SMART_LLM config
config.fast_llm = GPT_4_MODEL
config.smart_llm = GPT_4_MODEL
Expand All @@ -103,17 +102,21 @@ def create_config(
supported_memory = get_supported_memory_backends()
chosen = memory_type
if chosen not in supported_memory:
logger.typewriter_log(
"ONLY THE FOLLOWING MEMORY BACKENDS ARE SUPPORTED: ",
Fore.RED,
f"{supported_memory}",
logger.warning(
extra={
"title": "ONLY THE FOLLOWING MEMORY BACKENDS ARE SUPPORTED:",
"title_color": Fore.RED,
},
msg=f"{supported_memory}",
)
print_attribute(
"Defaulting to", config.memory_backend, title_color=Fore.YELLOW
)
logger.typewriter_log("Defaulting to: ", Fore.YELLOW, config.memory_backend)
else:
config.memory_backend = chosen

if skip_reprompt:
logger.typewriter_log("Skip Re-prompt: ", Fore.GREEN, "ENABLED")
print_attribute("Skip Re-prompt", "ENABLED")
config.skip_reprompt = True

if ai_settings_file:
Expand All @@ -122,11 +125,11 @@ def create_config(
# Validate file
(validated, message) = utils.validate_yaml_file(file)
if not validated:
logger.typewriter_log("FAILED FILE VALIDATION", Fore.RED, message)
logger.double_check()
logger.fatal(extra={"title": "FAILED FILE VALIDATION:"}, msg=message)
request_user_double_check()
exit(1)

logger.typewriter_log("Using AI Settings File:", Fore.GREEN, file)
print_attribute("Using AI Settings File", file)
config.ai_settings_file = file
config.skip_reprompt = True

Expand All @@ -136,28 +139,24 @@ def create_config(
# Validate file
(validated, message) = utils.validate_yaml_file(file)
if not validated:
logger.typewriter_log("FAILED FILE VALIDATION", Fore.RED, message)
logger.double_check()
logger.fatal(extra={"title": "FAILED FILE VALIDATION:"}, msg=message)
request_user_double_check()
exit(1)

logger.typewriter_log("Using Prompt Settings File:", Fore.GREEN, file)
print_attribute("Using Prompt Settings File", file)
config.prompt_settings_file = file

if browser_name:
config.selenium_web_browser = browser_name

if allow_downloads:
logger.typewriter_log("Native Downloading:", Fore.GREEN, "ENABLED")
logger.typewriter_log(
"WARNING: ",
Fore.YELLOW,
f"{Back.LIGHTYELLOW_EX}Auto-GPT will now be able to download and save files to your machine.{Back.RESET} "
+ "It is recommended that you monitor any files it downloads carefully.",
print_attribute("Native Downloading", "ENABLED")
logger.warn(
msg=f"{Back.LIGHTYELLOW_EX}Auto-GPT will now be able to download and save files to your machine.{Back.RESET}"
" It is recommended that you monitor any files it downloads carefully.",
)
logger.typewriter_log(
"WARNING: ",
Fore.YELLOW,
f"{Back.RED + Style.BRIGHT}ALWAYS REMEMBER TO NEVER OPEN FILES YOU AREN'T SURE OF!{Style.RESET_ALL}",
logger.warn(
msg=f"{Back.RED + Style.BRIGHT}ALWAYS REMEMBER TO NEVER OPEN FILES YOU AREN'T SURE OF!{Style.RESET_ALL}",
)
config.allow_downloads = True

Expand All @@ -178,10 +177,7 @@ def check_model(
if any(model_name in m["id"] for m in models):
return model_name

logger.typewriter_log(
"WARNING: ",
Fore.YELLOW,
f"You do not have access to {model_name}. Setting {model_type} to "
f"gpt-3.5-turbo.",
logger.warn(
f"You do not have access to {model_name}. Setting {model_type} to gpt-3.5-turbo."
)
return "gpt-3.5-turbo"
Loading

0 comments on commit 4e761b4

Please sign in to comment.