Help us shape the future of Go! Take the 2026 Go Developer Survey

tokenizer

package
v1.46.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package tokenizer adapts embedded text encodings for local CLI token inspection.

Index

Constants

View Source
const DefaultEncoding = "o200k_base"

DefaultEncoding is the encoding used when the caller makes no selection.

View Source
const MaxInputBytes = 1 << 20

MaxInputBytes bounds this local utility's input and result allocations. It does not limit API requests or guarantee short execution for unbroken text.

Variables

View Source
var Licenses string

Licenses retains the tokenizer dependencies' distribution notices in the binary.

Functions

func IsSupportedEncoding

func IsSupportedEncoding(name string) bool

IsSupportedEncoding checks an exact encoding name without loading vocabulary data.

func SupportedEncodings

func SupportedEncodings() []string

SupportedEncodings returns exact encoding names in presentation order.

Types

type Result

type Result struct {
	Encoding   string
	InputBytes int
	TokenCount int
	IDs        []uint
	Fragments  []string
}

Result preserves the encoding's exact token IDs and byte fragments when inspected. A fragment can contain only part of a UTF-8 character.

func Encode

func Encode(text, encoding string, inspect bool) (Result, error)

Encode treats special-token markers as ordinary text and preserves input bytes. It does not normalize Unicode, strip a BOM, or modify whitespace. Calls are synchronous. The dependency does not expose context cancellation.

Jump to

Keyboard shortcuts

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