mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 21:29:58 -04:00
Remove HTTPX compatibility casts for openai client (#184751)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Config flow for LiteLLM integration."""
|
||||
|
||||
import logging
|
||||
from typing import Any, cast, override
|
||||
from typing import Any, override
|
||||
|
||||
from openai import AsyncOpenAI, AuthenticationError, OpenAIError, PermissionDeniedError
|
||||
import probatio
|
||||
@@ -68,8 +68,7 @@ async def _get_models(hass: HomeAssistant, url: str, api_key: str | None) -> lis
|
||||
client = AsyncOpenAI(
|
||||
base_url=url,
|
||||
api_key=api_key or PLACEHOLDER_API_KEY,
|
||||
# Legacy HTTPX clients are supported at runtime only.
|
||||
http_client=cast(Any, get_async_client(hass)),
|
||||
http_client=get_async_client(hass),
|
||||
)
|
||||
try:
|
||||
return [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Coordinator for the LiteLLM integration."""
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import Any, cast, override
|
||||
from typing import override
|
||||
|
||||
from openai import AsyncOpenAI, AuthenticationError, OpenAIError, PermissionDeniedError
|
||||
|
||||
@@ -40,8 +40,7 @@ class LiteLLMDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||
self.client = AsyncOpenAI(
|
||||
base_url=config_entry.data[CONF_URL],
|
||||
api_key=config_entry.data.get(CONF_API_KEY) or PLACEHOLDER_API_KEY,
|
||||
# Legacy HTTPX clients are supported at runtime only.
|
||||
http_client=cast(Any, get_async_client(hass)),
|
||||
http_client=get_async_client(hass),
|
||||
)
|
||||
|
||||
@override
|
||||
|
||||
@@ -62,8 +62,7 @@ async def async_create_client(
|
||||
client = openai.AsyncOpenAI(
|
||||
api_key=api_key,
|
||||
base_url=config_entry_data[CONF_BASE_URL],
|
||||
# Legacy HTTPX clients are supported at runtime only.
|
||||
http_client=cast(Any, get_async_client(hass)),
|
||||
http_client=get_async_client(hass),
|
||||
)
|
||||
# Cache current platform data which gets added to each request
|
||||
# (caching done by library)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"""The OpenRouter integration."""
|
||||
|
||||
from typing import Any, cast
|
||||
|
||||
from openai import AsyncOpenAI, AuthenticationError, OpenAIError
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@@ -22,8 +20,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OpenRouterConfigEntry) -
|
||||
client = AsyncOpenAI(
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
api_key=entry.data[CONF_API_KEY],
|
||||
# Legacy HTTPX clients are supported at runtime only.
|
||||
http_client=cast(Any, get_async_client(hass)),
|
||||
http_client=get_async_client(hass),
|
||||
)
|
||||
|
||||
# Cache current platform data which gets added to each request
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""The OpenAI Conversation integration."""
|
||||
|
||||
from types import MappingProxyType
|
||||
from typing import Any, cast
|
||||
|
||||
import openai
|
||||
|
||||
@@ -49,8 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OpenAIConfigEntry) -> bo
|
||||
"""Set up OpenAI Conversation from a config entry."""
|
||||
client = openai.AsyncOpenAI(
|
||||
api_key=entry.data[CONF_API_KEY],
|
||||
# Legacy HTTPX clients are supported at runtime only.
|
||||
http_client=cast(Any, get_async_client(hass)),
|
||||
http_client=get_async_client(hass),
|
||||
)
|
||||
|
||||
# Cache current platform data which gets added to each request
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from collections.abc import Mapping
|
||||
import json
|
||||
import logging
|
||||
from typing import Any, cast, override
|
||||
from typing import Any, override
|
||||
|
||||
import openai
|
||||
import probatio
|
||||
@@ -118,8 +118,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
|
||||
"""
|
||||
client = openai.AsyncOpenAI(
|
||||
api_key=data[CONF_API_KEY],
|
||||
# Legacy HTTPX clients are supported at runtime only.
|
||||
http_client=cast(Any, get_async_client(hass)),
|
||||
http_client=get_async_client(hass),
|
||||
)
|
||||
await client.models.list(timeout=10.0)
|
||||
|
||||
@@ -669,7 +668,7 @@ class OpenAISubentryFlowHandler(ConfigSubentryFlow):
|
||||
if zone_home is not None:
|
||||
client = openai.AsyncOpenAI(
|
||||
api_key=self._get_entry().data[CONF_API_KEY],
|
||||
http_client=cast(Any, get_async_client(self.hass)),
|
||||
http_client=get_async_client(self.hass),
|
||||
)
|
||||
location_schema = probatio.Schema(
|
||||
{
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"""The OVHcloud AI Endpoints integration."""
|
||||
|
||||
from typing import Any, cast
|
||||
|
||||
from openai import (
|
||||
AsyncOpenAI,
|
||||
AuthenticationError,
|
||||
@@ -29,8 +27,7 @@ def _create_client(hass: HomeAssistant, api_key: str) -> AsyncOpenAI:
|
||||
return AsyncOpenAI(
|
||||
base_url=BASE_URL,
|
||||
api_key=api_key,
|
||||
# Legacy HTTPX clients are supported at runtime only.
|
||||
http_client=cast(Any, get_async_client(hass)),
|
||||
http_client=get_async_client(hass),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user