Skip to content

Commit

Permalink
feat: Introduce PlannerService Class with Tests
Browse files Browse the repository at this point in the history
- Implement PlannerService class to encapsulate planner-related logic.
- Add pytest tests for PlannerService to validate its functionality.
- Fix mocking issue in PlannerService tests.
  • Loading branch information
shoutsid committed Oct 17, 2023
1 parent 4a8d303 commit a65ad6a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
23 changes: 23 additions & 0 deletions agents/services/planner_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
import os

sys.path.insert(
0,
os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")),
)

from autogen import AssistantAgent, UserProxyAgent


class PlannerService:
def __init__(self, config_list):
self.planner = AssistantAgent(
name="planner", llm_config={"config_list": config_list}
)
self.planner_user = UserProxyAgent(
name="planner_user", max_consecutive_auto_reply=0, human_input_mode="NEVER"
)

def ask_planner(self, msg):
self.planner_user.initiate_chat(self.planner, message=msg)
return self.planner_user.last_message()["content"]
24 changes: 24 additions & 0 deletions tests/agents/services/planner_service_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
from unittest.mock import patch, MagicMock
import sys
import os

sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
)

from agents.services.planner_service import PlannerService


@pytest.mark.parametrize(
"msg, expected", [("Hello", "Hello, Planner!"), ("Test", "Test message!")]
)
def test_ask_planner(msg, expected):
with patch("agents.services.planner_service.AssistantAgent") as MockedAgent, patch(
"agents.services.planner_service.UserProxyAgent"
) as MockedProxy:
mocked_last_message = MagicMock()
mocked_last_message.return_value = {"content": expected}
MockedProxy.return_value.last_message = mocked_last_message
service = PlannerService("some_config")
assert service.ask_planner(msg) == expected

0 comments on commit a65ad6a

Please sign in to comment.