mirror of
https://github.com/home-assistant/core.git
synced 2026-04-27 05:57:53 +00:00
Add gpt-image-2 model support for OpenAI (#168826)
This commit is contained in:
@@ -525,7 +525,12 @@ class OpenAISubentryFlowHandler(ConfigSubentryFlow):
|
||||
vol.Optional(CONF_IMAGE_MODEL, default=RECOMMENDED_IMAGE_MODEL)
|
||||
] = SelectSelector(
|
||||
SelectSelectorConfig(
|
||||
options=["gpt-image-1.5", "gpt-image-1", "gpt-image-1-mini"],
|
||||
options=[
|
||||
"gpt-image-2",
|
||||
"gpt-image-1.5",
|
||||
"gpt-image-1",
|
||||
"gpt-image-1-mini",
|
||||
],
|
||||
mode=SelectSelectorMode.DROPDOWN,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ CONF_WEB_SEARCH_TIMEZONE = "timezone"
|
||||
CONF_WEB_SEARCH_INLINE_CITATIONS = "inline_citations"
|
||||
RECOMMENDED_CODE_INTERPRETER = False
|
||||
RECOMMENDED_CHAT_MODEL = "gpt-4o-mini"
|
||||
RECOMMENDED_IMAGE_MODEL = "gpt-image-1.5"
|
||||
RECOMMENDED_IMAGE_MODEL = "gpt-image-2"
|
||||
RECOMMENDED_MAX_TOKENS = 3000
|
||||
RECOMMENDED_REASONING_EFFORT = "low"
|
||||
RECOMMENDED_STORE_RESPONSES = False
|
||||
|
||||
@@ -615,7 +615,7 @@ class OpenAIBaseLLMEntity(Entity):
|
||||
model=image_model,
|
||||
output_format="png",
|
||||
)
|
||||
if image_model != "gpt-image-1-mini":
|
||||
if image_model not in ("gpt-image-1-mini", "gpt-image-2"):
|
||||
image_tool["input_fidelity"] = "high"
|
||||
tools.append(image_tool)
|
||||
# Keep image state on OpenAI so follow-up prompts can continue by
|
||||
|
||||
@@ -225,7 +225,13 @@ async def test_generate_data_with_attachments(
|
||||
@pytest.mark.freeze_time("2025-06-14 22:59:00")
|
||||
@pytest.mark.parametrize("configured_store", [False, True])
|
||||
@pytest.mark.parametrize(
|
||||
"image_model", ["gpt-image-1.5", "gpt-image-1", "gpt-image-1-mini"]
|
||||
("image_model", "input_fidelity_present"),
|
||||
[
|
||||
("gpt-image-2", False),
|
||||
("gpt-image-1.5", True),
|
||||
("gpt-image-1", True),
|
||||
("gpt-image-1-mini", False),
|
||||
],
|
||||
)
|
||||
async def test_generate_image(
|
||||
hass: HomeAssistant,
|
||||
@@ -234,6 +240,7 @@ async def test_generate_image(
|
||||
entity_registry: er.EntityRegistry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
image_model: str,
|
||||
input_fidelity_present: bool,
|
||||
configured_store: bool,
|
||||
) -> None:
|
||||
"""Test AI Task image generation."""
|
||||
@@ -296,6 +303,14 @@ async def test_generate_image(
|
||||
mock_upload_media.assert_called_once()
|
||||
assert mock_create_stream.call_args is not None
|
||||
assert mock_create_stream.call_args.kwargs["store"] is True
|
||||
image_tool = next(
|
||||
iter(
|
||||
tool
|
||||
for tool in mock_create_stream.call_args.kwargs["tools"]
|
||||
if tool["type"] == "image_generation"
|
||||
),
|
||||
)
|
||||
assert ("input_fidelity" in image_tool) == input_fidelity_present
|
||||
image_data = mock_upload_media.call_args[0][1]
|
||||
assert image_data.file.getvalue() == b"A"
|
||||
assert image_data.content_type == "image/png"
|
||||
|
||||
@@ -1196,7 +1196,7 @@ async def test_creating_ai_task_subentry_advanced(
|
||||
assert result4.get("data") == {
|
||||
CONF_RECOMMENDED: False,
|
||||
CONF_CHAT_MODEL: "gpt-4o",
|
||||
CONF_IMAGE_MODEL: "gpt-image-1.5",
|
||||
CONF_IMAGE_MODEL: "gpt-image-2",
|
||||
CONF_MAX_TOKENS: 200,
|
||||
CONF_STORE_RESPONSES: True,
|
||||
CONF_TEMPERATURE: 0.5,
|
||||
|
||||
Reference in New Issue
Block a user