OpenAITokenizers

org.llm4s.llmconnect.provider.OpenAITokenizers
@Stable

Which tokenizer vocabulary an OpenAI model uses, so its tokens can be counted exactly without a call to the API.

val counter = OpenAITokenizers.counterFor("gpt-4o")   // o200k_base

The name may carry the openai/ or azure/ prefix. An Azure deployment is matched on the OpenAI model name its text contains, spelled as OpenAI spells it: azure/my-gpt-4o-deployment is o200k_base, while a deployment whose name does not contain a model name is not recognised.

Models of other vendors have no public tokenizer here. Count them with ConversationTokenCounter.cl100k(), an approximation that can be 20-30% off, or with your own StringTokenizer through ConversationTokenCounter.of.

Attributes

Source
OpenAITokenizers.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

A token counter over the vocabulary of an OpenAI model, or a TokenizerError when model is not recognised as one (see tokenizerFor).

A token counter over the vocabulary of an OpenAI model, or a TokenizerError when model is not recognised as one (see tokenizerFor).

Attributes

Source
OpenAITokenizers.scala

The vocabulary of an OpenAI model, or None when model is not recognised as one: a name under another provider's prefix, or one that contains no OpenAI model name.

The vocabulary of an OpenAI model, or None when model is not recognised as one: a name under another provider's prefix, or one that contains no OpenAI model name.

Attributes

Source
OpenAITokenizers.scala