1use rskit_errors::AppResult;
7use serde::{Deserialize, Serialize};
8use std::collections::HashMap;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct BenchSample<L = String> {
15 pub id: String,
17 #[serde(skip)]
19 pub input: Vec<u8>,
20 pub label: L,
22 #[serde(default)]
24 pub source: String,
25 #[serde(default)]
27 pub metadata: HashMap<String, serde_json::Value>,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct Prediction<L = String> {
33 #[serde(default)]
35 pub sample_id: String,
36 pub label: L,
38 pub score: f64,
40 #[serde(default)]
42 pub scores: HashMap<String, f64>,
43 #[serde(default)]
45 pub metadata: HashMap<String, serde_json::Value>,
46}
47
48#[derive(Debug, Clone)]
50pub struct ScoredSample<L = String> {
51 pub sample: BenchSample<L>,
52 pub prediction: Prediction<L>,
53}
54
55pub type LabelMapper<L> = Box<dyn Fn(&str) -> AppResult<L> + Send + Sync>;
57
58pub fn string_label_mapper() -> LabelMapper<String> {
60 Box::new(|s| Ok(s.to_string()))
61}
62
63impl<L: Default> Default for Prediction<L> {
64 fn default() -> Self {
65 Self {
66 sample_id: String::default(),
67 label: L::default(),
68 score: 0.0,
69 scores: HashMap::new(),
70 metadata: HashMap::new(),
71 }
72 }
73}