Package com.axelor.ai.chat.plugin
Class TokenEstimator
java.lang.Object
com.axelor.ai.chat.plugin.TokenEstimator
Estimates token counts for
UIMessage lists using provider-specific tokenizers when
available, falling back to a character-based heuristic for providers without public tokenizers.-
Method Summary
Modifier and TypeMethodDescriptionstatic intcountMessageTokens(UIMessage msg, dev.langchain4j.model.TokenCountEstimator estimator) Counts tokens for a single message by extracting all text content from its parts.static intcountTokens(List<UIMessage> messages, dev.langchain4j.model.TokenCountEstimator estimator) Counts the total tokens across all messages.static dev.langchain4j.model.TokenCountEstimatorReturns aTokenCountEstimatorappropriate for the given model's provider.
-
Method Details
-
forModel
Returns aTokenCountEstimatorappropriate for the given model's provider. -
countTokens
public static int countTokens(List<UIMessage> messages, dev.langchain4j.model.TokenCountEstimator estimator) Counts the total tokens across all messages. -
countMessageTokens
public static int countMessageTokens(UIMessage msg, dev.langchain4j.model.TokenCountEstimator estimator) Counts tokens for a single message by extracting all text content from its parts.
-