|
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 | from autogen_agentchat.base import Response
|
7 |
| -from autogen_agentchat.messages import BaseChatMessage, TextMessage |
8 |
| -from autogen_core import CancellationToken, FunctionCall |
| 7 | +from autogen_agentchat.messages import BaseChatMessage, MultiModalMessage, TextMessage |
| 8 | +from autogen_core import CancellationToken, FunctionCall, Image |
9 | 9 | from autogen_core.models import UserMessage
|
10 | 10 | from autogen_core.tools import Tool, ToolSchema
|
11 | 11 | from autogen_ext.agents.openai import OpenAIAgent
|
@@ -446,7 +446,7 @@ async def test_build_api_params(agent: OpenAIAgent) -> None:
|
446 | 446 | agent._json_mode = True # type: ignore
|
447 | 447 | params = agent._build_api_parameters([{"role": "user", "content": "hi"}]) # type: ignore
|
448 | 448 | assert "text.format" not in params
|
449 |
| - assert params.get("response_format") == {"type": "json_object"} |
| 449 | + assert params.get("text") == {"type": "json_object"} |
450 | 450 |
|
451 | 451 |
|
452 | 452 | @pytest.mark.asyncio
|
@@ -568,3 +568,29 @@ async def test_from_config(agent: OpenAIAgent) -> None:
|
568 | 568 | assert loaded_agent._max_output_tokens == 1000 # type: ignore
|
569 | 569 | assert loaded_agent._store is True # type: ignore
|
570 | 570 | assert loaded_agent._truncation == "auto" # type: ignore
|
| 571 | + |
| 572 | + |
| 573 | +@pytest.mark.asyncio |
| 574 | +async def test_multimodal_message_response(agent: OpenAIAgent, cancellation_token: CancellationToken) -> None: |
| 575 | + # Test that the multimodal message is converted to the correct format |
| 576 | + img = Image.from_base64( |
| 577 | + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC" |
| 578 | + ) |
| 579 | + multimodal_message = MultiModalMessage(content=["Can you describe the content of this image?", img], source="user") |
| 580 | + |
| 581 | + # Patch client.responses.create to simulate image-capable output |
| 582 | + async def mock_responses_create(**kwargs: Any) -> Any: |
| 583 | + class MockResponse: |
| 584 | + def __init__(self) -> None: |
| 585 | + self.output_text = "I see a cat in the image." |
| 586 | + self.id = "resp-image-001" |
| 587 | + |
| 588 | + return MockResponse() |
| 589 | + |
| 590 | + agent._client.responses.create = AsyncMock(side_effect=mock_responses_create) # type: ignore |
| 591 | + |
| 592 | + response = await agent.on_messages([multimodal_message], cancellation_token) |
| 593 | + |
| 594 | + assert response.chat_message is not None |
| 595 | + assert isinstance(response.chat_message, TextMessage) |
| 596 | + assert "cat" in response.chat_message.content.lower() |
0 commit comments