Package dev.langchain4j.model.azure
Class AzureOpenAiTokenCountEstimator
java.lang.Object
dev.langchain4j.model.azure.AzureOpenAiTokenCountEstimator
- All Implemented Interfaces:
TokenCountEstimator
This class can be used to estimate the cost (in tokens) before calling OpenAI or when using streaming.
Magic numbers present in this class were found empirically while testing.
There are integration tests in place that are making sure that the calculations here are very close to that of OpenAI.
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Please use other constructors and specify the model name explicitly.Creates an instance of theAzureOpenAiTokenCountEstimator
for a givenAzureOpenAiChatModelName
.Creates an instance of theAzureOpenAiTokenCountEstimator
for a givenAzureOpenAiEmbeddingModelName
.Creates an instance of theAzureOpenAiTokenCountEstimator
for a givenAzureOpenAiLanguageModelName
.AzureOpenAiTokenCountEstimator
(String modelName) Creates an instance of theAzureOpenAiTokenCountEstimator
for a given model name. -
Method Summary
Modifier and TypeMethodDescriptionint
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.
-
Constructor Details
-
AzureOpenAiTokenCountEstimator
Deprecated, for removal: This API element is subject to removal in a future version.Please use other constructors and specify the model name explicitly.Creates an instance of theAzureOpenAiTokenCountEstimator
for the "gpt-3.5-turbo" model. -
AzureOpenAiTokenCountEstimator
Creates an instance of theAzureOpenAiTokenCountEstimator
for a givenAzureOpenAiChatModelName
. -
AzureOpenAiTokenCountEstimator
Creates an instance of theAzureOpenAiTokenCountEstimator
for a givenAzureOpenAiEmbeddingModelName
. -
AzureOpenAiTokenCountEstimator
Creates an instance of theAzureOpenAiTokenCountEstimator
for a givenAzureOpenAiLanguageModelName
. -
AzureOpenAiTokenCountEstimator
Creates an instance of theAzureOpenAiTokenCountEstimator
for a given model name.
-
-
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.
-
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.
-