Class TokenizerUtils
java.lang.Object
uno.anahata.asi.internal.TokenizerUtils
A centralized utility class for token counting, powered by the jtokkit
library. This provides a single, efficient, and reusable tokenizer instance
for the entire application.
- Author:
- anahata
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountTokens(String text, TokenizerType type) Counts the number of tokens in the given text using a specific tokenizer strategy.
-
Field Details
-
REGISTRY
private static final com.knuddels.jtokkit.api.EncodingRegistry REGISTRYTokkit default registry. -
TOKENIZER
private static final com.knuddels.jtokkit.api.Encoding TOKENIZERA robust, general-purpose tokenizer. CL100K_BASE is the encoding used by gpt-4, gpt-3.5-turbo, and text-embedding-ada-002. It serves as a high-quality default for token counting.
-
-
Constructor Details
-
TokenizerUtils
public TokenizerUtils()
-
-
Method Details
-
countTokens
Counts the number of tokens in the given text using a specific tokenizer strategy.- Parameters:
text- The text to count tokens for.type- The tokenizer strategy to use.- Returns:
- The number of tokens.
-

