Skip to content

Commit

Permalink
[#217] resolve "blocking call" warning log.
Browse files Browse the repository at this point in the history
  • Loading branch information
jekalmin committed Oct 27, 2024
1 parent bc3565c commit f66a3fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions custom_components/extended_openai_conversation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
intent,
template,
)
from homeassistant.helpers.httpx_client import get_async_client
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import ulid

Expand Down Expand Up @@ -145,12 +146,14 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
azure_endpoint=base_url,
api_version=entry.data.get(CONF_API_VERSION),
organization=entry.data.get(CONF_ORGANIZATION),
http_client=get_async_client(hass),
)
else:
self.client = AsyncOpenAI(
api_key=entry.data[CONF_API_KEY],
base_url=base_url,
organization=entry.data.get(CONF_ORGANIZATION),
http_client=get_async_client(hass),
)

@property
Expand Down
7 changes: 6 additions & 1 deletion custom_components/extended_openai_conversation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from homeassistant.core import HomeAssistant, State
from homeassistant.exceptions import HomeAssistantError, ServiceNotFound
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.httpx_client import get_async_client
from homeassistant.helpers.script import Script
from homeassistant.helpers.template import Template
import homeassistant.util.dt as dt_util
Expand Down Expand Up @@ -141,10 +142,14 @@ async def validate_authentication(
azure_endpoint=base_url,
api_version=api_version,
organization=organization,
http_client=get_async_client(hass),
)
else:
client = AsyncOpenAI(
api_key=api_key, base_url=base_url, organization=organization
api_key=api_key,
base_url=base_url,
organization=organization,
http_client=get_async_client(hass),
)

await client.models.list(timeout=10)
Expand Down

0 comments on commit f66a3fc

Please sign in to comment.