pub fn parse_number<T: FromStr>(response: &str) -> Result<T, ParseError>Expand description
Extract a numeric value from an LLM response.
Handles common patterns:
- Direct number:
"8.5" - Score format:
"8.5/10","8/10" - In prose:
"I'd rate it 8.5 out of 10" - Labeled:
"Score: 8.5","Rating: 8" - With think block:
"<think>considering...</think>8.5"
ยงExamples
use llm_output_parser::parse_number;
let score: f64 = parse_number("Score: 8.5").unwrap();
assert!((score - 8.5).abs() < f64::EPSILON);