tokenwindow

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package tokenwindow preserves source text when vocabulary tokens split UTF-8.

Index

Constants

This section is empty.

Variables

View Source
var ErrSearchBudgetExceeded = errors.New("tokenwindow: search budget exceeded")

ErrSearchBudgetExceeded means the search stopped without proving absence.

Functions

func Prefix

func Prefix(ctx context.Context, codec tokenizer.Tokenizer, source string, limit, maxWork int, render func(string) string) (string, error)

Prefix returns a lossless source prefix whose rendered text fits limit tokens. Probe and final rendering are encoded independently because vocabulary boundaries can change after trimming or adding structural context, and token counts need not be monotonic. Token-prefix decoding only selects a candidate; when it finds none, every source rune boundary is checked by independent encoding. An empty result proves that no nonempty rendered prefix fits. maxWork bounds input bytes passed to render and Encode plus tokens passed to Decode; each operation costs at least one unit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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