use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use synaptic_core::SynapticError;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EvalResult {
pub score: f64,
pub passed: bool,
pub reasoning: Option<String>,
}
impl EvalResult {
pub fn pass() -> Self {
Self {
score: 1.0,
passed: true,
reasoning: None,
}
}
pub fn fail() -> Self {
Self {
score: 0.0,
passed: false,
reasoning: None,
}
}
pub fn with_score(score: f64) -> Self {
Self {
score,
passed: score >= 0.5,
reasoning: None,
}
}
pub fn with_reasoning(mut self, reasoning: impl Into<String>) -> Self {
self.reasoning = Some(reasoning.into());
self
}
}
#[async_trait]
pub trait Evaluator: Send + Sync {
async fn evaluate(
&self,
prediction: &str,
reference: &str,
input: &str,
) -> Result<EvalResult, SynapticError>;
}