Skip to main content

model_runtime/
predictions.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5/// Backend-neutral raw model prediction used for runtime conformance checks.
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
7pub struct RawPrediction {
8    /// Optional prediction kind.
9    pub kind: Option<String>,
10    /// Optional label.
11    pub label: Option<String>,
12    /// Optional text payload.
13    pub text: Option<String>,
14    /// Optional confidence score.
15    pub score: Option<f32>,
16    /// Arbitrary model attributes.
17    #[serde(default)]
18    pub attributes: BTreeMap<String, String>,
19}
20
21impl RawPrediction {
22    /// Creates a label prediction.
23    pub fn label(label: impl Into<String>, score: f32) -> Self {
24        Self {
25            label: Some(label.into()),
26            score: Some(score),
27            ..Self::default()
28        }
29    }
30}