mirror of
https://github.com/usestrix/strix.git
synced 2026-09-11 22:51:18 +00:00
refactor(llm): rename _get_message_tokens to public API name
This commit is contained in:
parent
4f852e662f
commit
63035db042
2 changed files with 4 additions and 4 deletions
|
|
@ -10,7 +10,7 @@ from litellm.utils import supports_prompt_caching, supports_vision
|
|||
|
||||
from strix.config import Config
|
||||
from strix.llm.config import LLMConfig
|
||||
from strix.llm.memory_compressor import MemoryCompressor, _get_message_tokens
|
||||
from strix.llm.memory_compressor import MemoryCompressor, get_message_tokens
|
||||
from strix.llm.utils import (
|
||||
_truncate_to_first_function,
|
||||
fix_incomplete_tool_call,
|
||||
|
|
@ -211,7 +211,7 @@ class LLM:
|
|||
)
|
||||
|
||||
reserved_tokens = sum(
|
||||
_get_message_tokens(msg, self.config.litellm_model) for msg in messages
|
||||
get_message_tokens(msg, self.config.litellm_model) for msg in messages
|
||||
)
|
||||
compressed = list(
|
||||
self.memory_compressor.compress_history(conversation_history, reserved_tokens)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ def _count_tokens(text: str, model: str) -> int:
|
|||
return len(text) // 4 # Rough estimate
|
||||
|
||||
|
||||
def _get_message_tokens(msg: dict[str, Any], model: str) -> int:
|
||||
def get_message_tokens(msg: dict[str, Any], model: str) -> int:
|
||||
content = msg.get("content", "")
|
||||
if isinstance(content, str):
|
||||
return _count_tokens(content, model)
|
||||
|
|
@ -209,7 +209,7 @@ class MemoryCompressor:
|
|||
model_name: str = self.model_name # type: ignore[assignment]
|
||||
|
||||
total_tokens = reserved_tokens + sum(
|
||||
_get_message_tokens(msg, model_name) for msg in system_msgs + regular_msgs
|
||||
get_message_tokens(msg, model_name) for msg in system_msgs + regular_msgs
|
||||
)
|
||||
|
||||
if total_tokens <= MAX_TOTAL_TOKENS * 0.9:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue