From 0d7fee779c7dd751ed68c518eb76b9dd513093bd Mon Sep 17 00:00:00 2001 From: Kye Date: Wed, 28 Feb 2024 16:09:01 -0800 Subject: [PATCH] [DOCS] --- docs/swarms/memory/qdrant.md | 3 ++- docs/swarms/tokenizers/basetokenizer.md | 1 - .../agents/multi_modal_auto_agent_example.py | 2 +- playground/agents/multion_agent.py | 3 ++- playground/memory/chroma_usage_example.py | 1 - .../structs/dialogue_simulator_example.py | 2 +- playground/structs/godmode_example.py | 2 +- playground/structs/kyle_hackathon.py | 1 + playground/structs/message_pool_example.py | 2 +- playground/tools/agent_with_tools_example.py | 2 +- swarms/agents/multion_agent.py | 3 ++- swarms/agents/worker_agent.py | 1 + swarms/models/__init__.py | 25 +++++-------------- swarms/models/azure_openai_llm.py | 20 +++++++-------- swarms/models/cog_vlm.py | 10 ++++---- swarms/models/fire_function.py | 6 +++-- swarms/models/test_fire_function.py | 1 + swarms/structs/agent.py | 2 +- swarms/structs/async_workflow.py | 2 +- swarms/structs/base_workflow.py | 2 +- swarms/structs/majority_voting.py | 6 ++--- swarms/structs/sequential_workflow.py | 3 +-- swarms/utils/video_to_frames.py | 3 ++- tests/agents/test_multion.py | 4 ++- tests/models/test_fire_function_caller.py | 1 - tests/structs/test_message_pool.py | 2 +- tests/utils/test_pdf_to_text.py | 1 + 27 files changed, 53 insertions(+), 58 deletions(-) diff --git a/docs/swarms/memory/qdrant.md b/docs/swarms/memory/qdrant.md index e234e7be..cfc65670 100644 --- a/docs/swarms/memory/qdrant.md +++ b/docs/swarms/memory/qdrant.md @@ -22,7 +22,8 @@ class Qdrant: collection_name: str = "qdrant", model_name: str = "BAAI/bge-small-en-v1.5", https: bool = True, - ): ... + ): + ... ``` ### Constructor Parameters diff --git a/docs/swarms/tokenizers/basetokenizer.md b/docs/swarms/tokenizers/basetokenizer.md index 8047f301..325640ee 100644 --- a/docs/swarms/tokenizers/basetokenizer.md +++ b/docs/swarms/tokenizers/basetokenizer.md @@ -27,7 +27,6 @@ from swarms.tokenizers import BaseTokenizer class SimpleTokenizer(BaseTokenizer): - def count_tokens(self, text: Union[str, List[dict]]) -> int: if isinstance(text, str): # Split text by spaces as a simple tokenization approach diff --git a/playground/agents/multi_modal_auto_agent_example.py b/playground/agents/multi_modal_auto_agent_example.py index a21aebb8..65f8fa2b 100644 --- a/playground/agents/multi_modal_auto_agent_example.py +++ b/playground/agents/multi_modal_auto_agent_example.py @@ -3,7 +3,7 @@ import os from dotenv import load_dotenv -from swarms import GPT4VisionAPI, Agent +from swarms import Agent, GPT4VisionAPI # Load the environment variables load_dotenv() diff --git a/playground/agents/multion_agent.py b/playground/agents/multion_agent.py index d1a02b8e..2bbe7e92 100644 --- a/playground/agents/multion_agent.py +++ b/playground/agents/multion_agent.py @@ -1,6 +1,7 @@ -from swarms.agents.multion_agent import MultiOnAgent import timeit + from swarms import Agent, ConcurrentWorkflow, Task +from swarms.agents.multion_agent import MultiOnAgent # model model = MultiOnAgent(multion_api_key="api-key") diff --git a/playground/memory/chroma_usage_example.py b/playground/memory/chroma_usage_example.py index 4f45117e..b2fc3ce0 100644 --- a/playground/memory/chroma_usage_example.py +++ b/playground/memory/chroma_usage_example.py @@ -1,6 +1,5 @@ from swarms.memory import ChromaDB - # Initialize the memory chroma = ChromaDB( metric="cosine", diff --git a/playground/structs/dialogue_simulator_example.py b/playground/structs/dialogue_simulator_example.py index b83e13ef..a7cdfe16 100644 --- a/playground/structs/dialogue_simulator_example.py +++ b/playground/structs/dialogue_simulator_example.py @@ -1,5 +1,5 @@ -from swarms.models import OpenAIChat from swarms import DialogueSimulator, Worker +from swarms.models import OpenAIChat llm = OpenAIChat( model_name="gpt-4", openai_api_key="api-key", temperature=0.5 diff --git a/playground/structs/godmode_example.py b/playground/structs/godmode_example.py index 5d3cef83..53e6b32e 100644 --- a/playground/structs/godmode_example.py +++ b/playground/structs/godmode_example.py @@ -2,8 +2,8 @@ import os from dotenv import load_dotenv -from swarms.models import Anthropic, Gemini, Mixtral, OpenAIChat from swarms import ModelParallelizer +from swarms.models import Anthropic, Gemini, Mixtral, OpenAIChat load_dotenv() diff --git a/playground/structs/kyle_hackathon.py b/playground/structs/kyle_hackathon.py index 48c15b39..1de48f1b 100644 --- a/playground/structs/kyle_hackathon.py +++ b/playground/structs/kyle_hackathon.py @@ -1,6 +1,7 @@ import os from dotenv import load_dotenv + from swarms import Agent, OpenAIChat from swarms.agents.multion_agent import MultiOnAgent from swarms.memory.chroma_db import ChromaDB diff --git a/playground/structs/message_pool_example.py b/playground/structs/message_pool_example.py index dca596ba..6dbad128 100644 --- a/playground/structs/message_pool_example.py +++ b/playground/structs/message_pool_example.py @@ -1,6 +1,6 @@ +from swarms import OpenAIChat from swarms.structs.agent import Agent from swarms.structs.message_pool import MessagePool -from swarms import OpenAIChat agent1 = Agent(llm=OpenAIChat(), agent_name="agent1") agent2 = Agent(llm=OpenAIChat(), agent_name="agent2") diff --git a/playground/tools/agent_with_tools_example.py b/playground/tools/agent_with_tools_example.py index 4524edf1..35b61703 100644 --- a/playground/tools/agent_with_tools_example.py +++ b/playground/tools/agent_with_tools_example.py @@ -2,7 +2,7 @@ import os from dotenv import load_dotenv -from swarms import OpenAIChat, Agent +from swarms import Agent, OpenAIChat from swarms.tools.tool import tool load_dotenv() diff --git a/swarms/agents/multion_agent.py b/swarms/agents/multion_agent.py index 2ef66b47..efeb5a43 100644 --- a/swarms/agents/multion_agent.py +++ b/swarms/agents/multion_agent.py @@ -1,8 +1,9 @@ import os + import multion +from dotenv import load_dotenv from swarms.models.base_llm import AbstractLLM -from dotenv import load_dotenv # Load environment variables load_dotenv() diff --git a/swarms/agents/worker_agent.py b/swarms/agents/worker_agent.py index 6dffc483..c0e7f464 100644 --- a/swarms/agents/worker_agent.py +++ b/swarms/agents/worker_agent.py @@ -6,6 +6,7 @@ from langchain.docstore import InMemoryDocstore from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import FAISS from langchain_experimental.autonomous_agents import AutoGPT + from swarms.tools.tool import BaseTool from swarms.utils.decorators import error_decorator, timing_decorator diff --git a/swarms/models/__init__.py b/swarms/models/__init__.py index 8981f70e..3f8fb3e2 100644 --- a/swarms/models/__init__.py +++ b/swarms/models/__init__.py @@ -1,9 +1,7 @@ from swarms.models.anthropic import Anthropic # noqa: E402 from swarms.models.base_embedding_model import BaseEmbeddingModel from swarms.models.base_llm import AbstractLLM # noqa: E402 -from swarms.models.base_multimodal_model import ( - BaseMultiModalModel, -) +from swarms.models.base_multimodal_model import BaseMultiModalModel # noqa: E402 from swarms.models.biogpt import BioGPT # noqa: E402 @@ -15,9 +13,7 @@ from swarms.models.clipq import CLIPQ # noqa: E402 # from swarms.models.kosmos_two import Kosmos # noqa: E402 # from swarms.models.cog_agent import CogAgent # noqa: E402 ## Function calling models -from swarms.models.fire_function import ( - FireFunctionCaller, -) +from swarms.models.fire_function import FireFunctionCaller from swarms.models.fuyu import Fuyu # noqa: E402 from swarms.models.gemini import Gemini # noqa: E402 from swarms.models.gigabind import Gigabind # noqa: E402 @@ -25,9 +21,7 @@ from swarms.models.gpt4_vision_api import GPT4VisionAPI # noqa: E402 from swarms.models.huggingface import HuggingfaceLLM # noqa: E402 from swarms.models.idefics import Idefics # noqa: E402 from swarms.models.kosmos_two import Kosmos # noqa: E402 -from swarms.models.layoutlm_document_qa import ( - LayoutLMDocumentQA, -) +from swarms.models.layoutlm_document_qa import LayoutLMDocumentQA # noqa: E402 from swarms.models.llava import LavaMultiModal # noqa: E402 @@ -47,10 +41,7 @@ from swarms.models.petals import Petals # noqa: E402 from swarms.models.qwen import QwenVLMultiModal # noqa: E402 from swarms.models.roboflow_model import RoboflowMultiModal from swarms.models.sam_supervision import SegmentAnythingMarkGenerator -from swarms.models.sampling_params import ( - SamplingParams, - SamplingType, -) +from swarms.models.sampling_params import SamplingParams, SamplingType from swarms.models.timm import TimmModel # noqa: E402 # from swarms.models.modelscope_pipeline import ModelScopePipeline @@ -67,15 +58,11 @@ from swarms.models.types import ( # noqa: E402 TextModality, VideoModality, ) -from swarms.models.ultralytics_model import ( - UltralyticsModel, -) +from swarms.models.ultralytics_model import UltralyticsModel # noqa: E402 from swarms.models.vilt import Vilt # noqa: E402 -from swarms.models.wizard_storytelling import ( - WizardLLMStoryTeller, -) +from swarms.models.wizard_storytelling import WizardLLMStoryTeller # noqa: E402 # from swarms.models.vllm import vLLM # noqa: E402 diff --git a/swarms/models/azure_openai_llm.py b/swarms/models/azure_openai_llm.py index 3ff8bd22..aebb03fb 100644 --- a/swarms/models/azure_openai_llm.py +++ b/swarms/models/azure_openai_llm.py @@ -2,7 +2,7 @@ from __future__ import annotations import logging import os -from typing import Any, Callable, Dict, List, Mapping, Optional, Union +from typing import Any, Callable, Mapping import openai from langchain_core.pydantic_v1 import ( @@ -36,14 +36,14 @@ class AzureOpenAI(BaseOpenAI): openai = AzureOpenAI(model_name="gpt-3.5-turbo-instruct") """ - azure_endpoint: Union[str, None] = None + azure_endpoint: str | None = None """Your Azure endpoint, including the resource. Automatically inferred from env var `AZURE_OPENAI_ENDPOINT` if not provided. Example: `https://example-resource.azure.openai.com/` """ - deployment_name: Union[str, None] = Field( + deployment_name: str | None = Field( default=None, alias="azure_deployment" ) """A model deployment. @@ -53,11 +53,11 @@ class AzureOpenAI(BaseOpenAI): """ openai_api_version: str = Field(default="", alias="api_version") """Automatically inferred from env var `OPENAI_API_VERSION` if not provided.""" - openai_api_key: Optional[SecretStr] = Field( + openai_api_key: SecretStr | None = Field( default=None, alias="api_key" ) """Automatically inferred from env var `AZURE_OPENAI_API_KEY` if not provided.""" - azure_ad_token: Optional[SecretStr] = None + azure_ad_token: SecretStr | None = None """Your Azure Active Directory token. Automatically inferred from env var `AZURE_OPENAI_AD_TOKEN` if not provided. @@ -65,7 +65,7 @@ class AzureOpenAI(BaseOpenAI): For more: https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id. """ # noqa: E501 - azure_ad_token_provider: Union[Callable[[], str], None] = None + azure_ad_token_provider: Callable[[], str] | None = None """A function that returns an Azure Active Directory token. Will be invoked on every request. @@ -78,12 +78,12 @@ class AzureOpenAI(BaseOpenAI): """ @classmethod - def get_lc_namespace(cls) -> List[str]: + def get_lc_namespace(cls) -> list[str]: """Get the namespace of the langchain object.""" return ["langchain", "llms", "openai"] @root_validator() - def validate_environment(cls, values: Dict) -> Dict: + def validate_environment(cls, values: dict) -> dict: """Validate that api key and python package exists in environment.""" if values["n"] < 1: raise ValueError("n must be at least 1.") @@ -206,7 +206,7 @@ class AzureOpenAI(BaseOpenAI): } @property - def _invocation_params(self) -> Dict[str, Any]: + def _invocation_params(self) -> dict[str, Any]: openai_params = {"model": self.deployment_name} return {**openai_params, **super()._invocation_params} @@ -216,7 +216,7 @@ class AzureOpenAI(BaseOpenAI): return "azure" @property - def lc_attributes(self) -> Dict[str, Any]: + def lc_attributes(self) -> dict[str, Any]: return { "openai_api_type": self.openai_api_type, "openai_api_version": self.openai_api_version, diff --git a/swarms/models/cog_vlm.py b/swarms/models/cog_vlm.py index e456b669..a3f820c5 100644 --- a/swarms/models/cog_vlm.py +++ b/swarms/models/cog_vlm.py @@ -209,8 +209,6 @@ class CogVLMMultiModal(BaseMultiModalModel): total_gb = total_bytes / (1 << 30) if total_gb < 40: pass - else: - pass torch.cuda.empty_cache() @@ -462,7 +460,7 @@ class CogVLMMultiModal(BaseMultiModalModel): elif role == "assistant": if formatted_history: if formatted_history[-1][1] != "": - assert False, ( + raise AssertionError( "the last query is answered. answer" f" again. {formatted_history[-1][0]}," f" {formatted_history[-1][1]}," @@ -473,9 +471,11 @@ class CogVLMMultiModal(BaseMultiModalModel): text_content, ) else: - assert False, "assistant reply before user" + raise AssertionError( + "assistant reply before user" + ) else: - assert False, f"unrecognized role: {role}" + raise AssertionError(f"unrecognized role: {role}") return last_user_query, formatted_history, image_list diff --git a/swarms/models/fire_function.py b/swarms/models/fire_function.py index 6803d822..f61ec2bd 100644 --- a/swarms/models/fire_function.py +++ b/swarms/models/fire_function.py @@ -1,8 +1,10 @@ -from transformers import AutoModelForCausalLM, AutoTokenizer import json -from swarms.models.base_llm import AbstractLLM from typing import Any +from transformers import AutoModelForCausalLM, AutoTokenizer + +from swarms.models.base_llm import AbstractLLM + class FireFunctionCaller(AbstractLLM): """ diff --git a/swarms/models/test_fire_function.py b/swarms/models/test_fire_function.py index b6a67c37..082d954d 100644 --- a/swarms/models/test_fire_function.py +++ b/swarms/models/test_fire_function.py @@ -1,4 +1,5 @@ from unittest.mock import MagicMock + from swarms.models.fire_function import FireFunctionCaller diff --git a/swarms/structs/agent.py b/swarms/structs/agent.py index 412dc02d..9d2a5e1a 100644 --- a/swarms/structs/agent.py +++ b/swarms/structs/agent.py @@ -8,6 +8,7 @@ import time import uuid from typing import Any, Callable, Dict, List, Optional, Tuple +import yaml from loguru import logger from termcolor import colored @@ -31,7 +32,6 @@ from swarms.utils.video_to_frames import ( save_frames_as_images, video_to_frames, ) -import yaml # Utils diff --git a/swarms/structs/async_workflow.py b/swarms/structs/async_workflow.py index 0d5e85b7..6cf9e312 100644 --- a/swarms/structs/async_workflow.py +++ b/swarms/structs/async_workflow.py @@ -2,9 +2,9 @@ import asyncio from dataclasses import dataclass, field from typing import Any, Callable, List, Optional +from swarms.structs.agent import Agent from swarms.structs.task import Task from swarms.utils.logger import logger -from swarms.structs.agent import Agent @dataclass diff --git a/swarms/structs/base_workflow.py b/swarms/structs/base_workflow.py index f91f994a..17b98ce8 100644 --- a/swarms/structs/base_workflow.py +++ b/swarms/structs/base_workflow.py @@ -3,9 +3,9 @@ from typing import Any, Dict, List, Optional from termcolor import colored +from swarms.structs.agent import Agent from swarms.structs.base import BaseStructure from swarms.structs.task import Task -from swarms.structs.agent import Agent from swarms.utils.loguru_logger import logger diff --git a/swarms/structs/majority_voting.py b/swarms/structs/majority_voting.py index fc4f8018..a2b414ba 100644 --- a/swarms/structs/majority_voting.py +++ b/swarms/structs/majority_voting.py @@ -1,15 +1,15 @@ import asyncio import concurrent.futures import re +import sys from collections import Counter from multiprocessing import Pool from typing import Any, List -from swarms.structs.agent import Agent -from swarms.structs.conversation import Conversation from loguru import logger -import sys +from swarms.structs.agent import Agent +from swarms.structs.conversation import Conversation # Configure loguru logger with advanced settings logger.remove() diff --git a/swarms/structs/sequential_workflow.py b/swarms/structs/sequential_workflow.py index 4db797fe..7c94f426 100644 --- a/swarms/structs/sequential_workflow.py +++ b/swarms/structs/sequential_workflow.py @@ -3,11 +3,10 @@ from typing import Any, Dict, List, Optional from termcolor import colored -from swarms.structs.task import Task - # from swarms.utils.logger import logger from swarms.structs.agent import Agent from swarms.structs.conversation import Conversation +from swarms.structs.task import Task from swarms.utils.loguru_logger import logger diff --git a/swarms/utils/video_to_frames.py b/swarms/utils/video_to_frames.py index ae16610c..528e45b0 100644 --- a/swarms/utils/video_to_frames.py +++ b/swarms/utils/video_to_frames.py @@ -1,6 +1,7 @@ -import cv2 from typing import List +import cv2 + def video_to_frames(video_file: str) -> List: """ diff --git a/tests/agents/test_multion.py b/tests/agents/test_multion.py index 8da68e23..23614934 100644 --- a/tests/agents/test_multion.py +++ b/tests/agents/test_multion.py @@ -1,5 +1,7 @@ +from unittest.mock import MagicMock, patch + import pytest -from unittest.mock import patch, MagicMock + from swarms.agents.multion_agent import MultiOnAgent diff --git a/tests/models/test_fire_function_caller.py b/tests/models/test_fire_function_caller.py index 703417a7..082d954d 100644 --- a/tests/models/test_fire_function_caller.py +++ b/tests/models/test_fire_function_caller.py @@ -1,6 +1,5 @@ from unittest.mock import MagicMock - from swarms.models.fire_function import FireFunctionCaller diff --git a/tests/structs/test_message_pool.py b/tests/structs/test_message_pool.py index 91d0c28b..cfbb4df5 100644 --- a/tests/structs/test_message_pool.py +++ b/tests/structs/test_message_pool.py @@ -1,6 +1,6 @@ +from swarms import OpenAIChat from swarms.structs.agent import Agent from swarms.structs.message_pool import MessagePool -from swarms import OpenAIChat def test_message_pool_initialization(): diff --git a/tests/utils/test_pdf_to_text.py b/tests/utils/test_pdf_to_text.py index f271af60..257364b4 100644 --- a/tests/utils/test_pdf_to_text.py +++ b/tests/utils/test_pdf_to_text.py @@ -1,5 +1,6 @@ import pypdf import pytest + from swarms.utils import pdf_to_text