generated from coulomb/repo-seed
Copy markitect.llm module into standalone llm_connect package. All markitect.* imports replaced with llm_connect.* equivalents. LLMError base class inlined (no markitect.exceptions dependency). Verified: from llm_connect import create_adapter works. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
17 lines
467 B
Python
17 lines
467 B
Python
"""
|
|
Rough token estimation for backends that don't return usage data.
|
|
|
|
Uses the ~4 characters per token heuristic common across English LLM tokenizers.
|
|
"""
|
|
|
|
|
|
def estimate_tokens(text: str) -> int:
|
|
"""Estimate the number of tokens in *text*.
|
|
|
|
This is intentionally coarse — it is only used by the Claude Code CLI
|
|
adapter where real token counts are unavailable.
|
|
"""
|
|
if not text:
|
|
return 0
|
|
return max(1, len(text) // 4)
|