mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 08:26:41 +01:00
Fix OpenAI image generation with reasoning (#166827)
This commit is contained in:
@@ -346,7 +346,9 @@ async def _transform_stream( # noqa: C901 - This is complex, but better to have
|
||||
id=event.item.id,
|
||||
tool_name="web_search_call",
|
||||
tool_args={
|
||||
"action": event.item.action.to_dict(),
|
||||
"action": event.item.action.to_dict()
|
||||
if event.item.action
|
||||
else None,
|
||||
},
|
||||
external=True,
|
||||
)
|
||||
@@ -360,6 +362,10 @@ async def _transform_stream( # noqa: C901 - This is complex, but better to have
|
||||
}
|
||||
last_role = "tool_result"
|
||||
elif isinstance(event.item, ImageGenerationCall):
|
||||
if last_summary_index is not None:
|
||||
yield {"role": "assistant"}
|
||||
last_role = "assistant"
|
||||
last_summary_index = None
|
||||
yield {"native": event.item}
|
||||
last_summary_index = -1 # Trigger new assistant message on next turn
|
||||
elif isinstance(event, ResponseTextDeltaEvent):
|
||||
|
||||
@@ -14,7 +14,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir, selector
|
||||
|
||||
from . import create_image_gen_call_item, create_message_item
|
||||
from . import create_image_gen_call_item, create_message_item, create_reasoning_item
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -247,8 +247,15 @@ async def test_generate_image(
|
||||
|
||||
# Mock the OpenAI response stream
|
||||
mock_create_stream.return_value = [
|
||||
create_image_gen_call_item(id="ig_A", output_index=0),
|
||||
create_message_item(id="msg_A", text="", output_index=1),
|
||||
(
|
||||
*create_reasoning_item(
|
||||
id="rs_A",
|
||||
output_index=0,
|
||||
reasoning_summary=[["The user asks me to generate an image"]],
|
||||
),
|
||||
*create_image_gen_call_item(id="ig_A", output_index=1),
|
||||
*create_message_item(id="msg_A", text="", output_index=2),
|
||||
)
|
||||
]
|
||||
|
||||
with patch.object(
|
||||
|
||||
Reference in New Issue
Block a user