Module response

Source
Expand description

Inference response parsing and conversion

This module provides functionality for parsing inference model responses and converting them into structured data according to type definitions. It handles both single-line and multi-line responses with various formatting patterns.

§Overview

The response parser processes text output from inference models and extracts structured key-value pairs according to AIM response format conventions. It supports:

  • Single-line responses with inline values
  • Multi-line list responses with common prefixes
  • Task status indicators (checkboxes)
  • Type-safe conversion to Value and Literal types

§Response Format

The parser expects responses in the following format:

KEY1: inline value
KEY2
- Checkbox item 1 [X]
- Checkbox item 2 [ ]
KEY3
1. Ordered item 1
2. Ordered item 2

§Examples

use aimx::{parse_response, inference::Response};
use aimx::typedef::Typedef;
 
let response_text = "ANSWER: 42";
if let Some(response_map) = parse_response(response_text) {
    let typedef = Typedef::Number;
    if let Some(response) = response_map.get("ANSWER") {
        match response.to_value(&typedef) {
            Ok(value) => println!("Parsed value: {:?}", value),
            Err(e) => eprintln!("Error: {}", e),
        }
    }
}

Enums§

Response
Represents a parsed inference response

Functions§

parse_response
Parse a formatted inference response and extract key/item data