mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-22 07:03:58 +08:00
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
This commit is contained in:
@@ -865,8 +865,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
context_tokens = self._calculate_context_tokens(
|
context_tokens = self._calculate_context_tokens(
|
||||||
[{"content": entry["question"]} for entry in context_history] +
|
[{"content": entry["question"]} for entry in context_history] +
|
||||||
[{"content": entry["response"]} for entry in context_history] +
|
[{"content": entry["response"]} for entry in context_history] +
|
||||||
[{"content": question}],
|
[{"content": question}]
|
||||||
temp_model
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Dynamic token allocation
|
# Dynamic token allocation
|
||||||
@@ -886,8 +885,7 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
|||||||
context_tokens = self._calculate_context_tokens(
|
context_tokens = self._calculate_context_tokens(
|
||||||
[{"content": entry["question"]} for entry in context_history] +
|
[{"content": entry["question"]} for entry in context_history] +
|
||||||
[{"content": entry["response"]} for entry in context_history] +
|
[{"content": entry["response"]} for entry in context_history] +
|
||||||
[{"content": question}],
|
[{"content": question}]
|
||||||
temp_model
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Rebuild messages with trimmed context
|
# Rebuild messages with trimmed context
|
||||||
|
|||||||
Reference in New Issue
Block a user