Counter
counter
Token counting with tiktoken.
CounterBackend
Bases: StrEnum
Backend used to produce a token count.
Currently only :attr:TIKTOKEN exists; the enum is retained as the seam
for a future HuggingFace/SentencePiece backend (Llama/Mistral/Gemma).
Source code in packages/axm-smelt/src/axm_smelt/core/counter.py
count(text, model='o200k_base')
Return the token count for text.
Uses tiktoken with model encoding; a claude* or unknown model is
routed to the o200k_base proxy.
Source code in packages/axm-smelt/src/axm_smelt/core/counter.py
count_with_backend(text, model='o200k_base')
Return (token_count, backend) for text.
Always counts with tiktoken (backend :attr:CounterBackend.TIKTOKEN):
a claude* or otherwise unknown model is routed to the o200k_base
proxy encoding rather than a len // 4 approximation.