From 949225ffebad2280c380f204c8b795f87d6c967c Mon Sep 17 00:00:00 2001 From: Denis Shulyaka Date: Wed, 30 Apr 2025 19:07:55 +0300 Subject: [PATCH] Bump openai to 1.76.2 (#143902) * Bump openai to 1.76.1 * Fix mypy * Fix coverage * 1.76.2 --------- Co-authored-by: Paulus Schoutsen --- .../openai_conversation/__init__.py | 3 +++ .../openai_conversation/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../openai_conversation/test_init.py | 27 +++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/openai_conversation/__init__.py b/homeassistant/components/openai_conversation/__init__.py index 276f5ddea3b..7da1becd333 100644 --- a/homeassistant/components/openai_conversation/__init__.py +++ b/homeassistant/components/openai_conversation/__init__.py @@ -101,6 +101,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: except openai.OpenAIError as err: raise HomeAssistantError(f"Error generating image: {err}") from err + if not response.data or not response.data[0].url: + raise HomeAssistantError("No image returned") + return response.data[0].model_dump(exclude={"b64_json"}) async def send_prompt(call: ServiceCall) -> ServiceResponse: diff --git a/homeassistant/components/openai_conversation/manifest.json b/homeassistant/components/openai_conversation/manifest.json index 988dd2321d5..84369eb15a2 100644 --- a/homeassistant/components/openai_conversation/manifest.json +++ b/homeassistant/components/openai_conversation/manifest.json @@ -8,5 +8,5 @@ "documentation": "https://www.home-assistant.io/integrations/openai_conversation", "integration_type": "service", "iot_class": "cloud_polling", - "requirements": ["openai==1.68.2"] + "requirements": ["openai==1.76.2"] } diff --git a/requirements_all.txt b/requirements_all.txt index 7f0979c67d1..e716b99a217 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1590,7 +1590,7 @@ open-garage==0.2.0 open-meteo==0.3.2 # homeassistant.components.openai_conversation -openai==1.68.2 +openai==1.76.2 # homeassistant.components.openerz openerz-api==0.3.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index fd6c7f33d92..902aa0ffbd2 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1339,7 +1339,7 @@ open-garage==0.2.0 open-meteo==0.3.2 # homeassistant.components.openai_conversation -openai==1.68.2 +openai==1.76.2 # homeassistant.components.openerz openerz-api==0.3.0 diff --git a/tests/components/openai_conversation/test_init.py b/tests/components/openai_conversation/test_init.py index c4d5605de03..dc83aa48807 100644 --- a/tests/components/openai_conversation/test_init.py +++ b/tests/components/openai_conversation/test_init.py @@ -136,6 +136,33 @@ async def test_generate_image_service_error( return_response=True, ) + with ( + patch( + "openai.resources.images.AsyncImages.generate", + return_value=ImagesResponse( + created=1700000000, + data=[ + Image( + b64_json=None, + revised_prompt=None, + url=None, + ) + ], + ), + ), + pytest.raises(HomeAssistantError, match="No image returned"), + ): + await hass.services.async_call( + "openai_conversation", + "generate_image", + { + "config_entry": mock_config_entry.entry_id, + "prompt": "Image of an epic fail", + }, + blocking=True, + return_response=True, + ) + @pytest.mark.usefixtures("mock_init_component") async def test_generate_content_service_with_image_not_allowed_path(