tiktoken

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CL100kBlob = "https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken"
	CL100kHash = "223921b76ee99bde995b7ff738513eef100fb51d18c93597a113bcffe865b2a7"
)

CL100kBlob and CL100kHash locate and verify the cl100k_base rank file

Functions

func LoadRanks

func LoadRanks(blobpath, expectedHash string) (map[string]int, error)

LoadRanks reads the rank file at a path or url through the cache, checked against a sha256 when one is given

func ParseRanks

func ParseRanks(contents []byte) (map[string]int, error)

ParseRanks reads a rank file, one base64 token and its rank per line

func ReadFileCached

func ReadFileCached(blobpath, expectedHash string) ([]byte, error)

ReadFileCached returns a rank file through the TIKTOKEN_CACHE_DIR, DATA_GYM_CACHE_DIR or temp data-gym-cache copy, fetched again on a hash mismatch

Types

type Encoding

type Encoding struct {
	Name string
	// contains filtered or unexported fields
}

Encoding is a BPE vocabulary with its pre-tokenizer pattern and special tokens

func CL100kBase

func CL100kBase() (*Encoding, error)

CL100kBase returns the cl100k_base encoding, loaded once per process

func New

func New(name, pattern string, ranks map[string]int, special map[string]int) (*Encoding, error)

New builds an encoding from a split pattern in regexp2 syntax, mergeable ranks and special tokens

func (*Encoding) Encode

func (e *Encoding) Encode(text string) []int

Encode returns the tokens of text, each special token in it as its id between ordinary runs

func (*Encoding) EncodeOrdinary

func (e *Encoding) EncodeOrdinary(text string) []int

EncodeOrdinary returns the tokens of text with special tokens read as plain text

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL