Skip to content

Commit

Permalink
[LOGGING CLEANUP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 16, 2024
1 parent 4a9a0ba commit 54dfa69
Show file tree
Hide file tree
Showing 31 changed files with 129 additions and 327 deletions.
4 changes: 3 additions & 1 deletion swarms/agents/ape_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any

from loguru import logger
from tenacity import retry, stop_after_attempt, wait_exponential

from swarms.prompts.prompt_generator import (
Expand All @@ -9,6 +8,9 @@
from swarms.prompts.prompt_generator_optimizer import (
prompt_generator_sys_prompt,
)
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="ape_agent")


@retry(
Expand Down
5 changes: 4 additions & 1 deletion swarms/agents/create_agents_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
from typing import Any, Callable, Dict, List, Tuple, Union

import yaml
from loguru import logger
from swarms.utils.loguru_logger import initialize_logger

from swarms.structs.agent import Agent
from swarms.structs.swarm_router import SwarmRouter


logger = initialize_logger(log_folder="create_agents_from_yaml")


def create_agents_from_yaml(
model: Callable = None,
yaml_file: str = "agents.yaml",
Expand Down
5 changes: 4 additions & 1 deletion swarms/cli/onboarding_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import time
from typing import Dict

from loguru import logger
from swarms.utils.loguru_logger import initialize_logger


from swarms.telemetry.capture_sys_data import (
capture_system_data,
log_agent_data,
)

logger = initialize_logger(log_folder="onboarding_process")


class OnboardingProcess:
"""
Expand Down
4 changes: 3 additions & 1 deletion swarms/prompts/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import uuid
from typing import Any, Callable, List

from loguru import logger
from pydantic import (
BaseModel,
Field,
Expand All @@ -17,6 +16,9 @@
log_agent_data,
)
from swarms.tools.base_tool import BaseTool
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(file_name="prompts")


class Prompt(BaseModel):
Expand Down
4 changes: 3 additions & 1 deletion swarms/structs/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
execute_on_gpu,
execute_with_cpu_cores,
)
from loguru import logger
from pydantic import BaseModel
from swarm_models.tiktoken_wrapper import TikTokenizer
from termcolor import colored
Expand Down Expand Up @@ -54,6 +53,9 @@
from swarms.utils.file_processing import create_file_in_folder
from swarms.utils.pdf_to_text import pdf_to_text
from swarms.artifacts.main_artifact import Artifact
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="agents")


# Utils
Expand Down
4 changes: 3 additions & 1 deletion swarms/structs/agent_router.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import List, Optional

import chromadb
from loguru import logger
from tenacity import retry, stop_after_attempt, wait_exponential
from typing import Union, Callable, Any
from swarms import Agent
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="agent_router")


class AgentRouter:
Expand Down
18 changes: 17 additions & 1 deletion swarms/structs/agents_available.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import os
from typing import List, Any
from loguru import logger
from swarms.structs.agent import Agent
from loguru import logger
import uuid

WORKSPACE_DIR = os.getenv("WORKSPACE_DIR")
uuid_for_log = str(uuid.uuid4())
logger.add(
os.path.join(
WORKSPACE_DIR,
"agents_available",
f"agents-available-{uuid_for_log}.log",
),
level="INFO",
colorize=True,
backtrace=True,
diagnose=True,
)


def get_agent_name(agent: Any) -> str:
Expand Down
3 changes: 3 additions & 0 deletions swarms/structs/auto_swarm_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from swarms.structs.agent import Agent
from swarms.structs.swarm_router import SwarmRouter
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="auto_swarm_builder")


class AgentConfig(BaseModel):
Expand Down
4 changes: 3 additions & 1 deletion swarms/structs/concurrent_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from datetime import datetime
from typing import Any, Dict, List, Optional, Union

from loguru import logger
from pydantic import BaseModel, Field
from tenacity import retry, stop_after_attempt, wait_exponential

Expand All @@ -19,6 +18,9 @@
execute_on_multiple_gpus,
list_available_gpus,
)
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="concurrent_workflow")


class AgentOutputSchema(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion swarms/structs/hiearchical_swarm.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import List, Any

from loguru import logger
from pydantic import BaseModel, Field
from swarms.utils.loguru_logger import initialize_logger
from swarms.structs.base_swarm import BaseSwarm
from swarms.structs.agent import Agent
from swarms.structs.concat import concat_strings
from swarms.structs.agent_registry import AgentRegistry
from swarm_models.base_llm import BaseLLM
from swarms.structs.conversation import Conversation

logger = initialize_logger(log_folder="hiearchical_swarm")

# Example usage:
HIEARCHICAL_AGENT_SYSTEM_PROMPT = """
Expand Down
16 changes: 2 additions & 14 deletions swarms/structs/majority_voting.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import concurrent.futures
import re
import sys
from collections import Counter
from typing import Any, Callable, List, Optional

from loguru import logger

from swarms.structs.agent import Agent
from swarms.structs.conversation import Conversation
from swarms.utils.file_processing import create_file
from swarms.utils.loguru_logger import initialize_logger

# Configure loguru logger with advanced settings
logger.remove()
logger.add(
sys.stderr,
colorize=True,
format="<green>{time}</green> <level>{message}</level>",
backtrace=True,
diagnose=True,
enqueue=True,
catch=True,
)
logger = initialize_logger(log_folder="majority_voting")


def extract_last_python_code_block(text):
Expand Down
4 changes: 3 additions & 1 deletion swarms/structs/mixture_of_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import time
from typing import Any, Dict, List, Optional

from loguru import logger
from pydantic import BaseModel, Field

from swarms.structs.agent import Agent
from swarms.telemetry.capture_sys_data import log_agent_data
from swarms.schemas.agent_step_schemas import ManySteps
from swarms.prompts.ag_prompt import aggregator_system_prompt
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="mixture_of_agents")

time_stamp = time.strftime("%Y-%m-%d %H:%M:%S")

Expand Down
4 changes: 3 additions & 1 deletion swarms/structs/spreadsheet_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from typing import List, Union

import aiofiles
from loguru import logger
from pydantic import BaseModel, Field

from swarms.structs.agent import Agent
from swarms.structs.base_swarm import BaseSwarm
from swarms.utils.file_processing import create_file_in_folder
from swarms.telemetry.capture_sys_data import log_agent_data
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="spreadsheet_swarm")

time = datetime.datetime.now().isoformat()
uuid_hex = uuid.uuid4().hex
Expand Down
4 changes: 3 additions & 1 deletion swarms/structs/swarm_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import torch
from transformers import AutoTokenizer, AutoModel
from pydantic import BaseModel, Field
from loguru import logger
import json
from tenacity import retry, stop_after_attempt, wait_exponential
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="swarm_matcher")


