diff --git a/mkdocs.yml b/mkdocs.yml index b9f1e856..f02daa9a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -61,10 +61,6 @@ nav: - Docker Container Setup: "docker_setup.md" - Swarms: - Overview: "swarms/index.md" - - swarms.swarms: - - AbstractSwarm: "swarms/swarms/abstractswarm.md" - - ModelParallelizer: "swarms/swarms/ModelParallelizer.md" - - Groupchat: "swarms/swarms/groupchat.md" - swarms.workers: - Overview: "swarms/workers/index.md" - AbstractWorker: "swarms/workers/abstract_worker.md" @@ -106,6 +102,9 @@ nav: - Agent: "swarms/structs/agent.md" - SequentialWorkflow: 'swarms/structs/sequential_workflow.md' - Conversation: "swarms/structs/conversation.md" + - AbstractSwarm: "swarms/swarms/abstractswarm.md" + - ModelParallelizer: "swarms/swarms/ModelParallelizer.md" + - Groupchat: "swarms/swarms/groupchat.md" - swarms.memory: - Weaviate: "swarms/memory/weaviate.md" - PineconeDB: "swarms/memory/pinecone.md" diff --git a/playground/swarms/groupchat.py b/playground/swarms/groupchat.py index f53257c7..b9ab5761 100644 --- a/playground/swarms/groupchat.py +++ b/playground/swarms/groupchat.py @@ -1,5 +1,5 @@ from swarms import OpenAI, Agent -from swarms.swarms.groupchat import GroupChatManager, GroupChat +from swarms.structs.groupchat import GroupChatManager, GroupChat api_key = "" diff --git a/swarms/swarms/README.md b/swarms/structs/README.md similarity index 100% rename from swarms/swarms/README.md rename to swarms/structs/README.md diff --git a/swarms/structs/__init__.py b/swarms/structs/__init__.py index 5921fb52..add8624d 100644 --- a/swarms/structs/__init__.py +++ b/swarms/structs/__init__.py @@ -10,6 +10,14 @@ from swarms.structs.schemas import ( ) from swarms.structs.swarm_net import SwarmNetwork + +from swarms.structs.model_parallizer import ModelParallelizer +from swarms.structs.multi_agent_collab import MultiAgentCollaboration +from swarms.structs.base_swarm import AbstractSwarm +from swarms.structs.groupchat import GroupChat, GroupChatManager + + + __all__ = [ "Agent", "SequentialWorkflow", @@ -20,4 +28,9 @@ __all__ = [ "ArtifactUpload", "StepInput", "SwarmNetwork", + "ModelParallelizer", + "MultiAgentCollaboration", + "AbstractSwarm", + "GroupChat", + "GroupChatManager", ] diff --git a/swarms/swarms/base.py b/swarms/structs/base_swarm.py similarity index 100% rename from swarms/swarms/base.py rename to swarms/structs/base_swarm.py diff --git a/swarms/swarms/groupchat.py b/swarms/structs/groupchat.py similarity index 100% rename from swarms/swarms/groupchat.py rename to swarms/structs/groupchat.py diff --git a/swarms/swarms/model_parallizer.py b/swarms/structs/model_parallizer.py similarity index 100% rename from swarms/swarms/model_parallizer.py rename to swarms/structs/model_parallizer.py diff --git a/swarms/swarms/multi_agent_collab.py b/swarms/structs/multi_agent_collab.py similarity index 100% rename from swarms/swarms/multi_agent_collab.py rename to swarms/structs/multi_agent_collab.py diff --git a/swarms/swarms/team.py b/swarms/structs/team.py similarity index 100% rename from swarms/swarms/team.py rename to swarms/structs/team.py diff --git a/swarms/swarms/utils.py b/swarms/structs/utils.py similarity index 100% rename from swarms/swarms/utils.py rename to swarms/structs/utils.py diff --git a/swarms/swarms/__init__.py b/swarms/swarms/__init__.py deleted file mode 100644 index 38ee6fb9..00000000 --- a/swarms/swarms/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -from swarms.structs.autoscaler import AutoScaler -from swarms.swarms.model_parallizer import ModelParallelizer -from swarms.swarms.multi_agent_collab import MultiAgentCollaboration -from swarms.swarms.base import AbstractSwarm - -# from swarms.swarms.team import Team - -__all__ = [ - "AutoScaler", - "ModelParallelizer", - "MultiAgentCollaboration", - "AbstractSwarm", -] diff --git a/tests/structs/test_autoscaler.py b/tests/structs/test_autoscaler.py index 62abeede..39d56741 100644 --- a/tests/structs/test_autoscaler.py +++ b/tests/structs/test_autoscaler.py @@ -216,3 +216,65 @@ def test_add_task_exception(mock_put): with pytest.raises(Exception) as e: autoscaler.add_task("test_task") assert str(e.value) == "test error" + + + +def test_autoscaler_initialization(): + autoscaler = AutoScaler( + initial_agents=5, + scale_up_factor=2, + idle_threshold=0.1, + busy_threshold=0.8, + agent=agent, + ) + assert isinstance(autoscaler, AutoScaler) + assert autoscaler.scale_up_factor == 2 + assert autoscaler.idle_threshold == 0.1 + assert autoscaler.busy_threshold == 0.8 + assert len(autoscaler.agents_pool) == 5 + + +def test_autoscaler_add_task(): + autoscaler = AutoScaler(agent=agent) + autoscaler.add_task("task1") + assert autoscaler.task_queue.qsize() == 1 + + +def test_autoscaler_scale_up(): + autoscaler = AutoScaler( + initial_agents=5, scale_up_factor=2, agent=agent + ) + autoscaler.scale_up() + assert len(autoscaler.agents_pool) == 10 + + +def test_autoscaler_scale_down(): + autoscaler = AutoScaler(initial_agents=5, agent=agent) + autoscaler.scale_down() + assert len(autoscaler.agents_pool) == 4 + + +@patch("swarms.swarms.AutoScaler.scale_up") +@patch("swarms.swarms.AutoScaler.scale_down") +def test_autoscaler_monitor_and_scale(mock_scale_down, mock_scale_up): + autoscaler = AutoScaler(initial_agents=5, agent=agent) + autoscaler.add_task("task1") + autoscaler.monitor_and_scale() + mock_scale_up.assert_called_once() + mock_scale_down.assert_called_once() + + +@patch("swarms.swarms.AutoScaler.monitor_and_scale") +@patch("swarms.swarms.agent.run") +def test_autoscaler_start(mock_run, mock_monitor_and_scale): + autoscaler = AutoScaler(initial_agents=5, agent=agent) + autoscaler.add_task("task1") + autoscaler.start() + mock_run.assert_called_once() + mock_monitor_and_scale.assert_called_once() + + +def test_autoscaler_del_agent(): + autoscaler = AutoScaler(initial_agents=5, agent=agent) + autoscaler.del_agent() + assert len(autoscaler.agents_pool) == 4 diff --git a/tests/swarms/test_groupchat.py b/tests/structs/test_groupchat.py similarity index 99% rename from tests/swarms/test_groupchat.py rename to tests/structs/test_groupchat.py index ce17a4d2..e8096d9c 100644 --- a/tests/swarms/test_groupchat.py +++ b/tests/structs/test_groupchat.py @@ -3,7 +3,7 @@ import pytest from swarms.models import OpenAIChat from swarms.models.anthropic import Anthropic from swarms.structs.agent import Agent -from swarms.swarms.groupchat import GroupChat, GroupChatManager +from swarms.structs.groupchat import GroupChat, GroupChatManager llm = OpenAIChat() llm2 = Anthropic() diff --git a/tests/swarms/test_model_parallizer.py b/tests/structs/test_model_parallizer.py similarity index 98% rename from tests/swarms/test_model_parallizer.py rename to tests/structs/test_model_parallizer.py index fb3dc2b2..37ca43db 100644 --- a/tests/swarms/test_model_parallizer.py +++ b/tests/structs/test_model_parallizer.py @@ -1,5 +1,5 @@ import pytest -from swarms.swarms.model_parallizer import ModelParallelizer +from swarms.structs.model_parallizer import ModelParallelizer from swarms.models import ( HuggingfaceLLM, Mixtral, diff --git a/tests/swarms/test_multi_agent_collab.py b/tests/structs/test_multi_agent_collab.py similarity index 98% rename from tests/swarms/test_multi_agent_collab.py rename to tests/structs/test_multi_agent_collab.py index 4d85a436..05b914b4 100644 --- a/tests/swarms/test_multi_agent_collab.py +++ b/tests/structs/test_multi_agent_collab.py @@ -4,7 +4,7 @@ import pytest from unittest.mock import Mock from swarms.structs import Agent from swarms.models import OpenAIChat -from swarms.swarms.multi_agent_collab import ( +from swarms.structs.multi_agent_collab import ( MultiAgentCollaboration, ) diff --git a/tests/structs/test_team.py b/tests/structs/test_team.py new file mode 100644 index 00000000..44d64e18 --- /dev/null +++ b/tests/structs/test_team.py @@ -0,0 +1,52 @@ +import json +import unittest + +from swarms.models import OpenAIChat +from swarms.structs import Agent, Task +from swarms.structs.team import Team + + +class TestTeam(unittest.TestCase): + def setUp(self): + self.agent = Agent( + llm=OpenAIChat(openai_api_key=""), + max_loops=1, + dashboard=False, + ) + self.task = Task( + description="What's the weather in miami", + agent=self.agent, + ) + self.team = Team( + tasks=[self.task], + agents=[self.agent], + architecture="sequential", + verbose=False, + ) + + def test_check_config(self): + with self.assertRaises(ValueError): + self.team.check_config({"config": None}) + + with self.assertRaises(ValueError): + self.team.check_config( + {"config": json.dumps({"agents": [], "tasks": []})} + ) + + def test_run(self): + self.assertEqual(self.team.run(), self.task.execute()) + + def test_sequential_loop(self): + self.assertEqual( + self.team._Team__sequential_loop(), self.task.execute() + ) + + def test_log(self): + self.assertIsNone(self.team._Team__log("Test message")) + + self.team.verbose = True + self.assertIsNone(self.team._Team__log("Test message")) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/swarms/test_autoscaler.py b/tests/swarms/test_autoscaler.py deleted file mode 100644 index fbf63637..00000000 --- a/tests/swarms/test_autoscaler.py +++ /dev/null @@ -1,73 +0,0 @@ -from unittest.mock import patch -from swarms.structs.autoscaler import AutoScaler -from swarms.models import OpenAIChat -from swarms.structs import Agent - -llm = OpenAIChat() - -agent = Agent( - llm=llm, - max_loops=2, - dashboard=True, -) - - -def test_autoscaler_initialization(): - autoscaler = AutoScaler( - initial_agents=5, - scale_up_factor=2, - idle_threshold=0.1, - busy_threshold=0.8, - agent=agent, - ) - assert isinstance(autoscaler, AutoScaler) - assert autoscaler.scale_up_factor == 2 - assert autoscaler.idle_threshold == 0.1 - assert autoscaler.busy_threshold == 0.8 - assert len(autoscaler.agents_pool) == 5 - - -def test_autoscaler_add_task(): - autoscaler = AutoScaler(agent=agent) - autoscaler.add_task("task1") - assert autoscaler.task_queue.qsize() == 1 - - -def test_autoscaler_scale_up(): - autoscaler = AutoScaler( - initial_agents=5, scale_up_factor=2, agent=agent - ) - autoscaler.scale_up() - assert len(autoscaler.agents_pool) == 10 - - -def test_autoscaler_scale_down(): - autoscaler = AutoScaler(initial_agents=5, agent=agent) - autoscaler.scale_down() - assert len(autoscaler.agents_pool) == 4 - - -@patch("swarms.swarms.AutoScaler.scale_up") -@patch("swarms.swarms.AutoScaler.scale_down") -def test_autoscaler_monitor_and_scale(mock_scale_down, mock_scale_up): - autoscaler = AutoScaler(initial_agents=5, agent=agent) - autoscaler.add_task("task1") - autoscaler.monitor_and_scale() - mock_scale_up.assert_called_once() - mock_scale_down.assert_called_once() - - -@patch("swarms.swarms.AutoScaler.monitor_and_scale") -@patch("swarms.swarms.agent.run") -def test_autoscaler_start(mock_run, mock_monitor_and_scale): - autoscaler = AutoScaler(initial_agents=5, agent=agent) - autoscaler.add_task("task1") - autoscaler.start() - mock_run.assert_called_once() - mock_monitor_and_scale.assert_called_once() - - -def test_autoscaler_del_agent(): - autoscaler = AutoScaler(initial_agents=5, agent=agent) - autoscaler.del_agent() - assert len(autoscaler.agents_pool) == 4