Package ai.platon.pulsar.coding
Object TokenEstimator
-
- All Implemented Interfaces:
public class TokenEstimatorHeuristic LLM token estimator for tool-call input/output text.
Zero dependencies. Approximates BPE tokenizers (cl100k/o200k class) within roughly ±25% for prose and source code — good enough for cost accounting and efficiency analysis, NOT for billing.
Model:
Identifiers are split at camelCase boundaries; each sub-word of length L costs ceil(L/5) tokens (English words average ~5 chars/sub-word).
Digit runs cost ceil(n/3) (BPE groups digits 1-3 per token).
Each CJK character costs 1 token.
Each symbol/punctuation character costs 1 token (slightly overestimates common merges like
::,->,==).Whitespace largely merges into neighboring tokens; counted as 1 per 8 chars.
-
-
Field Summary
Fields Modifier and Type Field Description public final static TokenEstimatorINSTANCE
-
Method Summary
Modifier and Type Method Description final LongestimateTokens(String text)Estimated token count of text; 0 for empty input. -
-
Method Detail
-
estimateTokens
final Long estimateTokens(String text)
Estimated token count of text; 0 for empty input.
-
-
-
-