Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content parameter of TextMessage class can also be list #432

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autogen/messages/agent_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def print(self, f: Optional[Callable[..., Any]] = None) -> None:

@wrap_message
class TextMessage(BasePrintReceivedMessage):
content: Optional[Union[str, int, float, bool]] = None # type: ignore [assignment]
content: Optional[Union[str, int, float, bool, list[dict[str, str]]]] = None # type: ignore [assignment]

def print(self, f: Optional[Callable[..., Any]] = None) -> None:
f = f or print
Expand Down
37 changes: 30 additions & 7 deletions test/messages/test_agent_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,42 @@ def test_print(


class TestTextMessage:
def test_print_context_message(self, uuid: UUID, sender: ConversableAgent, recipient: ConversableAgent) -> None:
message = {"content": "hello {name}", "context": {"name": "there"}}

@pytest.mark.parametrize(
"message, expected_content",
[
(
{"content": "hello {name}", "context": {"name": "there"}},
"hello {name}",
),
(
{
"content": [
{
"type": "text",
"text": "Please extract table from the following image and convert it to Markdown.",
}
]
},
"Please extract table from the following image and convert it to Markdown.",
),
],
)
def test_print_messages(
self,
uuid: UUID,
sender: ConversableAgent,
recipient: ConversableAgent,
message: dict[str, Any],
expected_content: str,
) -> None:
actual = create_received_message_model(uuid=uuid, message=message, sender=sender, recipient=recipient)

assert isinstance(actual, TextMessage)
expected_model_dump = {
"type": "text",
"content": {
"uuid": uuid,
"content": "hello {name}",
"content": message["content"],
"sender_name": "sender",
"recipient_name": "recipient",
},
Expand All @@ -325,11 +350,9 @@ def test_print_context_message(self, uuid: UUID, sender: ConversableAgent, recip
mock = MagicMock()
actual.print(f=mock)

# print(mock.call_args_list)

expected_call_args_list = [
call("\x1b[33msender\x1b[0m (to recipient):\n", flush=True),
call("hello {name}", flush=True),
call(expected_content, flush=True),
call(
"\n",
"--------------------------------------------------------------------------------",
Expand Down
Loading