mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-29 00:53:52 +08:00
Release v2.0.0
This commit is contained in:
@@ -238,13 +238,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
"model": model,
|
"model": model,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Получаем интервал обновления
|
||||||
|
update_interval = entry.data.get(CONF_REQUEST_INTERVAL, DEFAULT_REQUEST_INTERVAL)
|
||||||
|
|
||||||
coordinator = HATextAICoordinator(
|
coordinator = HATextAICoordinator(
|
||||||
hass=hass,
|
hass=hass,
|
||||||
client=api_client,
|
client=api_client,
|
||||||
model=model,
|
model=model,
|
||||||
update_interval=timedelta(
|
update_interval=update_interval, # Передаем числовое значение
|
||||||
seconds=entry.data.get(CONF_REQUEST_INTERVAL, DEFAULT_REQUEST_INTERVAL)
|
|
||||||
),
|
|
||||||
instance_name=instance_name,
|
instance_name=instance_name,
|
||||||
max_tokens=entry.data.get(CONF_MAX_TOKENS, DEFAULT_MAX_TOKENS),
|
max_tokens=entry.data.get(CONF_MAX_TOKENS, DEFAULT_MAX_TOKENS),
|
||||||
temperature=entry.data.get(CONF_TEMPERATURE, DEFAULT_TEMPERATURE),
|
temperature=entry.data.get(CONF_TEMPERATURE, DEFAULT_TEMPERATURE),
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
client: Any,
|
client: Any,
|
||||||
model: str,
|
model: str,
|
||||||
update_interval: float,
|
update_interval: timedelta, # Изменен тип на timedelta
|
||||||
instance_name: str,
|
instance_name: str,
|
||||||
max_tokens: int = 1000,
|
max_tokens: int = 1000,
|
||||||
temperature: float = 0.7,
|
temperature: float = 0.7,
|
||||||
@@ -31,7 +31,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
name=f"HA Text AI {instance_name}",
|
name=f"HA Text AI {instance_name}",
|
||||||
update_interval=timedelta(seconds=update_interval),
|
update_interval=update_interval, # Передаем напрямую
|
||||||
)
|
)
|
||||||
|
|
||||||
self.instance_name = instance_name
|
self.instance_name = instance_name
|
||||||
@@ -139,7 +139,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
"total_requests": self._request_count,
|
"total_requests": self._request_count,
|
||||||
"total_errors": self._error_count,
|
"total_errors": self._error_count,
|
||||||
"last_request_time": dt_util.utcnow().isoformat(),
|
"last_request_time": dt_util.utcnow().isoformat(),
|
||||||
"instance": self.instance_name, # Добавляем идентификатор интеграции
|
"instance": self.instance_name,
|
||||||
})
|
})
|
||||||
|
|
||||||
async def async_process_message(self, message: str, **kwargs) -> dict:
|
async def async_process_message(self, message: str, **kwargs) -> dict:
|
||||||
@@ -190,7 +190,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
"question": message,
|
"question": message,
|
||||||
"response": response_text,
|
"response": response_text,
|
||||||
"model": model,
|
"model": model,
|
||||||
"instance": self.instance_name, # Добавляем идентификатор интеграции
|
"instance": self.instance_name,
|
||||||
"error": None
|
"error": None
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
"timestamp": dt_util.utcnow().isoformat(),
|
"timestamp": dt_util.utcnow().isoformat(),
|
||||||
"question": message,
|
"question": message,
|
||||||
"response": None,
|
"response": None,
|
||||||
"instance": self.instance_name, # Добавляем идентификатор интеграции
|
"instance": self.instance_name,
|
||||||
"error": str(err)
|
"error": str(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,13 +237,13 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
self,
|
self,
|
||||||
limit: Optional[int] = None,
|
limit: Optional[int] = None,
|
||||||
filter_model: Optional[str] = None,
|
filter_model: Optional[str] = None,
|
||||||
instance: Optional[str] = None # Добавляем фильтр по интеграции
|
instance: Optional[str] = None
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
"""Get conversation history with optional filtering."""
|
"""Get conversation history with optional filtering."""
|
||||||
history = self._history.copy()
|
history = self._history.copy()
|
||||||
|
|
||||||
if instance and instance != self.instance_name:
|
if instance and instance != self.instance_name:
|
||||||
return [] # Возвращаем пустой список для чужих интеграций
|
return []
|
||||||
|
|
||||||
if filter_model:
|
if filter_model:
|
||||||
history = [h for h in history if h.get("model") == filter_model]
|
history = [h for h in history if h.get("model") == filter_model]
|
||||||
@@ -262,7 +262,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
"total_errors": 0,
|
"total_errors": 0,
|
||||||
"avg_response_time": 0.0,
|
"avg_response_time": 0.0,
|
||||||
"last_request_time": None,
|
"last_request_time": None,
|
||||||
"instance": self.instance_name, # Добавляем идентификатор интеграции
|
"instance": self.instance_name,
|
||||||
}
|
}
|
||||||
_LOGGER.debug("[%s] Metrics reset", self.instance_name)
|
_LOGGER.debug("[%s] Metrics reset", self.instance_name)
|
||||||
self.async_update_listeners()
|
self.async_update_listeners()
|
||||||
|
|||||||
Reference in New Issue
Block a user