synaptic_eval/
evaluator.rs1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3use synaptic_core::SynapticError;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct EvalResult {
8 pub score: f64,
10 pub passed: bool,
12 pub reasoning: Option<String>,
14}
15
16impl EvalResult {
17 pub fn pass() -> Self {
19 Self {
20 score: 1.0,
21 passed: true,
22 reasoning: None,
23 }
24 }
25
26 pub fn fail() -> Self {
28 Self {
29 score: 0.0,
30 passed: false,
31 reasoning: None,
32 }
33 }
34
35 pub fn with_score(score: f64) -> Self {
37 Self {
38 score,
39 passed: score >= 0.5,
40 reasoning: None,
41 }
42 }
43
44 pub fn with_reasoning(mut self, reasoning: impl Into<String>) -> Self {
46 self.reasoning = Some(reasoning.into());
47 self
48 }
49}
50
51#[async_trait]
53pub trait Evaluator: Send + Sync {
54 async fn evaluate(
56 &self,
57 prediction: &str,
58 reference: &str,
59 input: &str,
60 ) -> Result<EvalResult, SynapticError>;
61}