Package org.springframework.ai.tokenizer
Class JTokkitTokenCountEstimator
java.lang.Object
org.springframework.ai.tokenizer.JTokkitTokenCountEstimator
- All Implemented Interfaces:
TokenCountEstimator
Estimates the number of tokens in a given text or message using the JTokkit encoding
library.
- Since:
- 1.0.0
- Author:
- Christian Tzolov, Soby Chacko
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new JTokkitTokenCountEstimator with default CL100K_BASE encoding.JTokkitTokenCountEstimator
(com.knuddels.jtokkit.api.EncodingType tokenEncodingType) Creates a new JTokkitTokenCountEstimator with the specified encoding type. -
Method Summary
Modifier and TypeMethodDescriptionint
estimate
(Iterable<MediaContent> contents) Estimates the number of tokens in the given messages.int
Estimates the number of tokens in the given text.int
estimate
(MediaContent content) Estimates the number of tokens in the given message.
-
Constructor Details
-
JTokkitTokenCountEstimator
public JTokkitTokenCountEstimator()Creates a new JTokkitTokenCountEstimator with default CL100K_BASE encoding. -
JTokkitTokenCountEstimator
public JTokkitTokenCountEstimator(com.knuddels.jtokkit.api.EncodingType tokenEncodingType) Creates a new JTokkitTokenCountEstimator with the specified encoding type.- Parameters:
tokenEncodingType
- the encoding type to use for token counting
-
-
Method Details
-
estimate
Description copied from interface:TokenCountEstimator
Estimates the number of tokens in the given text.- Specified by:
estimate
in interfaceTokenCountEstimator
- Parameters:
text
- the text to estimate the number of tokens for.- Returns:
- the estimated number of tokens.
-
estimate
Description copied from interface:TokenCountEstimator
Estimates the number of tokens in the given message.- Specified by:
estimate
in interfaceTokenCountEstimator
- Parameters:
content
- the content (Message or Document) to estimate the number of tokens for.- Returns:
- the estimated number of tokens.
-
estimate
Description copied from interface:TokenCountEstimator
Estimates the number of tokens in the given messages.- Specified by:
estimate
in interfaceTokenCountEstimator
- Parameters:
contents
- the messages to estimate the number of tokens for.- Returns:
- the estimated number of tokens.
-