tokens

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 0 Imported by: 0

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