Skip to main content

compact_reasoning_text

Function compact_reasoning_text 

Source
pub fn compact_reasoning_text(text: &str) -> String
Expand description

Compact reasoning text for on-screen display.

Unlike clean_reasoning_text, which removes all blank lines, this collapses runs of two or more blank/whitespace-only lines into a single blank line so paragraph structure is preserved while “blank-line spam” from the model is removed. Leading/trailing whitespace on every line is trimmed and leading/trailing blank lines of the whole block are dropped.

assert_eq!(compact_reasoning_text("line1\n\n\n\nline2\n"), "line1\n\nline2");
assert_eq!(compact_reasoning_text("  a  \n\n\n  b  \n"), "a\n\nb");
assert_eq!(compact_reasoning_text("\n\n\n"), "");
assert_eq!(compact_reasoning_text(""), "");