DefaultTokenizerService
Wisej.AI.Services.DefaultTokenizerService
Last updated
Wisej.AI.Services.DefaultTokenizerService
Last updated
Namespace: Wisej.AI.Services
Assembly: Wisej.AI (3.5.0.0)
Provides services for tokenizing text, including counting tokens, tokenizing, and truncating content based on a token limit.
Initializes a new instance of .
Counts the number of tokens in the specified text using an optional encoder.
text
The text to be tokenized.
The name of the encoder to use for tokenization. Defaults to "o200K_base".
Returns: . The number of tokens in the specified text.
This method uses a tokenizer to count the number of discrete tokens in the provided input text. It can optionally accept an encoder parameter that influences how the tokenization is performed. Example usage:
Tokenizes the specified text into an array of tokens using an optional encoder.
text
The text to be tokenized.
The name of the encoder to use for tokenization. Defaults to "o200K_base".
This method splits the input text into its constituent tokens, which can then be processed individually. The optional encoder parameter can alter the tokenization process. Example usage:
Truncates the specified text to a maximum number of tokens, using an optional encoder.
text
The text to be truncated.
maxTokens
The maximum number of tokens to retain in the truncated text.
An optional encoder name to use for tokenization. Defaults to "o200K_base".
This method reduces the length of the input text by truncating it to a specified number of tokens. This is useful for scenarios where the input text needs to fit within a token limit. Example usage:
Represents a service for tokenizing text, counting tokens, and truncating content based on token limits.
encoder
Thrown if text is null.
encoder
Returns: . An array of tokens extracted from the specified text.
Thrown if text is null.
encoder
Returns: . A string representing the truncated text based on the specified maximum tokens.
Thrown if text is null.
Thrown if maxTokens is less than zero.