Skip to content

update: openai response api #6622

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

Merged
merged 6 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
update: openai response api
  • Loading branch information
bassmang committed Jun 3, 2025
commit 19ce24681b6de0e35f6c424db0303595ded39d16
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def _build_api_parameters(self: "OpenAIAgent", messages: List[Dict[str, Any]]) -
if self._tools:
api_params["tools"] = self._tools
if self._json_mode:
api_params["response_format"] = {"type": "json_object"}
api_params["text"] = {"type": "json_object"}
api_params["store"] = self._store
api_params["truncation"] = self._truncation
if self._last_response_id:
Expand Down
27 changes: 26 additions & 1 deletion python/packages/autogen-ext/tests/test_openai_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from autogen_agentchat.base import Response
from autogen_agentchat.messages import BaseChatMessage, TextMessage
from autogen_core import CancellationToken, FunctionCall
from autogen_core import CancellationToken, FunctionCall, Image
from autogen_core.models import UserMessage
from autogen_core.tools import Tool, ToolSchema
from autogen_ext.agents.openai import OpenAIAgent
Expand Down Expand Up @@ -566,3 +566,28 @@ async def test_from_config(agent: OpenAIAgent) -> None:
assert loaded_agent._max_output_tokens == 1000 # type: ignore
assert loaded_agent._store is True # type: ignore
assert loaded_agent._truncation == "auto" # type: ignore

@pytest.mark.asyncio
async def test_multimodal_message_response(agent: OpenAIAgent, cancellation_token: CancellationToken) -> None:

# Test that the multimodal message is converted to the correct format
img = Image.from_base64(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC"
)
multimodal_message = MultiModalMessage(content=["Can you describe the content of this image?", img], source="user")

# Patch client.responses.create to simulate image-capable output
async def mock_responses_create(**kwargs: Any) -> Any:
class MockResponse:
def __init__(self) -> None:
self.output_text = "I see a cat in the image."
self.id = "resp-image-001"
return MockResponse()

agent._client.responses.create = AsyncMock(side_effect=mock_responses_create) # type: ignore

response = await agent.on_messages([multimodal_message], cancellation_token)

assert response.chat_message is not None
assert isinstance(response.chat_message, TextMessage)
assert "cat" in response.chat_message.content.lower()
Loading