Class HuggingFaceTokenCountEstimator
java.lang.Object
dev.langchain4j.model.embedding.onnx.HuggingFaceTokenCountEstimator
- All Implemented Interfaces:
dev.langchain4j.model.TokenCountEstimator
public class HuggingFaceTokenCountEstimator
extends Object
implements dev.langchain4j.model.TokenCountEstimator
A token count estimator for models that can be found on HuggingFace.
Uses DJL's
Requires
Uses DJL's
HuggingFaceTokenizer under the hood.
Requires
tokenizer.json to instantiate.
An example.-
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance of aHuggingFaceTokenCountEstimatorusing a built-intokenizer.jsonfile.HuggingFaceTokenCountEstimator(String pathToTokenizer) Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile.HuggingFaceTokenCountEstimator(String pathToTokenizer, Map<String, String> options) Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile and a map of DJL's tokenizer options.HuggingFaceTokenCountEstimator(Path pathToTokenizer) Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile.HuggingFaceTokenCountEstimator(Path pathToTokenizer, Map<String, String> options) Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile and a map of DJL's tokenizer options. -
Method Summary
Modifier and TypeMethodDescriptionintestimateTokenCountInMessage(dev.langchain4j.data.message.ChatMessage message) intestimateTokenCountInMessages(Iterable<dev.langchain4j.data.message.ChatMessage> messages) int
-
Constructor Details
-
HuggingFaceTokenCountEstimator
public HuggingFaceTokenCountEstimator()Creates an instance of aHuggingFaceTokenCountEstimatorusing a built-intokenizer.jsonfile. -
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile.- Parameters:
pathToTokenizer- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
-
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile and a map of DJL's tokenizer options.- Parameters:
pathToTokenizer- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")options- The DJL's tokenizer options
-
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile.- Parameters:
pathToTokenizer- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
-
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimatorusing a providedtokenizer.jsonfile and a map of DJL's tokenizer options.- Parameters:
pathToTokenizer- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")options- The DJL's tokenizer options
-
-
Method Details
-
estimateTokenCountInText
- Specified by:
estimateTokenCountInTextin interfacedev.langchain4j.model.TokenCountEstimator
-
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
-