Skip to main content

Module analyzer

Module analyzer 

Source
Expand description

Analyzer Engine

This module provides real-time analysis capabilities for LLM optimization metrics. It includes 5 specialized analyzers:

  • Performance Analyzer: Latency, throughput, token usage, performance degradation
  • Cost Analyzer: Token costs, budget utilization, cost optimization opportunities
  • Quality Analyzer: Response quality, error rates, SLA compliance
  • Pattern Analyzer: Temporal patterns, traffic bursts, seasonality, trends
  • Anomaly Analyzer: Statistical anomaly detection using Z-score and IQR methods

§Example

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

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create and start an analyzer
    let mut analyzer = PerformanceAnalyzer::with_defaults();
    analyzer.start().await?;

    // Process an 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 a report
    let report = analyzer.generate_report().await?;
    println!("Insights: {}", report.insights.len());
    println!("Recommendations: {}", report.recommendations.len());

    Ok(())
}

Re-exports§

pub use traits::Analyzer;
pub use traits::AnalyzerConfig;
pub use traits::AnalyzerConfigBuilder;
pub use traits::AnalyzerError;
pub use traits::AnalyzerResult;
pub use traits::AnalyzerState;
pub use types::Action;
pub use types::ActionType;
pub use types::Alert;
pub use types::AlertStatus;
pub use types::AnalysisReport;
pub use types::AnalyzerEvent;
pub use types::AnalyzerStats;
pub use types::Confidence;
pub use types::Evidence;
pub use types::EvidenceType;
pub use types::FeedbackType;
pub use types::Impact;
pub use types::ImpactMetric;
pub use types::Insight;
pub use types::InsightCategory;
pub use types::Priority;
pub use types::Recommendation;
pub use types::ReportSummary;
pub use types::RiskLevel;
pub use types::Severity;
pub use types::Threshold;
pub use types::ThresholdOperator;
pub use performance_analyzer::PerformanceAnalyzer;
pub use performance_analyzer::PerformanceAnalyzerConfig;
pub use cost_analyzer::CostAnalyzer;
pub use cost_analyzer::CostAnalyzerConfig;
pub use cost_analyzer::ModelPricing;
pub use quality_analyzer::QualityAnalyzer;
pub use quality_analyzer::QualityAnalyzerConfig;
pub use pattern_analyzer::PatternAnalyzer;
pub use pattern_analyzer::PatternAnalyzerConfig;
pub use pattern_analyzer::PatternType;
pub use anomaly_analyzer::AnomalyAnalyzer;
pub use anomaly_analyzer::AnomalyAnalyzerConfig;
pub use anomaly_analyzer::AnomalyType;
pub use stats::calculate_linear_trend;
pub use stats::calculate_percentiles;
pub use stats::is_outlier_iqr;
pub use stats::is_outlier_zscore;
pub use stats::mean;
pub use stats::percentage_change;
pub use stats::std_dev;
pub use stats::z_score;
pub use stats::CircularBuffer;
pub use stats::ExponentialMovingAverage;
pub use stats::LinearTrend;
pub use stats::SimpleMovingAverage;

Modules§

anomaly_analyzer
Anomaly Analyzer
cost_analyzer
Cost Analyzer
pattern_analyzer
Pattern Analyzer
performance_analyzer
Performance Analyzer
quality_analyzer
Quality Analyzer
stats
Statistical utilities for analyzers
traits
Core traits for the analyzer framework
types
Type definitions for the analyzer framework