-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce PlannerService Class with Tests
- 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
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |