rs_adk/evaluation/
eval_result.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct PerInvocationResult {
8 pub invocation_id: String,
10 pub score: f64,
12 #[serde(default)]
14 pub explanation: Option<String>,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct EvalMetric {
20 pub name: String,
22 pub score: f64,
24 pub per_invocation: Vec<PerInvocationResult>,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct EvalResult {
31 pub overall_score: f64,
33 pub metrics: Vec<EvalMetric>,
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn eval_result_construction() {
43 let result = EvalResult {
44 overall_score: 0.85,
45 metrics: vec![EvalMetric {
46 name: "response_match".into(),
47 score: 0.85,
48 per_invocation: vec![PerInvocationResult {
49 invocation_id: "inv-1".into(),
50 score: 0.9,
51 explanation: Some("Good match".into()),
52 }],
53 }],
54 };
55 assert!((result.overall_score - 0.85).abs() < f64::EPSILON);
56 assert_eq!(result.metrics.len(), 1);
57 }
58
59 #[test]
60 fn eval_result_serde_roundtrip() {
61 let result = EvalResult {
62 overall_score: 0.75,
63 metrics: vec![],
64 };
65 let json = serde_json::to_string(&result).unwrap();
66 let deserialized: EvalResult = serde_json::from_str(&json).unwrap();
67 assert!((deserialized.overall_score - 0.75).abs() < f64::EPSILON);
68 }
69}