Skip to main content

truncate_for_model

Function truncate_for_model 

Source
pub fn truncate_for_model(text: &str, budget: usize) -> (String, bool)
Expand description

Bound text to roughly budget bytes for model consumption, keeping the head and tail and eliding the middle (middle-truncation, Codex-style) with a byte-count marker in the seam.

Returns (text, was_truncated). Below budget the input is returned untouched with no marker (idempotent). UTF-8-safe: cuts fall on char boundaries.