diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index d3f42fb1..8e3f75d3 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/pytestmac.yml b/.github/workflows/pytestmac.yml new file mode 100644 index 00000000..09392b7b --- /dev/null +++ b/.github/workflows/pytestmac.yml @@ -0,0 +1,35 @@ +name: Test on Macos-14 M1 + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: macos-14 + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.11.7 + uses: actions/setup-python@v5 + with: + python-version: 3.11.7 + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + + - name: Install dependencies + run: | + poetry install + + - name: Run tests + run: | + poetry run pytest \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index baaadfc8..6b175ce2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,9 +19,7 @@ jobs: - "3.9" - "3.10" - "3.11" - test_type: - - "core" - - "extended" + steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -29,48 +27,26 @@ jobs: with: python-version: ${{ matrix.python-version }} poetry-version: "1.4.2" - cache-key: ${{ matrix.test_type }} install-command: - if [ "${{ matrix.test_type }}" == "core" ]; then - echo "Running core tests, installing dependencies with poetry..." - poetry install - else - echo "Running extended tests, installing dependencies with poetry..." - poetry install -E extended_testing - fi - - name: Run ${{matrix.test_type}} tests - run: | - if [ "${{ matrix.test_type }}" == "core" ]; then - make test - else - make extended_tests - fi + echo "Running core tests, installing dependencies with poetry..." + poetry install + - name: Run core tests + run: pytest shell: bash - name: Python ${{ matrix.python-version }} ${{ matrix.test_type }} - steps: - - uses: actions/checkout@v4 + - name: Python ${{ matrix.python-version }} core + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: "./.github/actions/poetry_setup" + uses: "actions/setup-python@v2" with: python-version: ${{ matrix.python-version }} poetry-version: "1.4.2" - cache-key: ${{ matrix.test_type }} install-command: | - if [ "${{ matrix.test_type }}" == "core" ]; then - echo "Running core tests, installing dependencies with poetry..." - poetry install - else - echo "Running extended tests, installing dependencies with poetry..." - poetry install -E extended_testing - fi - - name: Run ${{matrix.test_type}} tests - run: | - if [ "${{ matrix.test_type }}" == "core" ]; then - make test - else - make extended_tests - fi + echo "Running core tests, installing dependencies with poetry..." + poetry install + - name: Run core tests + run: pytest shell: bash + build: runs-on: ubuntu-latest strategy: @@ -80,31 +56,17 @@ jobs: - "3.9" - "3.10" - "3.11" - test_type: - - "core" - - "extended" - name: Python ${{ matrix.python-version }} ${{ matrix.test_type }} + name: Python ${{ matrix.python-version }} core steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: "./.github/actions/poetry_setup" + uses: "actions/setup-python@v2" with: python-version: ${{ matrix.python-version }} poetry-version: "1.4.2" - cache-key: ${{ matrix.test_type }} install-command: | - if [ "${{ matrix.test_type }}" == "core" ]; then - echo "Running core tests, installing dependencies with poetry..." - poetry install - else - echo "Running extended tests, installing dependencies with poetry..." - poetry install -E extended_testing - fi - - name: Run ${{matrix.test_type}} tests - run: | - if [ "${{ matrix.test_type }}" == "core" ]; then - make test - else - make extended_tests - fi + echo "Running core tests, installing dependencies with poetry..." + poetry install + - name: Run core tests + run: pytest shell: bash \ No newline at end of file diff --git a/example.py b/example.py index 33c3bef1..05ff27e8 100644 --- a/example.py +++ b/example.py @@ -1,3 +1,4 @@ +""" Example of using the OpenAIChat model to generate a blog post. """ import os from dotenv import load_dotenv diff --git a/playground/agents/mm_agent_example.py b/playground/agents/mm_agent_example.py index 6cedcb29..10bacefb 100644 --- a/playground/agents/mm_agent_example.py +++ b/playground/agents/mm_agent_example.py @@ -1,8 +1,10 @@ -from swarms.agents import MultiModalAgent +""" Example of using the MultiModalAgent """ + +from swarms.agents import OmniModalAgent load_dict = {"ImageCaptioning": "cuda"} -node = MultiModalAgent(load_dict) +node = OmniModalAgent(load_dict) text = node.run_text( "What is your name? Generate a picture of yourself" diff --git a/pyproject.toml b/pyproject.toml index 5128ab33..a58febbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ [tool.poetry.dependencies] -python = "^3.6.1" +python = ">=3.9.1,<3.12" torch = "2.1.1" transformers = "4.37.1" openai = "0.28.0" @@ -33,6 +33,7 @@ einops = "0.7.0" google-generativeai = "0.3.1" langchain-experimental = "0.0.10" tensorflow = "*" +tensorflow-io = "*" weaviate-client = "3.25.3" opencv-python-headless = "4.8.1.78" faiss-cpu = "1.7.4" @@ -74,6 +75,7 @@ supervision = "*" scikit-image = "*" pinecone-client = "*" roboflow = "*" +python-dotenv = "*" diff --git a/requirements.txt b/requirements.txt index 00c92023..ce25dc57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,6 +18,7 @@ PyPDF2==3.0.1 accelerate==0.22.0 chromadb==0.4.14 tensorflow +tensorflow-io optimum toml tiktoken==0.4.0 @@ -51,4 +52,5 @@ supervision scikit-image anthropic pinecone-client -roboflow \ No newline at end of file +roboflow +python-dotenv \ No newline at end of file diff --git a/swarms/__init__.py b/swarms/__init__.py index 3a28d980..dd28a374 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -1,15 +1,16 @@ +""" init file for swarms package. """ # from swarms.telemetry.main import Telemetry # noqa: E402, F403 from swarms.telemetry.bootup import bootup # noqa: E402, F403 bootup() -from swarms.agents import * # noqa: E402, F403 -from swarms.structs import * # noqa: E402, F403 -from swarms.models import * # noqa: E402, F403 -from swarms.telemetry import * # noqa: E402, F403 -from swarms.utils import * # noqa: E402, F403 -from swarms.prompts import * # noqa: E402, F403 -from swarms.tokenizers import * # noqa: E402, F403 -from swarms.loaders import * # noqa: E402, F403 -from swarms.artifacts import * # noqa: E402, F403 -from swarms.chunkers import * # noqa: E402, F403 +from swarms.agents import * # noqa: E402, F403, C0413 +from swarms.structs import * # noqa: E402, F403, C0413 +from swarms.models import * # noqa: E402, F403, C0413 +from swarms.telemetry import * # noqa: E402, F403, C0413 +from swarms.utils import * # noqa: E402, F403, C0413 +from swarms.prompts import * # noqa: E402, F403, C0413 +from swarms.tokenizers import * # noqa: E402, F403, C0413 +from swarms.loaders import * # noqa: E402, F403, C0413 +from swarms.artifacts import * # noqa: E402, F403, C0413 +from swarms.chunkers import * # noqa: E402, F403, C0413 diff --git a/swarms/agents/__init__.py b/swarms/agents/__init__.py index 461baa16..5d17ce84 100644 --- a/swarms/agents/__init__.py +++ b/swarms/agents/__init__.py @@ -1,3 +1,4 @@ +""" init file for swarms/agents module. """ from swarms.agents.base import AbstractAgent from swarms.agents.omni_modal_agent import OmniModalAgent from swarms.agents.simple_agent import SimpleAgent diff --git a/swarms/agents/agent_wrapper.py b/swarms/agents/agent_wrapper.py index 738f599d..c3e60fa5 100644 --- a/swarms/agents/agent_wrapper.py +++ b/swarms/agents/agent_wrapper.py @@ -1,7 +1,9 @@ +""" This module provides a function to wrap a class to inherit from 'Agent'. """ + from swarms.structs.agent import Agent -def agent_wrapper(ClassToWrap): +def agent_wrapper(ClassToWrap): # noqa C0103 """ This function takes a class 'ClassToWrap' and returns a new class that inherits from both 'ClassToWrap' and 'Agent'. The new class overrides @@ -14,7 +16,8 @@ def agent_wrapper(ClassToWrap): type: The new class that inherits from both 'ClassToWrap' and 'Agent'. """ - class WrappedClass(ClassToWrap, Agent): + class WrappedClass(ClassToWrap, Agent): # noqa C0103 + """ A class that inherits from both 'ClassToWrap' and 'Agent'. """ def __init__(self, *args, **kwargs): try: Agent.__init__(self, *args, **kwargs) diff --git a/swarms/agents/base.py b/swarms/agents/base.py index 22c0addc..5ce53510 100644 --- a/swarms/agents/base.py +++ b/swarms/agents/base.py @@ -1,3 +1,5 @@ +""" Base class for AI agents. """ + from typing import Dict, List diff --git a/swarms/agents/omni_modal_agent.py b/swarms/agents/omni_modal_agent.py index 113ec461..1123c788 100644 --- a/swarms/agents/omni_modal_agent.py +++ b/swarms/agents/omni_modal_agent.py @@ -1,3 +1,5 @@ +""" OmniModalAgent """ + from langchain.base_language import BaseLanguageModel from langchain_experimental.autonomous_agents.hugginggpt.repsonse_generator import ( load_response_generator, @@ -72,11 +74,11 @@ class OmniModalAgent: # self.task_executor = TaskExecutor self.history = [] - def run(self, input: str) -> str: + def run(self, input_to_agent: str) -> str: """Run the OmniAgent""" plan = self.chat_planner.plan( inputs={ - "input": input, + "input": input_to_agent, "hf_tools": self.tools, } ) diff --git a/swarms/agents/simple_agent.py b/swarms/agents/simple_agent.py index 757715dd..4224d08f 100644 --- a/swarms/agents/simple_agent.py +++ b/swarms/agents/simple_agent.py @@ -1,8 +1,10 @@ -from swarms.structs.conversation import Conversation -from swarms.models.base_llm import AbstractLLM from typing import Any import importlib import pkgutil + +from swarms.structs.conversation import Conversation +from swarms.models.base_llm import AbstractLLM + import swarms.models @@ -16,7 +18,7 @@ def get_llm_by_name(name: str): Returns: type: The class with the given name, or None if no such class is found. """ - for importer, modname, ispkg in pkgutil.iter_modules( + for importer, modname, ispkg in pkgutil.iter_modules( # noqa: W0612 swarms.models.__path__ ): module = importlib.import_module(f"swarms.models.{modname}") @@ -26,7 +28,7 @@ def get_llm_by_name(name: str): # Run the language model in a loop for n iterations -def SimpleAgent( +def SimpleAgent( #noqa: C0103 llm: AbstractLLM = None, iters: Any = "automatic", *args, **kwargs ): """ @@ -39,21 +41,21 @@ def SimpleAgent( **kwargs: Additional keyword arguments to pass to the language model. Raises: - Exception: If the language model is not defined or cannot be found. + AttributeError: If the language model is not defined or cannot be found. Returns: None """ try: if llm is None: - raise Exception("Language model not defined") + raise AttributeError("Language model not defined") if isinstance(llm, str): llm = get_llm_by_name(llm) if llm is None: - raise Exception(f"Language model {llm} not found") + raise AttributeError(f"Language model {llm} not found") llm = llm(*args, **kwargs) - except Exception as error: + except AttributeError as error: print(f"[ERROR][SimpleAgent] {error}") raise error @@ -98,7 +100,7 @@ def SimpleAgent( print(f"[ERROR][SimpleAgentConversation] {error}") raise error - except KeyboardInterrupt: + except KeyboardInterrupt as exc: print("[INFO][SimpleAgentConversation] Keyboard interrupt") conv.export_conversation("conversation.txt") - raise KeyboardInterrupt + raise KeyboardInterrupt from exc