pub struct DecisionOutput {
pub model: Option<DecisionModel>,
pub answers: BTreeMap<String, DecisionAnswer>,
pub usage: DecisionUsage,
}Expand description
The typed result of a decision: answers keyed by question name, plus usage.
§Examples
use ironflow_core::decision::{DecisionOutput, DecisionAnswer, NoulAnswer, DecisionUsage};
use std::collections::BTreeMap;
let output = DecisionOutput {
model: Some("jev-latest".into()),
answers: BTreeMap::from([
("is_urgent".to_string(), DecisionAnswer::Noul(NoulAnswer { noul: 0.92 })),
]),
usage: DecisionUsage::default(),
};
assert_eq!(output.noul("is_urgent").unwrap(), 0.92);Fields§
§model: Option<DecisionModel>Model that performed the evaluation, if the provider reported one.
answers: BTreeMap<String, DecisionAnswer>Answers keyed by the question names from the request.
usage: DecisionUsageToken usage.
Implementations§
Source§impl DecisionOutput
impl DecisionOutput
Sourcepub fn answer(&self, name: &str) -> Option<&DecisionAnswer>
pub fn answer(&self, name: &str) -> Option<&DecisionAnswer>
Look up an answer by name.
§Examples
use ironflow_core::decision::{DecisionOutput, DecisionAnswer, NoulAnswer, DecisionUsage};
use std::collections::BTreeMap;
let output = DecisionOutput {
model: None,
answers: BTreeMap::from([("q".to_string(), DecisionAnswer::Noul(NoulAnswer { noul: 0.1 }))]),
usage: DecisionUsage::default(),
};
assert!(output.answer("q").is_some());
assert!(output.answer("missing").is_none());Sourcepub fn noul(&self, name: &str) -> Result<f64, DecisionError>
pub fn noul(&self, name: &str) -> Result<f64, DecisionError>
The probability of a Noul answer.
§Errors
Returns DecisionError::NotFound if no answer has that name, or
DecisionError::TypeMismatch if the answer is not a noul.
§Examples
use ironflow_core::decision::{DecisionOutput, DecisionAnswer, NoulAnswer, DecisionUsage};
use std::collections::BTreeMap;
let output = DecisionOutput {
model: None,
answers: BTreeMap::from([("q".to_string(), DecisionAnswer::Noul(NoulAnswer { noul: 0.7 }))]),
usage: DecisionUsage::default(),
};
assert_eq!(output.noul("q").unwrap(), 0.7);Sourcepub fn choice(&self, name: &str) -> Result<&ChoiceAnswer, DecisionError>
pub fn choice(&self, name: &str) -> Result<&ChoiceAnswer, DecisionError>
The ChoiceAnswer for a choice question.
§Errors
Returns DecisionError::NotFound if no answer has that name, or
DecisionError::TypeMismatch if the answer is not a choice.
§Examples
use ironflow_core::decision::{DecisionOutput, DecisionAnswer, ChoiceAnswer, DecisionUsage};
use std::collections::BTreeMap;
let output = DecisionOutput {
model: None,
answers: BTreeMap::from([("dept".to_string(), DecisionAnswer::Choice(ChoiceAnswer {
choice: "billing".to_string(),
probabilities: BTreeMap::new(),
confidence: 0.9,
}))]),
usage: DecisionUsage::default(),
};
assert_eq!(output.choice("dept").unwrap().choice, "billing");Sourcepub fn score(&self, name: &str) -> Result<&ScoreAnswer, DecisionError>
pub fn score(&self, name: &str) -> Result<&ScoreAnswer, DecisionError>
The ScoreAnswer for a score question.
§Errors
Returns DecisionError::NotFound if no answer has that name, or
DecisionError::TypeMismatch if the answer is not a score.
§Examples
use ironflow_core::decision::{DecisionOutput, DecisionAnswer, ScoreAnswer, DecisionUsage};
use std::collections::BTreeMap;
let output = DecisionOutput {
model: None,
answers: BTreeMap::from([("mood".to_string(), DecisionAnswer::Score(ScoreAnswer {
score: 1.6,
legend: BTreeMap::new(),
probabilities: BTreeMap::new(),
confidence: 0.78,
}))]),
usage: DecisionUsage::default(),
};
assert!(output.score("mood").unwrap().score > 1.5);Sourcepub fn min_confidence(&self) -> Option<f64>
pub fn min_confidence(&self) -> Option<f64>
The lowest confidence across every answer, or None when there are no answers.
Used by the engine to decide escalation: a run escalates when the minimum confidence falls below the configured threshold.
§Examples
use ironflow_core::decision::{DecisionOutput, DecisionAnswer, NoulAnswer, DecisionUsage};
use std::collections::BTreeMap;
let output = DecisionOutput {
model: None,
answers: BTreeMap::from([("q".to_string(), DecisionAnswer::Noul(NoulAnswer { noul: 0.5 }))]),
usage: DecisionUsage::default(),
};
assert_eq!(output.min_confidence(), Some(0.0));