Class WatsonxTokenCountEstimator
java.lang.Object
dev.langchain4j.model.watsonx.WatsonxTokenCountEstimator
- All Implemented Interfaces:
dev.langchain4j.model.TokenCountEstimator
public class WatsonxTokenCountEstimator
extends Object
implements dev.langchain4j.model.TokenCountEstimator
A
TokenCountEstimator implementation that integrates IBM watsonx.ai with LangChain4j.
Example usage:
TokenCountEstimator tokenCountEstimator = WatsonxTokenCountEstimator.builder()
.url("https://...") // or use CloudRegion
.apiKey("...")
.projectId("...")
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for constructingWatsonxTokenCountEstimatorinstances with configurable parameters. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Returns a newWatsonxTokenCountEstimator.Builderinstance.intestimateTokenCountInMessage(dev.langchain4j.data.message.ChatMessage message) intestimateTokenCountInMessages(Iterable<dev.langchain4j.data.message.ChatMessage> messages) intintestimateTokenCountInText(String text, com.ibm.watsonx.ai.tokenization.TokenizationParameters parameters) Estimates the count of tokens in the given text using the specifiedTokenizationParameters.
-
Method Details
-
estimateTokenCountInText
- Specified by:
estimateTokenCountInTextin interfacedev.langchain4j.model.TokenCountEstimator
-
estimateTokenCountInText
public int estimateTokenCountInText(String text, com.ibm.watsonx.ai.tokenization.TokenizationParameters parameters) Estimates the count of tokens in the given text using the specifiedTokenizationParameters.- Parameters:
text- the text.parameters- the tokenization parameters to use.- Returns:
- the estimated count of tokens.
-
estimateTokenCountInMessage
public int estimateTokenCountInMessage(dev.langchain4j.data.message.ChatMessage message) - Specified by:
estimateTokenCountInMessagein interfacedev.langchain4j.model.TokenCountEstimator
-
estimateTokenCountInMessages
public int estimateTokenCountInMessages(Iterable<dev.langchain4j.data.message.ChatMessage> messages) - Specified by:
estimateTokenCountInMessagesin interfacedev.langchain4j.model.TokenCountEstimator
-
builder
Returns a newWatsonxTokenCountEstimator.Builderinstance.Example usage:
TokenCountEstimator tokenCountEstimator = WatsonxTokenCountEstimator.builder() .url("https://...") // or use CloudRegion .apiKey("...") .projectId("...") .build();
-