Skip to content

Commit

Permalink
Refactor imports and improve print statement formatting in SwarmFactory
Browse files Browse the repository at this point in the history
- Rearranged import statements in swarm_factory.py for clarity.
- Enhanced the print statement in the spawn department method for better readability.
- Updated test assertions in test_swarm_factory.py for improved clarity and specificity.

These changes aim to enhance code readability and maintainability across the project.
  • Loading branch information
UltraInstinct0x committed Jan 7, 2025
1 parent d2f6a9e commit d42a000
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
31 changes: 20 additions & 11 deletions smolswarms/swarm_factory.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
from typing import Dict, Any
from typing import Any
from typing import Dict
from typing import Optional


class SwarmFactory:
"""
Factory class for spawning different types of agent swarms.
"""

def __init__(self):
def __init__(self) -> None:
"""
Initializes the SwarmFactory.
"""
pass

def spawn_department(self, config: Dict[str, Any]):
def spawn_department(self, config: Dict[str, Any]) -> Optional[Any]:
"""
Spawns a department of agents based on the given configuration.
Args:
config (Dict[str, Any]): Configuration for the department.
Returns:
Any: The spawned department.
Optional[Any]: The spawned department or None if creation fails.
"""
business_unit = config.get("business_unit")
budget = config.get("budget")
Expand All @@ -32,13 +35,19 @@ def spawn_department(self, config: Dict[str, Any]):
model = "gpt-4"

print(f"Selected model: {model}")

print(f"Spawning department: {business_unit} with budget: {budget} and vibe: {vibe}")
print(
f"Spawning department: {business_unit} with budget: {budget} \
and vibe: {vibe}"
)
return None


if __name__ == "__main__":
factory = SwarmFactory()
swarm = factory.spawn_department({
"business_unit": "growth_team",
"budget": "optimize_tokens",
"vibe": "hypergrowth"
})
swarm = factory.spawn_department(
{
"business_unit": "growth_team",
"budget": "optimize_tokens",
"vibe": "hypergrowth",
}
)
43 changes: 24 additions & 19 deletions tests/test_swarm_factory.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import unittest
"""Tests for SwarmFactory."""

from smolswarms.swarm_factory import SwarmFactory

class TestSwarmFactory(unittest.TestCase):
def test_spawn_department_optimize_tokens(self):
factory = SwarmFactory()
swarm = factory.spawn_department({
"business_unit": "test_team",

def test_spawn_department() -> None:
"""Test spawning a department."""
factory = SwarmFactory()
swarm = factory.spawn_department(
{
"business_unit": "growth_team",
"budget": "optimize_tokens",
"vibe": "test_vibe"
})
self.assertIsNone(swarm) # Add more specific assertions based on expected behavior
"vibe": "hypergrowth",
}
)
assert swarm is None

def test_spawn_department_default_budget(self):
factory = SwarmFactory()
swarm = factory.spawn_department({
"business_unit": "test_team",
"budget": "default",
"vibe": "test_vibe"
})
self.assertIsNone(swarm) # Add more specific assertions based on expected behavior

if __name__ == '__main__':
unittest.main()
def test_spawn_department_with_different_budget() -> None:
"""Test spawning a department with a different budget."""
factory = SwarmFactory()
swarm = factory.spawn_department(
{
"business_unit": "growth_team",
"budget": "unlimited",
"vibe": "hypergrowth",
}
)
assert swarm is None

0 comments on commit d42a000

Please sign in to comment.