From df025b5993e58fca34535e085681adf279db34c7 Mon Sep 17 00:00:00 2001 From: Joseph <1315585+joseph39@users.noreply.github.com> Date: Fri, 24 Nov 2023 04:14:44 -0800 Subject: [PATCH] Enumerate openai.Models to validate config (#99438) --- homeassistant/components/openai_conversation/__init__.py | 2 +- homeassistant/components/openai_conversation/config_flow.py | 2 +- tests/components/openai_conversation/conftest.py | 2 +- tests/components/openai_conversation/test_config_flow.py | 4 ++-- tests/components/openai_conversation/test_init.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/openai_conversation/__init__.py b/homeassistant/components/openai_conversation/__init__.py index 0279580e56b..054ccbdbe37 100644 --- a/homeassistant/components/openai_conversation/__init__.py +++ b/homeassistant/components/openai_conversation/__init__.py @@ -89,7 +89,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: await hass.async_add_executor_job( partial( - openai.Engine.list, + openai.Model.list, api_key=entry.data[CONF_API_KEY], request_timeout=10, ) diff --git a/homeassistant/components/openai_conversation/config_flow.py b/homeassistant/components/openai_conversation/config_flow.py index b391f531eb1..9c5ef32d796 100644 --- a/homeassistant/components/openai_conversation/config_flow.py +++ b/homeassistant/components/openai_conversation/config_flow.py @@ -60,7 +60,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None: Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user. """ openai.api_key = data[CONF_API_KEY] - await hass.async_add_executor_job(partial(openai.Engine.list, request_timeout=10)) + await hass.async_add_executor_job(partial(openai.Model.list, request_timeout=10)) class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/tests/components/openai_conversation/conftest.py b/tests/components/openai_conversation/conftest.py index 9f00290600e..40f2eb33f08 100644 --- a/tests/components/openai_conversation/conftest.py +++ b/tests/components/openai_conversation/conftest.py @@ -25,7 +25,7 @@ def mock_config_entry(hass): async def mock_init_component(hass, mock_config_entry): """Initialize integration.""" with patch( - "openai.Engine.list", + "openai.Model.list", ): assert await async_setup_component(hass, "openai_conversation", {}) await hass.async_block_till_done() diff --git a/tests/components/openai_conversation/test_config_flow.py b/tests/components/openai_conversation/test_config_flow.py index 471be8035b6..43dfc26ca82 100644 --- a/tests/components/openai_conversation/test_config_flow.py +++ b/tests/components/openai_conversation/test_config_flow.py @@ -32,7 +32,7 @@ async def test_form(hass: HomeAssistant) -> None: assert result["errors"] is None with patch( - "homeassistant.components.openai_conversation.config_flow.openai.Engine.list", + "homeassistant.components.openai_conversation.config_flow.openai.Model.list", ), patch( "homeassistant.components.openai_conversation.async_setup_entry", return_value=True, @@ -88,7 +88,7 @@ async def test_form_invalid_auth(hass: HomeAssistant, side_effect, error) -> Non ) with patch( - "homeassistant.components.openai_conversation.config_flow.openai.Engine.list", + "homeassistant.components.openai_conversation.config_flow.openai.Model.list", side_effect=side_effect, ): result2 = await hass.config_entries.flow.async_configure( diff --git a/tests/components/openai_conversation/test_init.py b/tests/components/openai_conversation/test_init.py index 1b145d9d545..61fe33e5469 100644 --- a/tests/components/openai_conversation/test_init.py +++ b/tests/components/openai_conversation/test_init.py @@ -140,7 +140,7 @@ async def test_template_error( }, ) with patch( - "openai.Engine.list", + "openai.Model.list", ), patch("openai.ChatCompletion.acreate"): await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done()