Skip to content

Commit

Permalink
Remove deprecated DALL-E image formats (#122388)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shulyaka authored Jul 22, 2024
1 parent 489457c commit ee30510
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 57 deletions.
33 changes: 3 additions & 30 deletions homeassistant/components/openai_conversation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

from typing import Literal, cast

import openai
import voluptuous as vol

Expand All @@ -20,11 +18,7 @@
HomeAssistantError,
ServiceValidationError,
)
from homeassistant.helpers import (
config_validation as cv,
issue_registry as ir,
selector,
)
from homeassistant.helpers import config_validation as cv, selector
from homeassistant.helpers.typing import ConfigType

from .const import DOMAIN, LOGGER
Expand Down Expand Up @@ -53,32 +47,11 @@ async def render_image(call: ServiceCall) -> ServiceResponse:

client: openai.AsyncClient = entry.runtime_data

if call.data["size"] in ("256", "512", "1024"):
ir.async_create_issue(
hass,
DOMAIN,
"image_size_deprecated_format",
breaks_in_ha_version="2024.7.0",
is_fixable=False,
is_persistent=True,
learn_more_url="https://www.home-assistant.io/integrations/openai_conversation/",
severity=ir.IssueSeverity.WARNING,
translation_key="image_size_deprecated_format",
)
size = "1024x1024"
else:
size = call.data["size"]

size = cast(
Literal["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"],
size,
) # size is selector, so no need to check further

try:
response = await client.images.generate(
model="dall-e-3",
prompt=call.data["prompt"],
size=size,
size=call.data["size"],
quality=call.data["quality"],
style=call.data["style"],
response_format="url",
Expand All @@ -102,7 +75,7 @@ async def render_image(call: ServiceCall) -> ServiceResponse:
),
vol.Required("prompt"): cv.string,
vol.Optional("size", default="1024x1024"): vol.In(
("1024x1024", "1024x1792", "1792x1024", "256", "512", "1024")
("1024x1024", "1024x1792", "1792x1024")
),
vol.Optional("quality", default="standard"): vol.In(("standard", "hd")),
vol.Optional("style", default="vivid"): vol.In(("vivid", "natural")),
Expand Down
27 changes: 0 additions & 27 deletions tests/components/openai_conversation/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,6 @@
"style": "natural",
},
),
(
{"prompt": "Picture of a dog", "size": "256"},
{
"prompt": "Picture of a dog",
"size": "1024x1024",
"quality": "standard",
"style": "vivid",
},
),
(
{"prompt": "Picture of a dog", "size": "512"},
{
"prompt": "Picture of a dog",
"size": "1024x1024",
"quality": "standard",
"style": "vivid",
},
),
(
{"prompt": "Picture of a dog", "size": "1024"},
{
"prompt": "Picture of a dog",
"size": "1024x1024",
"quality": "standard",
"style": "vivid",
},
),
],
)
async def test_generate_image_service(
Expand Down

0 comments on commit ee30510

Please sign in to comment.