ITokenizerService
Wisej.AI.Services.ITokenizerService
Last updated
Wisej.AI.Services.ITokenizerService
Last updated
Namespace: Wisej.AI.Services
Assembly: Wisej.AI (3.5.0.0)
Represents a service for tokenizing text, counting tokens, and truncating content based on token limits.
The interface provides methods to handle text tokenization operations such as:
Counting the number of tokens in a given text.
Converting text into tokens.
Truncating text to ensure it does not exceed a specified number of tokens. These operations can be customized using a different encoder if specified.
Counts the number of tokens in the specified text, optionally using a specified encoder.
text
The text to be tokenized and counted.
The optional name of the encoder used for tokenization. If not specified, a default encoder is used.
Returns: . The total count of tokens in the specified text.
This method provides a way to determine the length of a text in terms of tokens, which can be useful for operations that have token limits. The method can utilize different models to tokenize the text, which may affect the token count. Example usage:
Throws:
Tokenizes the specified text into an array of tokens, optionally using a specified encoder.
text
The text to be tokenized.
The optional name of the encoder used for tokenization. If not specified, a default encoder is used.
This method splits the text into discrete tokens, which can be useful for various text processing tasks. Different tokenization models can produce different token arrays from the same text. Example usage:
Throws:
Truncates the specified text to ensure it does not exceed a given number of tokens, optionally using a specified encoder.
text
The text to be truncated based on token count.
maxTokens
The maximum number of tokens allowed for the text.
The optional name of the encoder used for tokenization. If not specified, a default encoder is used.
This method is useful for ensuring that the text does not exceed a certain token limit, which can be important in contexts where token usage is limited or costly. The truncation respects token boundaries. Example usage:
Throws:
Provides services for tokenizing text, including counting tokens, tokenizing, and truncating content based on a token limit.
encoder
Thrown when text is null.
encoder
Returns: . An array of tokens derived from the specified text.
Thrown when text is null.
encoder
Returns: . The truncated text that is within the specified token limit.
Thrown when text is null.
Thrown when maxTokens is less than zero.