Skip to main content

Module quality_analyzer

Module quality_analyzer 

Source
Expand description

Quality Analyzer

Monitors response quality, error rates, SLA compliance, and user feedback.

§Features

  • Error Rate Tracking: Success/failure rates with thresholds
  • SLA Compliance: Latency-based SLA monitoring (P95, P99)
  • Feedback Analysis: User rating tracking and sentiment
  • Response Quality: Completeness, accuracy, relevance metrics
  • Quality Degradation: Detect declining quality trends

§Example

use processor::analyzer::{QualityAnalyzer, QualityAnalyzerConfig, Analyzer, AnalyzerEvent};
use chrono::Utc;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create analyzer with SLA targets
    let config = QualityAnalyzerConfig {
        sla_p95_ms: 1000.0,
        sla_p99_ms: 2000.0,
        min_success_rate_pct: 99.5,
        min_avg_rating: 4.0,
        ..Default::default()
    };

    let mut analyzer = QualityAnalyzer::new(config);
    analyzer.start().await?;

    // Process response event
    let event = AnalyzerEvent::Response {
        timestamp: Utc::now(),
        request_id: "req-123".to_string(),
        model: "gpt-4".to_string(),
        completion_tokens: 100,
        total_tokens: 200,
        latency_ms: 500,
        success: true,
        error: None,
        metadata: HashMap::new(),
    };

    analyzer.process_event(event).await?;

    // Generate quality report
    let report = analyzer.generate_report().await?;
    println!("Quality Insights: {}", report.insights.len());

    Ok(())
}

Structs§

QualityAnalyzer
Quality Analyzer implementation
QualityAnalyzerConfig
Configuration for the Quality Analyzer