OnDemandTokenizer

An implementation of the PromptTokenizer interface that delegates token counting to an instance of the Tokenizer interface. The class provides methods to estimate the token count for individual messages and for the entirety of a prompt.

This is useful in contexts where token-based costs or limitations are significant, such as when interacting with large language models (LLMs).

Constructors

Link copied to clipboard
constructor(tokenizer: Tokenizer)

Functions

Link copied to clipboard
open override fun tokenCountFor(prompt: Prompt): Int

Calculates the total number of tokens spent for the given prompt based on its messages.

open override fun tokenCountFor(message: Message): Int

Computes the number of tokens in a given message.