Expand description
Local token counting (§6.3): tiktoken for gpt families, bundled/downloaded
HF tokenizers for the rest, char-estimate floor. Native-only behind
count-local except the estimate, which serves the edge build.
Structs§
- Count
Result - Tokenizer
Registry - Global tokenizer registry living on
AppState. - Vocab
Info - Listing entry for the admin surface.
Enums§
- Count
Error - Count
Method - Count
Warning - Load
Request Status - Vocab
Source - Where a vocab comes from.
Traits§
Functions§
- count
- Count tokens of a provider-native request body.
map= provider settingstokenizer_map(glob → vocab name). Never fails: worst case is the chars/2 estimate. - count_
detailed - Count with provenance and diagnostics. Unlike
count, malformed JSON is never indistinguishable from a genuinely empty request: it falls back to a conservative estimate over the raw body and records warnings. - count_
text - Count a single text buffer with the same local fallback Clove uses for Claude Web usage synthesis: cl100k when local tokenizers are enabled, otherwise the cross-target character estimate.
- harvest
- Harvest human-text from any provider-native request JSON: walks the value,
collecting strings under text-ish keys (
text,content,instructions, string-formsystem, gemini parts text) plus tool definitions serialized. Returns(texts, message_count)wheremessage_countis the length of the largestmessages/contents/inputarray found (0 if none). - is_
gpt_ family - Whether
modelbelongs to a gpt family with an exact local tiktoken vocabulary (drives the §17 counting-ladder source label). - try_
count - Strict counting for correctness-sensitive paths. This rejects malformed
JSON and, with
hf-registry, waits for store hydration/download instead of returning a result that changes after a background load. - try_
harvest - Fallible harvesting for callers that must distinguish malformed JSON from an intentionally empty request.
Type Aliases§
- Registry
Handle - What
countreceives as the registry: a real handle undercount-local, a unit on builds without it (edge) so call sites stay uniform.