This commit is contained in:
SMKRV
2024-11-19 16:25:44 +03:00
parent 30aa894634
commit 42324a793b
+23 -8
View File
@@ -7,12 +7,27 @@ from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import aiohttp_client from homeassistant.helpers import aiohttp_client
from homeassistant.helpers import config_validation as cv
from .const import DOMAIN, PLATFORMS from .const import (
from .coordinator import HATextAICoordinator DOMAIN,
PLATFORMS,
CONF_MODEL,
CONF_TEMPERATURE,
CONF_MAX_TOKENS,
CONF_API_ENDPOINT,
CONF_REQUEST_INTERVAL,
DEFAULT_MODEL,
DEFAULT_TEMPERATURE,
DEFAULT_MAX_TOKENS,
DEFAULT_API_ENDPOINT,
DEFAULT_REQUEST_INTERVAL,
)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool: async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool:
"""Set up the HA Text AI component.""" """Set up the HA Text AI component."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
@@ -26,11 +41,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
coordinator = HATextAICoordinator( coordinator = HATextAICoordinator(
hass, hass,
api_key=entry.data[CONF_API_KEY], api_key=entry.data[CONF_API_KEY],
endpoint=entry.data.get("api_endpoint", "https://api.openai.com/v1"), endpoint=entry.data.get(CONF_API_ENDPOINT, DEFAULT_API_ENDPOINT),
model=entry.data.get("model", "gpt-3.5-turbo"), model=entry.data.get(CONF_MODEL, DEFAULT_MODEL),
temperature=entry.data.get("temperature", 0.7), temperature=entry.data.get(CONF_TEMPERATURE, DEFAULT_TEMPERATURE),
max_tokens=entry.data.get("max_tokens", 1000), max_tokens=entry.data.get(CONF_MAX_TOKENS, DEFAULT_MAX_TOKENS),
request_interval=entry.data.get("request_interval", 1.0), request_interval=entry.data.get(CONF_REQUEST_INTERVAL, DEFAULT_REQUEST_INTERVAL),
session=session, session=session,
) )
@@ -54,7 +69,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
_LOGGER.info( _LOGGER.info(
"Successfully set up HA Text AI with model: %s", "Successfully set up HA Text AI with model: %s",
entry.data.get("model", "gpt-3.5-turbo") entry.data.get(CONF_MODEL, DEFAULT_MODEL)
) )
return True return True