Skip to main content

apply_input_cap

Function apply_input_cap 

Source
pub fn apply_input_cap(content: &mut String, max_tokens: usize)
Expand description

Truncate content in place using the max_tokens * 4 byte approximation.

Truncates at a valid UTF-8 char boundary via str::floor_char_boundary. Uses saturating_mul to avoid overflow on extreme token counts.

Pass config.max_compress_input_tokens as max_tokens before an LLM compress call, or config.max_embed_input_tokens before an embed call.