org.llm4s.context.ConversationTokenCounter
See theConversationTokenCounter companion class
object ConversationTokenCounter
Factory methods for creating ConversationTokenCounter instances.
Provides model-aware counter creation that automatically selects the appropriate tokenizer based on the model name. Supports OpenAI, Anthropic, Azure, and Ollama models.
==Tokenizer Selection==
Different models use different tokenization schemes:
- '''GPT-4o, o1''': Uses
o200k_basetokenizer - '''GPT-4, GPT-3.5''': Uses
cl100k_basetokenizer - '''Claude models''': Uses
cl100k_baseapproximation (may differ 20-30%) - '''Ollama models''': Uses
cl100k_baseapproximation
Attributes
- Example
-
// Model-aware creation (recommended) val counter = ConversationTokenCounter.forModel("openai/gpt-4o") // Direct tokenizer selection val openAICounter = ConversationTokenCounter.openAI() val gpt4oCounter = ConversationTokenCounter.openAI_o200k() - Companion
- class
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
Members list
In this article