class SwarmType(BaseModel):
Expand Down
4 changes: 3 additions & 1 deletion swarms/structs/swarm_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any, Callable, Dict, List, Literal, Union

from doc_master import doc_master
from loguru import logger
from pydantic import BaseModel, Field
from tenacity import retry, stop_after_attempt, wait_fixed

Expand All @@ -18,6 +17,9 @@
from swarms.utils.wrapper_clusterop import (
exec_callable_with_clusterops,
)
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="swarm_router")

SwarmType = Literal[
"AgentRearrange",
Expand Down
4 changes: 3 additions & 1 deletion swarms/structs/swarming_architectures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import math
from typing import List, Union

from loguru import logger
from pydantic import BaseModel

from swarms.structs.agent import Agent
from swarms.structs.omni_agent_types import AgentListType
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="swarming_architectures")


# Define Pydantic schema for logging agent responses
Expand Down
6 changes: 4 additions & 2 deletions swarms/structs/tree_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from datetime import datetime
from typing import Any, List, Optional

from loguru import logger
from pydantic import BaseModel, Field
from sentence_transformers import SentenceTransformer, util

from swarms import Agent
from swarms.structs.agent import Agent
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="tree_swarm")

# Pretrained model for embeddings
embedding_model = SentenceTransformer(
Expand Down
15 changes: 12 additions & 3 deletions swarms/telemetry/auto_upgrade_swarms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import subprocess

from loguru import logger

from swarms.utils.loguru_logger import initialize_logger
from swarms.telemetry.check_update import check_for_update

logger = initialize_logger(log_folder="auto_upgrade_swarms")


def auto_update():
"""auto update swarms"""
Expand All @@ -13,7 +14,15 @@ def auto_update():
logger.info(
"There is a new version of swarms available! Downloading..."
)
subprocess.run(["pip", "install", "-U", "swarms"])
try:
subprocess.run(
["pip", "install", "-U", "swarms"], check=True
)
except subprocess.CalledProcessError:
logger.info("Attempting to install with pip3...")
subprocess.run(
["pip3", "install", "-U", "swarms"], check=True
)
else:
logger.info("swarms is up to date!")
except Exception as e:
Expand Down
5 changes: 4 additions & 1 deletion swarms/telemetry/capture_sys_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import socket
import psutil
import uuid
from loguru import logger
from typing import Dict
import requests

from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="capture_sys_data")


def capture_system_data() -> Dict[str, str]:
"""
Expand Down
4 changes: 3 additions & 1 deletion swarms/tools/tool_registry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from typing import Any, Callable, Dict, List, Optional
import time
from loguru import logger
from pydantic import BaseModel, Field
from concurrent.futures import ThreadPoolExecutor, as_completed
from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="tool_registry")


class ToolMetadata(BaseModel):
Expand Down
2 changes: 0 additions & 2 deletions swarms/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from swarms.utils.parse_code import extract_code_from_markdown
from swarms.utils.pdf_to_text import pdf_to_text
from swarms.utils.try_except_wrapper import try_except_wrapper
from swarms.utils.concurrent_utils import execute_concurrently
from swarms.utils.calculate_func_metrics import profile_func


Expand All @@ -37,6 +36,5 @@
"extract_code_from_markdown",
"pdf_to_text",
"try_except_wrapper",
"execute_concurrently",
"profile_func",
]
10 changes: 7 additions & 3 deletions swarms/utils/add_docs_to_agents.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Any, List, Optional, Union
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path
from loguru import logger
from typing import Any, List, Optional, Union

from doc_master import doc_master
from concurrent.futures import ThreadPoolExecutor, as_completed
from tenacity import retry, stop_after_attempt, wait_exponential

from swarms.utils.loguru_logger import initialize_logger

logger = initialize_logger(log_folder="add_docs_to_agents")


@retry(
stop=stop_after_attempt(3),
Expand Down
Loading

0 comments on commit 54dfa69

Please sign in to comment.