use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PerInvocationResult {
pub invocation_id: String,
pub score: f64,
#[serde(default)]
pub explanation: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EvalMetric {
pub name: String,
pub score: f64,
pub per_invocation: Vec<PerInvocationResult>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EvalResult {
pub overall_score: f64,
pub metrics: Vec<EvalMetric>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn eval_result_construction() {
let result = EvalResult {
overall_score: 0.85,
metrics: vec![EvalMetric {
name: "response_match".into(),
score: 0.85,
per_invocation: vec![PerInvocationResult {
invocation_id: "inv-1".into(),
score: 0.9,
explanation: Some("Good match".into()),
}],
}],
};
assert!((result.overall_score - 0.85).abs() < f64::EPSILON);
assert_eq!(result.metrics.len(), 1);
}
#[test]
fn eval_result_serde_roundtrip() {
let result = EvalResult {
overall_score: 0.75,
metrics: vec![],
};
let json = serde_json::to_string(&result).unwrap();
let deserialized: EvalResult = serde_json::from_str(&json).unwrap();
assert!((deserialized.overall_score - 0.75).abs() < f64::EPSILON);
}
}