tokens

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: GPL-3.0 Imports: 0 Imported by: 0 modules, 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

Overview

Package tokens carries the shared token-count heuristic used by every provider's EstimateTokens implementation plus the internal/diff and internal/compress consumers. The chars/4 approximation is intentionally crude — it's an upper-bound estimate good enough for the cost preflight and context-window gate. Per-provider exact tokenizers would supersede it when they're cheap to call from outside the provider's process.

Why a dedicated leaf package: keeping the heuristic in one place prevents drift between providers. The package is import-cycle safe (depends on nothing) so any package can pull it in without dragging the diff/compress trees along.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Estimate

func Estimate(s string) int

Estimate returns a rough token count using the chars/4 heuristic. `(len(s) + 3) / 4` rounds up so empty input gets 0 and short strings get at least 1 token.

Types

This section is empty.

Jump to

Keyboard shortcuts

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