[CLEANUP][swarms.swarms -> swarms.structs]

pull/323/head^2
Kye 1 year ago
parent 61c1894576
commit 8791248eff

@ -61,10 +61,6 @@ nav:
- Docker Container Setup: "docker_setup.md" - Docker Container Setup: "docker_setup.md"
- Swarms: - Swarms:
- Overview: "swarms/index.md" - Overview: "swarms/index.md"
- swarms.swarms:
- AbstractSwarm: "swarms/swarms/abstractswarm.md"
- ModelParallelizer: "swarms/swarms/ModelParallelizer.md"
- Groupchat: "swarms/swarms/groupchat.md"
- swarms.workers: - swarms.workers:
- Overview: "swarms/workers/index.md" - Overview: "swarms/workers/index.md"
- AbstractWorker: "swarms/workers/abstract_worker.md" - AbstractWorker: "swarms/workers/abstract_worker.md"
@ -106,6 +102,9 @@ nav:
- Agent: "swarms/structs/agent.md" - Agent: "swarms/structs/agent.md"
- SequentialWorkflow: 'swarms/structs/sequential_workflow.md' - SequentialWorkflow: 'swarms/structs/sequential_workflow.md'
- Conversation: "swarms/structs/conversation.md" - Conversation: "swarms/structs/conversation.md"
- AbstractSwarm: "swarms/swarms/abstractswarm.md"
- ModelParallelizer: "swarms/swarms/ModelParallelizer.md"
- Groupchat: "swarms/swarms/groupchat.md"
- swarms.memory: - swarms.memory:
- Weaviate: "swarms/memory/weaviate.md" - Weaviate: "swarms/memory/weaviate.md"
- PineconeDB: "swarms/memory/pinecone.md" - PineconeDB: "swarms/memory/pinecone.md"

@ -1,5 +1,5 @@
from swarms import OpenAI, Agent from swarms import OpenAI, Agent
from swarms.swarms.groupchat import GroupChatManager, GroupChat from swarms.structs.groupchat import GroupChatManager, GroupChat
api_key = "" api_key = ""

@ -10,6 +10,14 @@ from swarms.structs.schemas import (
) )
from swarms.structs.swarm_net import SwarmNetwork 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__ = [ __all__ = [
"Agent", "Agent",
"SequentialWorkflow", "SequentialWorkflow",
@ -20,4 +28,9 @@ __all__ = [
"ArtifactUpload", "ArtifactUpload",
"StepInput", "StepInput",
"SwarmNetwork", "SwarmNetwork",
"ModelParallelizer",
"MultiAgentCollaboration",
"AbstractSwarm",
"GroupChat",
"GroupChatManager",
] ]

@ -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",
]

@ -216,3 +216,65 @@ def test_add_task_exception(mock_put):
with pytest.raises(Exception) as e: with pytest.raises(Exception) as e:
autoscaler.add_task("test_task") autoscaler.add_task("test_task")
assert str(e.value) == "test error" 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

@ -3,7 +3,7 @@ import pytest
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.models.anthropic import Anthropic from swarms.models.anthropic import Anthropic
from swarms.structs.agent import Agent from swarms.structs.agent import Agent
from swarms.swarms.groupchat import GroupChat, GroupChatManager from swarms.structs.groupchat import GroupChat, GroupChatManager
llm = OpenAIChat() llm = OpenAIChat()
llm2 = Anthropic() llm2 = Anthropic()

@ -1,5 +1,5 @@
import pytest import pytest
from swarms.swarms.model_parallizer import ModelParallelizer from swarms.structs.model_parallizer import ModelParallelizer
from swarms.models import ( from swarms.models import (
HuggingfaceLLM, HuggingfaceLLM,
Mixtral, Mixtral,

@ -4,7 +4,7 @@ import pytest
from unittest.mock import Mock from unittest.mock import Mock
from swarms.structs import Agent from swarms.structs import Agent
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.swarms.multi_agent_collab import ( from swarms.structs.multi_agent_collab import (
MultiAgentCollaboration, MultiAgentCollaboration,
) )

@ -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()

@ -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
Loading…
Cancel
Save