token_count
Class info¶
🛈 DocStrings¶
Token counting utilities with multiple fallback strategies.
count_tokens
¶
Count total number of tokens in text(s) with fallback strategies.
Uses following fallback order: 1. tiktoken (if available) 2. transformers (if available) 3. rough approximation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | Sequence[str]
|
Single text or sequence of texts to count tokens for |
required |
model
|
str | None
|
Optional model name for tiktoken (ignored in fallbacks) |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Total token count for all provided text(s) |