Package dev.langchain4j.model.watsonx
Class WatsonxTokenCountEstimator
java.lang.Object
dev.langchain4j.model.watsonx.WatsonxTokenCountEstimator
- All Implemented Interfaces:
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 class
Builder class for constructingWatsonxTokenCountEstimator
instances with configurable parameters. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Returns a newWatsonxTokenCountEstimator.Builder
instance.int
estimateTokenCountInMessage
(ChatMessage message) Estimates the count of tokens in the given message.int
estimateTokenCountInMessages
(Iterable<ChatMessage> messages) Estimates the count of tokens in the given messages.int
Estimates the count of tokens in the given text.int
estimateTokenCountInText
(String text, com.ibm.watsonx.ai.tokenization.TokenizationParameters parameters) Estimates the count of tokens in the given text using the specifiedTokenizationParameters
.
-
Method Details
-
estimateTokenCountInText
Description copied from interface:TokenCountEstimator
Estimates the count of tokens in the given text.- Specified by:
estimateTokenCountInText
in interfaceTokenCountEstimator
- Parameters:
text
- the text.- Returns:
- the estimated count of tokens.
-
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
Description copied from interface:TokenCountEstimator
Estimates the count of tokens in the given message.- Specified by:
estimateTokenCountInMessage
in interfaceTokenCountEstimator
- Parameters:
message
- the message.- Returns:
- the estimated count of tokens.
-
estimateTokenCountInMessages
Description copied from interface:TokenCountEstimator
Estimates the count of tokens in the given messages.- Specified by:
estimateTokenCountInMessages
in interfaceTokenCountEstimator
- Parameters:
messages
- the messages.- Returns:
- the estimated count of tokens.
-
builder
Returns a newWatsonxTokenCountEstimator.Builder
instance.Example usage:
TokenCountEstimator tokenCountEstimator = WatsonxTokenCountEstimator.builder() .url("https://...") // or use CloudRegion .apiKey("...") .projectId("...") .build();
-