count_tokens
Class info¶
🛈 DocStrings¶
Token counting utilities with fallback strategies.
batch_count_tokens
¶
Count tokens for multiple texts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
Sequence[str]
|
Sequence of texts to count |
required |
model
|
str | None
|
Optional model name for tiktoken |
None
|
Returns:
Type | Description |
---|---|
list[int]
|
List of token counts |
Source code in src/llmling_agent/utils/count_tokens.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
count_tokens
¶
Count tokens in text with fallback strategy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
Text to count tokens for |
required |
model
|
str | None
|
Optional model name for tiktoken (ignored in fallback) |
None
|
Returns:
Type | Description |
---|---|
int
|
Estimated token count |
Source code in src/llmling_agent/utils/count_tokens.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|