pub fn truncate_to_token_limit(text: &str, max_tokens: usize) -> StringExpand description
Truncate text to at most max_tokens tokens.
Decodes the truncated token sequence back to text so the result is always valid UTF-8 with no mid-token corruption. If a token ends mid-character, earlier token boundaries are tried. Without BPE, uses the byte heuristic.