Encodes text into tokens, decodes tokens back into text, and counts tokens, delegating to the first registered TokeniserService. It is registered in the root context and its methods are exported for use from GraalJS. The encoder names currently supported by the registered TikTokenService implementation are gpt2, r50k_base, p50k_base, p50k_edit and cl100k_base.

Group: Managers


Properties

PropertyReturnsDescription
tokeniserServicesList<TokeniserService>

Methods

encode(String encoder, String content)

Returns: List<Integer>

Encodes the given content using the specified encoder using the first available TokeniserService

ParameterDescription
encoderthe encoder to use
contentthe content to encode

decode(String encoder, Collection<Integer> tokens)

Returns: String

Decodes the given tokens back into text using the specified encoder and the first available TokeniserService. Returns null if no TokeniserService is registered.

ParameterDescription
encoderthe encoder that was used to produce the tokens
tokensthe tokens to decode

countTokens(String encoder, String content)

Returns: Integer

Counts the number of tokens the given content would encode to, using the specified encoder and the first available TokeniserService.

ParameterDescription
encoderthe encoder to use
contentthe content to count tokens for
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.