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 aHuggingFaceTokenCountEstimator
using a built-intokenizer.json
file.HuggingFaceTokenCountEstimator
(String pathToTokenizer) Creates an instance of aHuggingFaceTokenCountEstimator
using a providedtokenizer.json
file.HuggingFaceTokenCountEstimator
(String pathToTokenizer, Map<String, String> options) Creates an instance of aHuggingFaceTokenCountEstimator
using a providedtokenizer.json
file and a map of DJL's tokenizer options.HuggingFaceTokenCountEstimator
(Path pathToTokenizer) Creates an instance of aHuggingFaceTokenCountEstimator
using a providedtokenizer.json
file.HuggingFaceTokenCountEstimator
(Path pathToTokenizer, Map<String, String> options) Creates an instance of aHuggingFaceTokenCountEstimator
using a providedtokenizer.json
file and a map of DJL's tokenizer options. -
Method Summary
Modifier and TypeMethodDescriptionint
estimateTokenCountInMessage
(dev.langchain4j.data.message.ChatMessage message) int
estimateTokenCountInMessages
(Iterable<dev.langchain4j.data.message.ChatMessage> messages) int
-
Constructor Details
-
HuggingFaceTokenCountEstimator
public HuggingFaceTokenCountEstimator()Creates an instance of aHuggingFaceTokenCountEstimator
using a built-intokenizer.json
file. -
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimator
using a providedtokenizer.json
file.- Parameters:
pathToTokenizer
- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
-
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimator
using a providedtokenizer.json
file 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 aHuggingFaceTokenCountEstimator
using a providedtokenizer.json
file.- Parameters:
pathToTokenizer
- The path to the tokenizer file (e.g., "/path/to/tokenizer.json")
-
HuggingFaceTokenCountEstimator
Creates an instance of aHuggingFaceTokenCountEstimator
using a providedtokenizer.json
file 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:
estimateTokenCountInText
in interfacedev.langchain4j.model.TokenCountEstimator
-
estimateTokenCountInMessage
public int estimateTokenCountInMessage(dev.langchain4j.data.message.ChatMessage message) - Specified by:
estimateTokenCountInMessage
in interfacedev.langchain4j.model.TokenCountEstimator
-
estimateTokenCountInMessages
public int estimateTokenCountInMessages(Iterable<dev.langchain4j.data.message.ChatMessage> messages) - Specified by:
estimateTokenCountInMessages
in interfacedev.langchain4j.model.TokenCountEstimator
-