From 3213f8736be55c360130d1b7de2196b06a324eb0 Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 27 Jul 2023 19:08:23 -0400 Subject: [PATCH] clean up --- .github/workflows/ruff.yml | 8 +++++ api/app.py | 2 +- api/olds/container.py | 1 - playground/swarms_example.py | 1 - swarms/__init__.py | 3 -- swarms/agents/__init__.py | 3 -- swarms/agents/agent.py | 7 +--- swarms/agents/models/__init__.py | 1 - swarms/agents/models/petals_hf.py | 2 -- swarms/agents/tools/__init__.py | 1 - swarms/agents/tools/agent_tools.py | 36 ++++--------------- swarms/agents/tools/base.py | 2 +- .../tools/core/code_interpreter/main.py | 7 ++-- swarms/agents/tools/main.py | 25 +++---------- swarms/agents/utils/Agent.py | 11 +----- swarms/agents/utils/Calback.py | 6 ++-- swarms/agents/utils/agent_creator.py | 4 +-- swarms/orchestrate.py | 2 -- swarms/swarms.py | 3 +- swarms/utils/embeddings/__init__.py | 1 - swarms/workers/__init__.py | 2 -- swarms/workers/generative_worker.py | 3 +- .../workers/models/GroundingDINO/__init__.py | 1 - .../GroundingDINO/demo/create_coco_dataset.py | 2 -- .../models/GroundingDINO/demo/gradio_app.py | 7 +--- .../demo/inference_on_a_image.py | 2 -- .../GroundingDINO/demo/test_ap_on_coco.py | 5 +-- .../models/GroundingDINO/__init__.py | 1 - .../models/GroundingDINO/backbone/__init__.py | 1 - .../models/GroundingDINO/backbone/backbone.py | 2 +- .../models/GroundingDINO/bertwarper.py | 6 +--- .../models/GroundingDINO/groundingdino.py | 18 +++------- .../models/GroundingDINO/transformer.py | 1 - .../GroundingDINO/transformer_vanilla.py | 5 --- .../groundingdino/models/__init__.py | 1 - .../groundingdino/util/get_tokenlizer.py | 2 +- .../GroundingDINO/groundingdino/util/utils.py | 3 +- .../groundingdino/util/visualizer.py | 3 +- swarms/workers/models/__init__.py | 22 ------------ .../models/segment_anything/__init__.py | 1 - .../segment_anything/__init__.py | 9 ----- .../segment_anything/modeling/__init__.py | 5 --- .../workers/multi_modal_workers/__init__.py | 1 - .../multi_modal_workers/multi_modal_agent.py | 23 ++---------- .../omni_agent/model_server.py | 14 +++----- .../omni_agent/omni_chat.py | 8 ++--- swarms/workers/worker_agent_ultra.py | 13 ++----- swarms/workers/worker_node.py | 10 +----- tests/agents/memory/main.py | 2 +- tests/agents/models/LLM.py | 4 +-- tests/agents/models/hf.py | 7 ++-- tests/agents/workers/omni_worker.py | 1 - tests/agents/workers/worker_agent_ultra.py | 6 ++-- tests/agents/workers/worker_node.py | 1 - tests/agents/workers/worker_ultra.py | 2 +- tests/boss/boss_node.py | 1 - tests/swarms.py | 4 +-- 57 files changed, 70 insertions(+), 255 deletions(-) create mode 100644 .github/workflows/ruff.yml diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 00000000..757cae68 --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,8 @@ +name: Ruff +on: [ push, pull_request ] +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: chartboost/ruff-action@v1 diff --git a/api/app.py b/api/app.py index addbb161..b4b7bc14 100644 --- a/api/app.py +++ b/api/app.py @@ -42,6 +42,6 @@ async def run(swarm_input: SwarmInput): except ValueError as ve: logging.error("A ValueError occurred", exc_info=True) raise HTTPException(status_code=400, detail=str(ve)) - except Exception as e: + except Exception: logging.error("An error occurred", exc_info=True) raise HTTPException(status_code=500, detail="An unexpected error occurred") diff --git a/api/olds/container.py b/api/olds/container.py index 4d037484..2ea88f33 100644 --- a/api/olds/container.py +++ b/api/olds/container.py @@ -1,5 +1,4 @@ import os -import re from pathlib import Path from typing import Dict, List diff --git a/playground/swarms_example.py b/playground/swarms_example.py index e074cecc..e2a1fa4e 100644 --- a/playground/swarms_example.py +++ b/playground/swarms_example.py @@ -1,5 +1,4 @@ from swarms import HierarchicalSwarm -import os # Retrieve your API key from the environment or replace with your actual key api_key = "" diff --git a/swarms/__init__.py b/swarms/__init__.py index 6217e211..3a381a0b 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -1,5 +1,2 @@ # from swarms import Swarms, swarm -from swarms.swarms import HierarchicalSwarm, swarm # from swarms.workers.worker_ultra_node import WorkerUltraNode, WorkerUltra -from swarms.workers.worker_node import WorkerNode, worker_node -from swarms.boss.boss_node import BossNode \ No newline at end of file diff --git a/swarms/agents/__init__.py b/swarms/agents/__init__.py index 16f5485c..6ee43d6d 100644 --- a/swarms/agents/__init__.py +++ b/swarms/agents/__init__.py @@ -2,11 +2,8 @@ #models -from swarms.agents.models.llm import LLM -from swarms.agents.models.hf import HuggingFaceLLM #tools -from swarms.agents.tools.main import process_csv, MaskFormer, ImageEditing, InstructPix2Pix, Text2Image, VisualQuestionAnswering, ImageCaptioning, browse_web_page, WebpageQATool, web_search diff --git a/swarms/agents/agent.py b/swarms/agents/agent.py index 5ceb24dd..91ab0e25 100644 --- a/swarms/agents/agent.py +++ b/swarms/agents/agent.py @@ -4,15 +4,10 @@ from swarms.utils.logger import logger from langchain.tools import BaseTool -from langchain.callbacks.manager import ( - AsyncCallbackManagerForToolRun, - CallbackManagerForToolRun, -) -from typing import List, Any, Dict, Optional, Type +from typing import List, Any, Optional from langchain.memory.chat_message_histories import FileChatMessageHistory import logging -from pydantic import BaseModel, Extra from swarms.agents.models.hf import HuggingFaceLLM logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') diff --git a/swarms/agents/models/__init__.py b/swarms/agents/models/__init__.py index d8e59621..e69de29b 100644 --- a/swarms/agents/models/__init__.py +++ b/swarms/agents/models/__init__.py @@ -1 +0,0 @@ -from swarms.agents.models.llm import LLM \ No newline at end of file diff --git a/swarms/agents/models/petals_hf.py b/swarms/agents/models/petals_hf.py index 737df847..c62ac413 100644 --- a/swarms/agents/models/petals_hf.py +++ b/swarms/agents/models/petals_hf.py @@ -1,5 +1,3 @@ -from transformers import AutoTokenizer -from petals import AutoDistributedForCasualLM class PetalsHFLLM: def __init__(self, model_name: str = None, prompt: str = None, device: str = None, use_fast = False, add_bos_token: str = None, cuda=False): diff --git a/swarms/agents/tools/__init__.py b/swarms/agents/tools/__init__.py index 05bbf557..fde972e5 100644 --- a/swarms/agents/tools/__init__.py +++ b/swarms/agents/tools/__init__.py @@ -1,3 +1,2 @@ # from swarms.agents.workers import multimodal_agent_tool -from swarms.agents.tools.main import process_csv, ReadFileTool, WriteFileTool, BaseTool, DuckDuckGoSearchRun # Terminal, CodeWriter, CodeEditor \ No newline at end of file diff --git a/swarms/agents/tools/agent_tools.py b/swarms/agents/tools/agent_tools.py index 69ed7ec8..baed1f79 100644 --- a/swarms/agents/tools/agent_tools.py +++ b/swarms/agents/tools/agent_tools.py @@ -1,36 +1,12 @@ # ---------- Dependencies ---------- -import os -import asyncio -import faiss -from typing import Any, Optional, List -from contextlib import contextmanager - -from pydantic import BaseModel, Field -from langchain import LLMChain, OpenAI, PromptTemplate -from langchain.chains.base import Chain - -from langchain.experimental import BabyAGI -from langchain.embeddings import OpenAIEmbeddings -from langchain.vectorstores.base import VectorStore -from langchain.vectorstores import FAISS - -from langchain.docstore import InMemoryDocstore -from langchain.chains.qa_with_sources.loading import load_qa_with_sources_chain -from langchain.agents import ZeroShotAgent, Tool, AgentExecutor - -from langchain.text_splitter import RecursiveCharacterTextSplitter -from langchain.tools import BaseTool, DuckDuckGoSearchRun -from langchain.tools.file_management.read import ReadFileTool - -from langchain.tools.file_management.write import WriteFileTool -from langchain.tools.human.tool import HumanInputRun -from swarms.agents.tools.main import process_csv, WebpageQATool - -from langchain.experimental.autonomous_agents.autogpt.agent import AutoGPT -from langchain.chat_models import ChatOpenAI -from langchain.tools import tool + + + + + + # ---------- Constants ---------- ROOT_DIR = "./data/" diff --git a/swarms/agents/tools/base.py b/swarms/agents/tools/base.py index ab29f6f5..676c5a84 100644 --- a/swarms/agents/tools/base.py +++ b/swarms/agents/tools/base.py @@ -1,7 +1,7 @@ from __future__ import annotations from abc import ABC, abstractmethod -from typing import Any, Awaitable, Callable, Dict, List, Optional, Type, Union +from typing import Any, Callable, Optional, Type, Union from pydantic import BaseModel class ToolException(Exception): diff --git a/swarms/agents/tools/core/code_interpreter/main.py b/swarms/agents/tools/core/code_interpreter/main.py index 4cf612cd..6fc0fd09 100644 --- a/swarms/agents/tools/core/code_interpreter/main.py +++ b/swarms/agents/tools/core/code_interpreter/main.py @@ -4,9 +4,8 @@ import json import re import uuid from dataclasses import dataclass -from dotenv import load_dotenv from io import BytesIO -from typing import Any, List, Optional, Sequence, Tuple, Union, TYPE_CHECKING +from typing import Any, List, Optional, Sequence, Tuple, Union from pydantic import BaseModel, BaseSettings, root_validator @@ -727,9 +726,9 @@ class CodeInterpreterSession: for file in self.output_files: if str(file.name) in final_response: # rm ![Any](file.name) from the response - final_response = re.sub(rf"\n\n!\[.*\]\(.*\)", "", final_response) + final_response = re.sub(r"\n\n!\[.*\]\(.*\)", "", final_response) - if self.output_files and re.search(rf"\n\[.*\]\(.*\)", final_response): + if self.output_files and re.search(r"\n\[.*\]\(.*\)", final_response): final_response = await remove_download_link(final_response, self.llm) return CodeInterpreterResponse(content=final_response, files=self.output_files) diff --git a/swarms/agents/tools/main.py b/swarms/agents/tools/main.py index 8397605d..c328ea82 100644 --- a/swarms/agents/tools/main.py +++ b/swarms/agents/tools/main.py @@ -10,7 +10,6 @@ from langchain.agents import load_tools from langchain.agents.tools import BaseTool from langchain.llms.base import BaseLLM -from langchain.chat_models import ChatOpenAI import requests @@ -58,9 +57,8 @@ class ToolWrapper: ) -> BaseTool: func = self.func if self.is_per_session(): - func = lambda *args, **kwargs: self.func( - *args, **kwargs, get_session=get_session - ) + def func(*args, **kwargs): + return self.func(*args, **kwargs, get_session=get_session) return Tool( name=self.name, @@ -170,7 +168,7 @@ class ExitConversation(BaseToolSet): _, executor = get_session() del executor - logger.debug(f"\nProcessed ExitConversation.") + logger.debug("\nProcessed ExitConversation.") return message @@ -422,8 +420,6 @@ class ToolsFactory: import os import subprocess -import time -from datetime import datetime from typing import Dict, List from swarms.utils.main import ANSI, Color, Style # test @@ -940,7 +936,7 @@ class CodeEditor(BaseToolSet): @tool( name="CodeEditor.READ", description="Read and understand code. " - f"Input should be filename and line number group. ex. test.py|1-10 " + "Input should be filename and line number group. ex. test.py|1-10 " "and the output will be code. ", ) def read(self, inputs: str) -> str: @@ -1470,14 +1466,11 @@ import pandas as pd from langchain.agents.agent_toolkits.pandas.base import create_pandas_dataframe_agent from langchain.docstore.document import Document import asyncio -import nest_asyncio # Tools from contextlib import contextmanager from typing import Optional from langchain.agents import tool -from langchain.tools.file_management.read import ReadFileTool -from langchain.tools.file_management.write import WriteFileTool ROOT_DIR = "./data/" @@ -1485,7 +1478,7 @@ from langchain.tools import BaseTool, DuckDuckGoSearchRun from langchain.text_splitter import RecursiveCharacterTextSplitter from pydantic import Field -from langchain.chains.qa_with_sources.loading import load_qa_with_sources_chain, BaseCombineDocumentsChain +from langchain.chains.qa_with_sources.loading import BaseCombineDocumentsChain @@ -1787,14 +1780,6 @@ web_search = DuckDuckGoSearchRun() ######################## ######################################################## file system -from langchain.tools.file_management import ( - ReadFileTool, - CopyFileTool, - DeleteFileTool, - MoveFileTool, - WriteFileTool, - ListDirectoryTool, -) from langchain.agents.agent_toolkits import FileManagementToolkit from tempfile import TemporaryDirectory diff --git a/swarms/agents/utils/Agent.py b/swarms/agents/utils/Agent.py index f11f0520..6bb035b9 100644 --- a/swarms/agents/utils/Agent.py +++ b/swarms/agents/utils/Agent.py @@ -1,30 +1,23 @@ """Chain that takes in an input and produces an action and action input.""" from __future__ import annotations -import asyncio import json import logging -import time from abc import abstractmethod from pathlib import Path -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +from typing import Any, Dict, List, Optional, Sequence, Tuple, Union import yaml from pydantic import BaseModel, root_validator from langchain.agents.agent_types import AgentType -from langchain.agents.tools import InvalidTool from langchain.callbacks.base import BaseCallbackManager from langchain.callbacks.manager import ( - AsyncCallbackManagerForChainRun, AsyncCallbackManagerForToolRun, - CallbackManagerForChainRun, CallbackManagerForToolRun, Callbacks, ) -from langchain.chains.base import Chain from langchain.chains.llm import LLMChain -from langchain.input import get_color_mapping from langchain.prompts.few_shot import FewShotPromptTemplate from langchain.prompts.prompt import PromptTemplate from langchain.schema import ( @@ -32,12 +25,10 @@ from langchain.schema import ( AgentFinish, BaseOutputParser, BasePromptTemplate, - OutputParserException, ) from langchain.schema.language_model import BaseLanguageModel from langchain.schema.messages import BaseMessage from langchain.tools.base import BaseTool -from langchain.utilities.asyncio import asyncio_timeout logger = logging.getLogger(__name__) diff --git a/swarms/agents/utils/Calback.py b/swarms/agents/utils/Calback.py index 771f370f..174ac5a9 100644 --- a/swarms/agents/utils/Calback.py +++ b/swarms/agents/utils/Calback.py @@ -51,17 +51,17 @@ class EVALCallbackHandler(BaseCallbackHandler): def on_chain_start( self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any ) -> None: - logger.info(ANSI(f"Entering new chain.").to(Color.green(), Style.italic())) + logger.info(ANSI("Entering new chain.").to(Color.green(), Style.italic())) logger.info(ANSI("Prompted Text").to(Color.yellow()) + f': {inputs["input"]}\n') def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - logger.info(ANSI(f"Finished chain.").to(Color.green(), Style.italic())) + logger.info(ANSI("Finished chain.").to(Color.green(), Style.italic())) def on_chain_error( self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any ) -> None: logger.error( - ANSI(f"Chain Error").to(Color.red()) + ": " + dim_multiline(str(error)) + ANSI("Chain Error").to(Color.red()) + ": " + dim_multiline(str(error)) ) def on_tool_start( diff --git a/swarms/agents/utils/agent_creator.py b/swarms/agents/utils/agent_creator.py index 97aa30ef..cc0ad0c2 100644 --- a/swarms/agents/utils/agent_creator.py +++ b/swarms/agents/utils/agent_creator.py @@ -1,4 +1,3 @@ -import os import logging from typing import Dict, Optional from celery import Task @@ -7,7 +6,6 @@ from langchain.callbacks.manager import CallbackManager from langchain.chains.conversation.memory import ConversationBufferMemory from langchain.memory.chat_memory import BaseChatMemory from swarms.agents.tools.main import BaseToolSet, ToolsFactory -from swarms.agents.prompts.prompts import EVAL_PREFIX, EVAL_SUFFIX from swarms.agents.utils.agent_setup import AgentSetup # from .callback import EVALCallbackHandler, ExecutionTracingCallbackHandler @@ -31,7 +29,7 @@ class AgentCreator: raise TypeError("Session must be a string") if not session: raise ValueError("Session is empty") - if not (session in self.memories): + if session not in self.memories: self.memories[session] = self.create_memory() return self.memories[session] diff --git a/swarms/orchestrate.py b/swarms/orchestrate.py index 8ba0ecdc..ac5da889 100644 --- a/swarms/orchestrate.py +++ b/swarms/orchestrate.py @@ -45,10 +45,8 @@ Orchestrate(WorkerNode, autoscale=True, nodes=int, swarm_type="flat") """ #in a shared state, provide 3 communication times, during task assignment, task compeltion, and feedback or inability to complete a task. from abc import ABC, abstractmethod -import celery from typing import List, Dict, Any -import numpy as np import threading from swarms.agents.memory.ocean import OceanDB diff --git a/swarms/swarms.py b/swarms/swarms.py index 8081713f..ed23bb50 100644 --- a/swarms/swarms.py +++ b/swarms/swarms.py @@ -2,10 +2,9 @@ import logging import asyncio from swarms.agents.tools.agent_tools import * -from swarms.workers.worker_node import WorkerNodeInitializer, worker_node +from swarms.workers.worker_node import WorkerNodeInitializer from swarms.boss.boss_node import BossNodeInitializer as BossNode -from swarms.utils.task import Task from swarms.agents.models.hf import HuggingFaceLLM # from langchain import LLMMathChain diff --git a/swarms/utils/embeddings/__init__.py b/swarms/utils/embeddings/__init__.py index dd08cd94..e69de29b 100644 --- a/swarms/utils/embeddings/__init__.py +++ b/swarms/utils/embeddings/__init__.py @@ -1 +0,0 @@ -from swarms.utils.embeddings.base import Embeddings \ No newline at end of file diff --git a/swarms/workers/__init__.py b/swarms/workers/__init__.py index da7b21b8..e69de29b 100644 --- a/swarms/workers/__init__.py +++ b/swarms/workers/__init__.py @@ -1,2 +0,0 @@ -from .worker_node import worker_node -from .worker_ultra_node import WorkerUltraNode diff --git a/swarms/workers/generative_worker.py b/swarms/workers/generative_worker.py index 45f4d7ad..917b424b 100644 --- a/swarms/workers/generative_worker.py +++ b/swarms/workers/generative_worker.py @@ -1,7 +1,7 @@ import logging import re from datetime import datetime -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Dict, List, Optional ############ from langchain.prompts import PromptTemplate @@ -19,7 +19,6 @@ logger = logging.getLogger(__name__) ####################### -from pydantic import BaseModel, Field class WorkerSims(BaseMemory): llm: BaseLanguageModel diff --git a/swarms/workers/models/GroundingDINO/__init__.py b/swarms/workers/models/GroundingDINO/__init__.py index f6c7cefb..e69de29b 100644 --- a/swarms/workers/models/GroundingDINO/__init__.py +++ b/swarms/workers/models/GroundingDINO/__init__.py @@ -1 +0,0 @@ -from GroundingDINO import groundingdino \ No newline at end of file diff --git a/swarms/workers/models/GroundingDINO/demo/create_coco_dataset.py b/swarms/workers/models/GroundingDINO/demo/create_coco_dataset.py index a0bb02a7..7e657584 100644 --- a/swarms/workers/models/GroundingDINO/demo/create_coco_dataset.py +++ b/swarms/workers/models/GroundingDINO/demo/create_coco_dataset.py @@ -2,7 +2,6 @@ import typer from groundingdino.util.inference import load_model, load_image, predict from tqdm import tqdm import torchvision -import torch import fiftyone as fo @@ -23,7 +22,6 @@ def main( dataset = fo.Dataset.from_images_dir(image_directory) - samples = [] if subsample is not None: diff --git a/swarms/workers/models/GroundingDINO/demo/gradio_app.py b/swarms/workers/models/GroundingDINO/demo/gradio_app.py index c1f5463a..8546fbf2 100644 --- a/swarms/workers/models/GroundingDINO/demo/gradio_app.py +++ b/swarms/workers/models/GroundingDINO/demo/gradio_app.py @@ -1,12 +1,8 @@ import argparse -from functools import partial import cv2 -import requests import os -from io import BytesIO from PIL import Image import numpy as np -from pathlib import Path import warnings @@ -26,7 +22,7 @@ import gradio as gr from groundingdino.models import build_model from groundingdino.util.slconfig import SLConfig from groundingdino.util.utils import clean_state_dict -from groundingdino.util.inference import annotate, load_image, predict +from groundingdino.util.inference import annotate, predict import groundingdino.datasets.transforms as T from huggingface_hub import hf_hub_download @@ -71,7 +67,6 @@ model = load_model_hf(config_file, ckpt_repo_id, ckpt_filenmae) def run_grounding(input_image, grounding_caption, box_threshold, text_threshold): init_image = input_image.convert("RGB") - original_size = init_image.size _, image_tensor = image_transform_grounding(init_image) image_pil: Image = image_transform_grounding_for_vis(init_image) diff --git a/swarms/workers/models/GroundingDINO/demo/inference_on_a_image.py b/swarms/workers/models/GroundingDINO/demo/inference_on_a_image.py index 0dd332f3..5083d511 100644 --- a/swarms/workers/models/GroundingDINO/demo/inference_on_a_image.py +++ b/swarms/workers/models/GroundingDINO/demo/inference_on_a_image.py @@ -1,6 +1,5 @@ import argparse import os -import sys import numpy as np import torch @@ -8,7 +7,6 @@ from PIL import Image, ImageDraw, ImageFont import groundingdino.datasets.transforms as T from groundingdino.models import build_model -from groundingdino.util import box_ops from groundingdino.util.slconfig import SLConfig from groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap from groundingdino.util.vl_utils import create_positive_map_from_span diff --git a/swarms/workers/models/GroundingDINO/demo/test_ap_on_coco.py b/swarms/workers/models/GroundingDINO/demo/test_ap_on_coco.py index 59ce6a22..1268c76f 100644 --- a/swarms/workers/models/GroundingDINO/demo/test_ap_on_coco.py +++ b/swarms/workers/models/GroundingDINO/demo/test_ap_on_coco.py @@ -1,12 +1,9 @@ import argparse -import os -import sys import time -import numpy as np import torch import torch.nn as nn -from torch.utils.data import DataLoader, DistributedSampler +from torch.utils.data import DataLoader from groundingdino.models import build_model import groundingdino.datasets.transforms as T diff --git a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/__init__.py b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/__init__.py index 2af819d6..d1ff79f3 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/__init__.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/__init__.py @@ -12,4 +12,3 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. # ------------------------------------------------------------------------ -from .groundingdino import build_groundingdino diff --git a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/backbone/__init__.py b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/backbone/__init__.py index 76e4b272..e69de29b 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/backbone/__init__.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/backbone/__init__.py @@ -1 +0,0 @@ -from .backbone import build_backbone diff --git a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/backbone/backbone.py b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/backbone/backbone.py index c8340c72..6940f1b4 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/backbone/backbone.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/backbone/backbone.py @@ -24,7 +24,7 @@ import torchvision from torch import nn from torchvision.models._utils import IntermediateLayerGetter -from groundingdino.util.misc import NestedTensor, clean_state_dict, is_main_process +from groundingdino.util.misc import NestedTensor, is_main_process from .position_encoding import build_position_encoding from .swin_transformer import build_swin_transformer diff --git a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/bertwarper.py b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/bertwarper.py index f0cf9779..e209a394 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/bertwarper.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/bertwarper.py @@ -6,11 +6,7 @@ # ------------------------------------------------------------------------ import torch -import torch.nn.functional as F -import torch.utils.checkpoint as checkpoint -from torch import Tensor, nn -from torchvision.ops.boxes import nms -from transformers import BertConfig, BertModel, BertPreTrainedModel +from torch import nn from transformers.modeling_outputs import BaseModelOutputWithPoolingAndCrossAttentions diff --git a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py index a5758fd0..2fe41f37 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py @@ -20,32 +20,22 @@ from typing import List import torch import torch.nn.functional as F from torch import nn -from torchvision.ops.boxes import nms -from transformers import AutoTokenizer, BertModel, BertTokenizer, RobertaModel, RobertaTokenizerFast -from groundingdino.util import box_ops, get_tokenlizer +from groundingdino.util import get_tokenlizer from groundingdino.util.misc import ( NestedTensor, - accuracy, - get_world_size, - interpolate, inverse_sigmoid, - is_dist_avail_and_initialized, nested_tensor_from_tensor_list, ) -from groundingdino.util.utils import get_phrases_from_posmap -from groundingdino.util.visualizer import COCOVisualizer -from groundingdino.util.vl_utils import create_positive_map_from_span from ..registry import MODULE_BUILD_FUNCS from .backbone import build_backbone from .bertwarper import ( BertModelWarper, - generate_masks_with_special_tokens, generate_masks_with_special_tokens_and_transfer_map, ) from .transformer import build_transformer -from .utils import MLP, ContrastiveEmbed, sigmoid_focal_loss +from .utils import MLP, ContrastiveEmbed class GroundingDINO(nn.Module): @@ -152,7 +142,7 @@ class GroundingDINO(nn.Module): self.backbone = backbone self.aux_loss = aux_loss - self.box_pred_damping = box_pred_damping = None + self.box_pred_damping = None self.iter_update = iter_update assert iter_update, "Why not iter_update?" @@ -308,7 +298,7 @@ class GroundingDINO(nn.Module): masks.append(mask) poss.append(pos_l) - input_query_bbox = input_query_label = attn_mask = dn_meta = None + input_query_bbox = input_query_label = attn_mask = None hs, reference, hs_enc, ref_enc, init_box_proposal = self.transformer( srcs, masks, input_query_bbox, poss, input_query_label, attn_mask, text_dict ) diff --git a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py index fcb8742d..ffc6a09c 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/transformer.py @@ -250,7 +250,6 @@ class Transformer(nn.Module): valid_ratios = torch.stack([self.get_valid_ratio(m) for m in masks], 1) # two stage - enc_topk_proposals = enc_refpoint_embed = None ######################################################### # Begin Encoder diff --git a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/transformer_vanilla.py b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/transformer_vanilla.py index 10c0920c..85f6822a 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/transformer_vanilla.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/models/GroundingDINO/transformer_vanilla.py @@ -17,16 +17,11 @@ Copy-paste from torch.nn.Transformer with modifications: from typing import Optional import torch -import torch.nn.functional as F from torch import Tensor, nn from .utils import ( - MLP, _get_activation_fn, _get_clones, - gen_encoder_output_proposals, - gen_sineembed_for_position, - sigmoid_focal_loss, ) diff --git a/swarms/workers/models/GroundingDINO/groundingdino/models/__init__.py b/swarms/workers/models/GroundingDINO/groundingdino/models/__init__.py index e3413961..4400f8dc 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/models/__init__.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/models/__init__.py @@ -5,7 +5,6 @@ # Licensed under the Apache License, Version 2.0 [see LICENSE for details] # ------------------------------------------------------------------------ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved -from .GroundingDINO import build_groundingdino def build_model(args): diff --git a/swarms/workers/models/GroundingDINO/groundingdino/util/get_tokenlizer.py b/swarms/workers/models/GroundingDINO/groundingdino/util/get_tokenlizer.py index dd2d972b..24675df9 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/util/get_tokenlizer.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/util/get_tokenlizer.py @@ -1,4 +1,4 @@ -from transformers import AutoTokenizer, BertModel, BertTokenizer, RobertaModel, RobertaTokenizerFast +from transformers import AutoTokenizer, BertModel, RobertaModel import os def get_tokenlizer(text_encoder_type): diff --git a/swarms/workers/models/GroundingDINO/groundingdino/util/utils.py b/swarms/workers/models/GroundingDINO/groundingdino/util/utils.py index 8cf83ae0..a0491db1 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/util/utils.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/util/utils.py @@ -268,7 +268,8 @@ def get_embedder(multires, i=0): } embedder_obj = Embedder(**embed_kwargs) - embed = lambda x, eo=embedder_obj: eo.embed(x) + def embed(x, eo=embedder_obj): + return eo.embed(x) return embed, embedder_obj.out_dim diff --git a/swarms/workers/models/GroundingDINO/groundingdino/util/visualizer.py b/swarms/workers/models/GroundingDINO/groundingdino/util/visualizer.py index 7a1b7b10..084e9988 100644 --- a/swarms/workers/models/GroundingDINO/groundingdino/util/visualizer.py +++ b/swarms/workers/models/GroundingDINO/groundingdino/util/visualizer.py @@ -9,7 +9,6 @@ import datetime import os -import cv2 import matplotlib.pyplot as plt import numpy as np import torch @@ -134,7 +133,7 @@ class COCOVisualizer: def addtgt(self, tgt): """ """ - if tgt is None or not "boxes" in tgt: + if tgt is None or "boxes" not in tgt: ax = plt.gca() if "caption" in tgt: diff --git a/swarms/workers/models/__init__.py b/swarms/workers/models/__init__.py index 715fde68..2346a006 100644 --- a/swarms/workers/models/__init__.py +++ b/swarms/workers/models/__init__.py @@ -3,27 +3,5 @@ # from .GroundingDINO.groundingdino.util import box_ops, SLConfig # from .GroundingDINO.groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap # from .segment_anything.segment_anything import build_sam, SamPredictor, SamAutomaticMaskGenerator -from swarms.workers.models.GroundingDINO.groundingdino.datasets.transforms import ( - Compose, - Normalize, - ToTensor, - crop, - hflip, - resize, - pad, - ResizeDebug, - RandomCrop, - RandomSizeCrop, - CenterCrop, - RandomHorizontalFlip, - RandomResize, - RandomPad, - RandomSelect -) -from swarms.workers.models.GroundingDINO.groundingdino.models import build_model -from swarms.workers.models.GroundingDINO.groundingdino.util import box_ops -from swarms.workers.models.GroundingDINO.groundingdino.util.slconfig import SLConfig -from swarms.workers.models.GroundingDINO.groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap -from swarms.workers.models.segment_anything import build_sam, SamPredictor, SamAutomaticMaskGenerator \ No newline at end of file diff --git a/swarms/workers/models/segment_anything/__init__.py b/swarms/workers/models/segment_anything/__init__.py index cbb9a960..e69de29b 100644 --- a/swarms/workers/models/segment_anything/__init__.py +++ b/swarms/workers/models/segment_anything/__init__.py @@ -1 +0,0 @@ -from segment_anything import segment_anything \ No newline at end of file diff --git a/swarms/workers/models/segment_anything/segment_anything/__init__.py b/swarms/workers/models/segment_anything/segment_anything/__init__.py index 34383d83..4a49a3a9 100644 --- a/swarms/workers/models/segment_anything/segment_anything/__init__.py +++ b/swarms/workers/models/segment_anything/segment_anything/__init__.py @@ -4,12 +4,3 @@ # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. -from .build_sam import ( - build_sam, - build_sam_vit_h, - build_sam_vit_l, - build_sam_vit_b, - sam_model_registry, -) -from .predictor import SamPredictor -from .automatic_mask_generator import SamAutomaticMaskGenerator diff --git a/swarms/workers/models/segment_anything/segment_anything/modeling/__init__.py b/swarms/workers/models/segment_anything/segment_anything/modeling/__init__.py index 38e90624..4a49a3a9 100644 --- a/swarms/workers/models/segment_anything/segment_anything/modeling/__init__.py +++ b/swarms/workers/models/segment_anything/segment_anything/modeling/__init__.py @@ -4,8 +4,3 @@ # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. -from .sam import Sam -from .image_encoder import ImageEncoderViT -from .mask_decoder import MaskDecoder -from .prompt_encoder import PromptEncoder -from .transformer import TwoWayTransformer diff --git a/swarms/workers/multi_modal_workers/__init__.py b/swarms/workers/multi_modal_workers/__init__.py index 81c50366..e69de29b 100644 --- a/swarms/workers/multi_modal_workers/__init__.py +++ b/swarms/workers/multi_modal_workers/__init__.py @@ -1 +0,0 @@ -from swarms.workers.multi_modal_workers.omni_agent.omni_chat import chat_huggingface \ No newline at end of file diff --git a/swarms/workers/multi_modal_workers/multi_modal_agent.py b/swarms/workers/multi_modal_workers/multi_modal_agent.py index 8b863b74..7fbdc345 100644 --- a/swarms/workers/multi_modal_workers/multi_modal_agent.py +++ b/swarms/workers/multi_modal_workers/multi_modal_agent.py @@ -11,10 +11,7 @@ import math import numpy as np import argparse import inspect -import tempfile -from transformers import CLIPSegProcessor, CLIPSegForImageSegmentation from transformers import pipeline, BlipProcessor, BlipForConditionalGeneration, BlipForQuestionAnswering -from transformers import AutoImageProcessor, UperNetForSemanticSegmentation from diffusers import StableDiffusionPipeline, StableDiffusionInpaintPipeline, StableDiffusionInstructPix2PixPipeline from diffusers import EulerAncestralDiscreteScheduler @@ -34,22 +31,10 @@ from swarms.workers.models import ( Compose, Normalize, ToTensor, - crop, - hflip, - resize, - pad, - ResizeDebug, - RandomCrop, - RandomSizeCrop, - CenterCrop, - RandomHorizontalFlip, - RandomResize, - RandomPad, - RandomSelect + RandomResize ) from swarms.workers.models import build_model -from swarms.workers.models import box_ops from swarms.workers.models import SLConfig from swarms.workers.models import clean_state_dict, get_phrases_from_posmap @@ -1019,8 +1004,6 @@ class Segmenting: sorted_anns = sorted(masks, key=(lambda x: x['area']), reverse=True) ax = plt.gca() ax.set_autoscale_on(False) - polygons = [] - color = [] for ann in sorted_anns: m = ann['segmentation'] img = np.ones((m.shape[0], m.shape[1], 3)) @@ -1363,7 +1346,7 @@ class ObjectSegmenting: image = self.sam.show_mask(mask[0].cpu().numpy(), image, random_color=True, transparency=0.3) - merged_mask_image = Image.fromarray(merged_mask) + Image.fromarray(merged_mask) return merged_mask @@ -1371,7 +1354,7 @@ class ObjectSegmenting: class ImageEditing: template_model = True def __init__(self, Text2Box:Text2Box, Segmenting:Segmenting, Inpainting:Inpainting): - print(f"Initializing ImageEditing") + print("Initializing ImageEditing") self.sam = Segmenting self.grounding = Text2Box self.inpaint = Inpainting diff --git a/swarms/workers/multi_modal_workers/omni_agent/model_server.py b/swarms/workers/multi_modal_workers/omni_agent/model_server.py index 35d9dd4d..11aaa811 100644 --- a/swarms/workers/multi_modal_workers/omni_agent/model_server.py +++ b/swarms/workers/multi_modal_workers/omni_agent/model_server.py @@ -8,24 +8,18 @@ from diffusers import DiffusionPipeline, StableDiffusionControlNetPipeline, Cont from diffusers.utils import load_image from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler from diffusers.utils import export_to_video -from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5ForSpeechToSpeech -from transformers import BlipProcessor, BlipForConditionalGeneration -from transformers import TrOCRProcessor, VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer +from transformers import SpeechT5Processor, SpeechT5HifiGan, SpeechT5ForSpeechToSpeech +from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer from datasets import load_dataset from PIL import Image # import flask # from flask import request, jsonify import waitress # from flask_cors import CORS -import io from torchvision import transforms import torch import torchaudio -from speechbrain.pretrained import WaveformEnhancement -import joblib -from huggingface_hub import hf_hub_url, cached_download -from transformers import AutoImageProcessor, TimesformerForVideoClassification -from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation, AutoFeatureExtractor +from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation from controlnet_aux import OpenposeDetector, MLSDdetector, HEDdetector, CannyDetector, MidasDetector from controlnet_aux.open_pose.body import Body from controlnet_aux.mlsd.models.mbv2_mlsd_large import MobileV2_MLSD_Large @@ -119,7 +113,7 @@ def load_pipes(local_deployment): "device": device }, "espnet/kan-bayashi_ljspeech_vits": { - "model": Text2Speech.from_pretrained(f"espnet/kan-bayashi_ljspeech_vits"), + "model": Text2Speech.from_pretrained("espnet/kan-bayashi_ljspeech_vits"), "device": device }, "lambdalabs/sd-image-variations-diffusers": { diff --git a/swarms/workers/multi_modal_workers/omni_agent/omni_chat.py b/swarms/workers/multi_modal_workers/omni_agent/omni_chat.py index 4395e8ea..f0371eec 100644 --- a/swarms/workers/multi_modal_workers/omni_agent/omni_chat.py +++ b/swarms/workers/multi_modal_workers/omni_agent/omni_chat.py @@ -20,11 +20,9 @@ import threading from queue import Queue # import flask # from flask import request, jsonify -import waitress # from flask_cors import CORS, cross_origin from swarms.workers.multi_modal_workers.omni_agent.get_token_ids import get_token_ids_for_task_parsing, get_token_ids_for_choose_model, count_tokens, get_max_context_length from huggingface_hub.inference_api import InferenceApi -from huggingface_hub.inference_api import ALL_TASKS parser = argparse.ArgumentParser() parser.add_argument("--config", type=str, default="swarms/agents/workers/multi_modal_workers/omni_agent/config.yml") @@ -253,7 +251,7 @@ def record_case(success, **args): def image_to_bytes(img_url): img_byte = io.BytesIO() - type = img_url.split(".")[-1] + img_url.split(".")[-1] load_image(img_url).save(img_byte, format="png") img_data = img_byte.getvalue() return img_data @@ -809,7 +807,7 @@ def run_task(input, command, results, api_key, api_type, api_endpoint): else: logger.warning(f"Task {command['task']} is not available. ControlNet need to be deployed locally.") record_case(success=False, **{"input": input, "task": command, "reason": f"Task {command['task']} is not available. ControlNet need to be deployed locally.", "op":"message"}) - inference_result = {"error": f"service related to ControlNet is not available."} + inference_result = {"error": "service related to ControlNet is not available."} results[id] = collect_result(command, "", inference_result) return False elif task in ["summarization", "translation", "conversational", "text-generation", "text2text-generation"]: # ChatGPT Can do @@ -872,7 +870,7 @@ def run_task(input, command, results, api_key, api_type, api_endpoint): reason = choose["reason"] best_model_id = choose["id"] hosted_on = "local" if best_model_id in all_avaliable_models["local"] else "huggingface" - except Exception as e: + except Exception: logger.warning(f"the response [ {choose_str} ] is not a valid JSON, try to find the model id and reason in the response.") choose_str = find_json(choose_str) best_model_id, reason, choose = get_id_reason(choose_str) diff --git a/swarms/workers/worker_agent_ultra.py b/swarms/workers/worker_agent_ultra.py index 7142dda2..26dede42 100644 --- a/swarms/workers/worker_agent_ultra.py +++ b/swarms/workers/worker_agent_ultra.py @@ -1,30 +1,23 @@ import os import logging -from typing import Optional, Type -from langchain.callbacks.manager import ( - AsyncCallbackManagerForToolRun, - CallbackManagerForToolRun, -) from swarms.agents.tools.agent_tools import * -from typing import List, Any, Dict, Optional +from typing import List, Dict from langchain.memory.chat_message_histories import FileChatMessageHistory import logging -from pydantic import BaseModel, Extra logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') -from typing import List, Any, Dict, Optional +from typing import List, Dict from langchain.memory.chat_message_histories import FileChatMessageHistory -from swarms.utils.main import BaseHandler, FileHandler, FileType +from swarms.utils.main import BaseHandler, FileType from swarms.agents.tools.main import ExitConversation, RequestsGet, CodeEditor, Terminal from swarms.utils.main import CsvToDataframe from swarms.agents.tools.main import BaseToolSet -from swarms.utils.main import StaticUploader class WorkerUltraNode: diff --git a/swarms/workers/worker_node.py b/swarms/workers/worker_node.py index a6db11c6..a61fc2a8 100644 --- a/swarms/workers/worker_node.py +++ b/swarms/workers/worker_node.py @@ -1,16 +1,8 @@ from swarms.agents.tools.agent_tools import * -from langchain.tools import BaseTool -from typing import Optional, Type - -from langchain.callbacks.manager import ( - AsyncCallbackManagerForToolRun, - CallbackManagerForToolRun, -) -from typing import List, Any, Dict, Optional + from langchain.memory.chat_message_histories import FileChatMessageHistory import logging -from pydantic import BaseModel, Extra logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') from swarms.agents.tools.main import Terminal diff --git a/tests/agents/memory/main.py b/tests/agents/memory/main.py index a6ea0706..f7ae0ec4 100644 --- a/tests/agents/memory/main.py +++ b/tests/agents/memory/main.py @@ -1,5 +1,5 @@ import pytest -from unittest.mock import Mock, MagicMock +from unittest.mock import Mock from swarms.agents.memory.oceandb import OceanDB diff --git a/tests/agents/models/LLM.py b/tests/agents/models/LLM.py index fbfce733..7e2d4ba5 100644 --- a/tests/agents/models/LLM.py +++ b/tests/agents/models/LLM.py @@ -1,7 +1,7 @@ import unittest import os -from unittest.mock import patch, MagicMock -from langchain import PromptTemplate, HuggingFaceHub, ChatOpenAI, LLMChain +from unittest.mock import patch +from langchain import HuggingFaceHub, ChatOpenAI from swarms.agents.models.llm import LLM diff --git a/tests/agents/models/hf.py b/tests/agents/models/hf.py index 292b94ba..c4422d44 100644 --- a/tests/agents/models/hf.py +++ b/tests/agents/models/hf.py @@ -1,8 +1,7 @@ import pytest import torch -from unittest.mock import Mock, MagicMock -from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig -from swarms.agents.models.hf import HuggingFaceLLM # replace with actual import +from unittest.mock import Mock +from swarms.agents.models.hf import HuggingFaceLLM @pytest.fixture @@ -50,7 +49,7 @@ def test_init_with_quantize(hugging_face_llm, mock_autotokenizer, mock_automodel } mock_bitsandbytesconfig.return_value = quantization_config - hugging_face_llm = HuggingFaceLLM(model_id='test', quantize=True) + HuggingFaceLLM(model_id='test', quantize=True) mock_bitsandbytesconfig.assert_called_once_with(**quantization_config) mock_autotokenizer.from_pretrained.assert_called_once_with('test') diff --git a/tests/agents/workers/omni_worker.py b/tests/agents/workers/omni_worker.py index 169272cd..7e735453 100644 --- a/tests/agents/workers/omni_worker.py +++ b/tests/agents/workers/omni_worker.py @@ -1,5 +1,4 @@ import pytest -from unittest.mock import Mock from swarms.worker.omni_worker import OmniWorkerAgent # replace 'yourmodule' with the actual module name @pytest.fixture diff --git a/tests/agents/workers/worker_agent_ultra.py b/tests/agents/workers/worker_agent_ultra.py index 16bd3f5b..9426604d 100644 --- a/tests/agents/workers/worker_agent_ultra.py +++ b/tests/agents/workers/worker_agent_ultra.py @@ -1,6 +1,6 @@ import pytest -from unittest.mock import Mock, MagicMock -from swarms.workers.worker_agent_ultra import WorkerUltraNode, WorkerUltraNodeInitializer # import your module here +from unittest.mock import Mock +from swarms.workers.worker_agent_ultra import WorkerUltraNode # import your module here def test_create_agent(): mock_llm = Mock() @@ -42,4 +42,4 @@ def test_worker_node(): def test_worker_node_no_key(): with pytest.raises(ValueError): - worker = worker_ultra_node(None) + worker_ultra_node(None) diff --git a/tests/agents/workers/worker_node.py b/tests/agents/workers/worker_node.py index 96340c6c..97e4c380 100644 --- a/tests/agents/workers/worker_node.py +++ b/tests/agents/workers/worker_node.py @@ -1,7 +1,6 @@ import pytest from swarms.agents.tools.agent_tools import * from unittest.mock import MagicMock, patch -from pydantic import ValidationError from swarms.worker.worker_node import WorkerNodeInitializer, WorkerNode # replace your_module with actual module name diff --git a/tests/agents/workers/worker_ultra.py b/tests/agents/workers/worker_ultra.py index b9fb523d..94aca5e3 100644 --- a/tests/agents/workers/worker_ultra.py +++ b/tests/agents/workers/worker_ultra.py @@ -58,6 +58,6 @@ def test_worker_ultra_node_initializer_initialize_vectorstore(worker_ultra_node_ assert vectorstore is not None def test_worker_ultra_node_initializer_create_worker_node(worker_ultra_node_initializer): - with patch.object(worker_ultra_node_initializer, 'initialize_llm') as mock_llm, patch.object(worker_ultra_node_initializer, 'initialize_toolsets') as mock_toolsets, patch.object(worker_ultra_node_initializer, 'initialize_vectorstore') as mock_vectorstore: + with patch.object(worker_ultra_node_initializer, 'initialize_llm'), patch.object(worker_ultra_node_initializer, 'initialize_toolsets'), patch.object(worker_ultra_node_initializer, 'initialize_vectorstore'): worker_node = worker_ultra_node_initializer.create_worker_node() assert worker_node is not None diff --git a/tests/boss/boss_node.py b/tests/boss/boss_node.py index 04c432d3..1982b810 100644 --- a/tests/boss/boss_node.py +++ b/tests/boss/boss_node.py @@ -1,6 +1,5 @@ import pytest from unittest.mock import Mock, patch -from pydantic import ValidationError from swarms.agents.tools.agent_tools import * from swarms.boss.boss_node import BossNodeInitializer, BossNode # For initializing BossNodeInitializer in multiple tests diff --git a/tests/swarms.py b/tests/swarms.py index 55a0e851..b740e732 100644 --- a/tests/swarms.py +++ b/tests/swarms.py @@ -1,6 +1,6 @@ import pytest import logging -from unittest.mock import Mock, patch +from unittest.mock import patch from swarms.swarms import HierarchicalSwarm # replace with your actual module name @pytest.fixture @@ -69,5 +69,5 @@ def test_initialize_tools_with_extra_tools(mock_llm, swarm): @patch('your_module.FAISS') def test_initialize_vectorstore(mock_faiss, mock_openai_embeddings, swarm): mock_openai_embeddings.return_value.embed_query = 'embed_query' - vectorstore = swarm.initialize_vectorstore() + swarm.initialize_vectorstore() mock_faiss.assert_called_once_with('embed_query', instance_of(faiss.IndexFlatL2), instance_of(InMemoryDocstore), {})