mirror of
https://github.com/usestrix/strix.git
synced 2026-08-22 02:58:39 +02:00
fix(context): over-estimate tokens when no tokenizer is available
The chars/4 fallback under-counts dense text (code, base64, CJK), which could let a summary request be packed past the real context window and get rejected. Use a conservative ~3-chars/token estimate instead so budget checks never under-count.
This commit is contained in:
@@ -38,8 +38,10 @@ def test_count_tokens_fallback_on_error(monkeypatch: pytest.MonkeyPatch) -> None
|
||||
raise RuntimeError("no tokenizer")
|
||||
|
||||
monkeypatch.setattr("strix.llm.context_budget.litellm.token_counter", _raise)
|
||||
text = "x" * 400
|
||||
assert context_budget.count_tokens("weird-model", text) == 100
|
||||
# Conservative ~3-chars/token estimate, rounded up, so budgets never
|
||||
# under-count when no tokenizer is available.
|
||||
assert context_budget.count_tokens("weird-model", "x" * 400) == 134
|
||||
assert context_budget.count_tokens("weird-model", "x") == 1
|
||||
|
||||
|
||||
def test_count_tokens_empty_is_zero() -> None:
|
||||
|
||||
Reference in New Issue
Block a user