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
ConstructorsConstructorDescriptionCreates an instance of theAzureOpenAiTokenCountEstimatorfor a givenAzureOpenAiChatModelName.Creates an instance of theAzureOpenAiTokenCountEstimatorfor a givenAzureOpenAiEmbeddingModelName.Creates an instance of theAzureOpenAiTokenCountEstimatorfor a givenAzureOpenAiLanguageModelName.AzureOpenAiTokenCountEstimator(String modelName) Creates an instance of theAzureOpenAiTokenCountEstimatorfor a given model name. -
Method Summary
Modifier and TypeMethodDescriptionintestimateTokenCountInMessage(ChatMessage message) intestimateTokenCountInMessages(Iterable<ChatMessage> messages) int
-
Constructor Details
-
AzureOpenAiTokenCountEstimator
Creates an instance of theAzureOpenAiTokenCountEstimatorfor a givenAzureOpenAiChatModelName. -
AzureOpenAiTokenCountEstimator
Creates an instance of theAzureOpenAiTokenCountEstimatorfor a givenAzureOpenAiEmbeddingModelName. -
AzureOpenAiTokenCountEstimator
Creates an instance of theAzureOpenAiTokenCountEstimatorfor a givenAzureOpenAiLanguageModelName. -
AzureOpenAiTokenCountEstimator
Creates an instance of theAzureOpenAiTokenCountEstimatorfor a given model name.
-
-
Method Details
-
estimateTokenCountInText
- Specified by:
estimateTokenCountInTextin interfaceTokenCountEstimator
-
estimateTokenCountInMessage
- Specified by:
estimateTokenCountInMessagein interfaceTokenCountEstimator
-
estimateTokenCountInMessages
- Specified by:
estimateTokenCountInMessagesin interfaceTokenCountEstimator
-