mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-28 10:04:00 +08:00
Release v2.0.0
This commit is contained in:
@@ -49,7 +49,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self._validate_params(api_key, temperature, max_tokens)
|
self._validate_params(api_key, temperature, max_tokens)
|
||||||
|
self._entity_id = None
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.endpoint = endpoint
|
self.endpoint = endpoint
|
||||||
self.model = model
|
self.model = model
|
||||||
@@ -211,6 +211,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
|
|
||||||
# Fire event for successful response
|
# Fire event for successful response
|
||||||
self.hass.bus.async_fire(f"{DOMAIN}_response_received", {
|
self.hass.bus.async_fire(f"{DOMAIN}_response_received", {
|
||||||
|
"entity_id": self._entity_id,
|
||||||
"question": question,
|
"question": question,
|
||||||
"model": response_data["model"],
|
"model": response_data["model"],
|
||||||
"tokens": response_data.get("tokens", 0)
|
"tokens": response_data.get("tokens", 0)
|
||||||
@@ -254,8 +255,9 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
|
|
||||||
# Fire error event
|
# Fire error event
|
||||||
self.hass.bus.async_fire(f"{DOMAIN}_error_occurred", {
|
self.hass.bus.async_fire(f"{DOMAIN}_error_occurred", {
|
||||||
|
"entity_id": self._entity_id,
|
||||||
"error_type": type(error).__name__,
|
"error_type": type(error).__name__,
|
||||||
"error_message": error_msg,
|
"error_message": str(error),
|
||||||
"question": question
|
"question": question
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -500,6 +502,16 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
self._performance_metrics["total_requests"] = self._request_count
|
self._performance_metrics["total_requests"] = self._request_count
|
||||||
self._performance_metrics["total_tokens"] = self._tokens_used
|
self._performance_metrics["total_tokens"] = self._tokens_used
|
||||||
|
|
||||||
|
@property
|
||||||
|
def entity_id(self) -> Optional[str]:
|
||||||
|
"""Get entity ID."""
|
||||||
|
return self._entity_id
|
||||||
|
|
||||||
|
@entity_id.setter
|
||||||
|
def entity_id(self, value: str) -> None:
|
||||||
|
"""Set entity ID."""
|
||||||
|
self._entity_id = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def performance_metrics(self) -> Dict[str, Any]:
|
def performance_metrics(self) -> Dict[str, Any]:
|
||||||
"""Return current performance metrics."""
|
"""Return current performance metrics."""
|
||||||
@@ -668,6 +680,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
def export_metrics(self) -> Dict[str, Any]:
|
def export_metrics(self) -> Dict[str, Any]:
|
||||||
"""Export all metrics and statistics."""
|
"""Export all metrics and statistics."""
|
||||||
return {
|
return {
|
||||||
|
"entity_id": self._entity_id,
|
||||||
"performance": self._performance_metrics,
|
"performance": self._performance_metrics,
|
||||||
"requests": {
|
"requests": {
|
||||||
"total": self._request_count,
|
"total": self._request_count,
|
||||||
|
|||||||
Reference in New Issue
Block a user