From ca3ae982b08db4d9db19e60f0f685e370eeec204 Mon Sep 17 00:00:00 2001 From: SMKRV Date: Fri, 6 Dec 2024 03:14:52 +0300 Subject: [PATCH] feat(performance): Optimize system resources and token estimation - Improve JSON history file processing - Add memory and disk space validation - Enhance parallel request handling - Refine token counting heuristics --- custom_components/ha_text_ai/coordinator.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/custom_components/ha_text_ai/coordinator.py b/custom_components/ha_text_ai/coordinator.py index 8751fec..5251014 100644 --- a/custom_components/ha_text_ai/coordinator.py +++ b/custom_components/ha_text_ai/coordinator.py @@ -865,8 +865,7 @@ class HATextAICoordinator(DataUpdateCoordinator): context_tokens = self._calculate_context_tokens( [{"content": entry["question"]} for entry in context_history] + [{"content": entry["response"]} for entry in context_history] + - [{"content": question}], - temp_model + [{"content": question}] ) # Dynamic token allocation @@ -886,8 +885,7 @@ class HATextAICoordinator(DataUpdateCoordinator): context_tokens = self._calculate_context_tokens( [{"content": entry["question"]} for entry in context_history] + [{"content": entry["response"]} for entry in context_history] + - [{"content": question}], - temp_model + [{"content": question}] ) # Rebuild messages with trimmed context