CachingTokenizer
A caching implementation of the PromptTokenizer
interface that optimizes token counting by storing previously computed token counts for messages. This reduces redundant computations when the same message is processed multiple times.
Constructors
Functions
Link copied to clipboard
Clears all cached token counts from the internal cache.
Link copied to clipboard
Calculates the total number of tokens spent on the given prompt by summing the token usage of all messages associated with the prompt.
Retrieves the number of tokens contained in the content of the given message. This method utilizes caching to improve performance, storing previously computed token counts and reusing them for identical messages.