pub struct SystemOneResult {
pub model: String,
pub answers: IndexMap<String, Value>,
pub input_tokens: usize,
pub output_tokens: usize,
pub routing: Option<Value>,
}Expand description
The result of a single-state evaluation (Jev-shaped).
Fields§
§model: String§answers: IndexMap<String, Value>§input_tokens: usize§output_tokens: usize§routing: Option<Value>Set by crate::Router::predict; the routing decision as JSON.
Implementations§
Source§impl SystemOneResult
impl SystemOneResult
Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
Serialise to the Jev wire shape: {model, answers, usage, routing?}.
Examples found in repository?
examples/predict.rs (line 41)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let model =
14 std::env::var("LAYA_MODEL").unwrap_or_else(|_| "convaiinnovations/laya".to_string());
15 let subfolder = std::env::var("LAYA_SUBFOLDER").ok();
16 let device = std::env::var("LAYA_DEVICE").ok().filter(|s| !s.is_empty());
17
18 let t = Instant::now();
19 let agent = Agent::load(
20 &model,
21 LoadOptions {
22 subfolder,
23 device: device.clone(),
24 ..Default::default()
25 },
26 )?;
27 println!(
28 "loaded {model} on {} in {:?}",
29 device.as_deref().unwrap_or("cpu"),
30 t.elapsed()
31 );
32
33 let state: State = serde_json::json!({
34 "message": "I was charged twice this month and I'm furious. Refund me now or I'm leaving."
35 });
36 let questions = triage_questions();
37
38 let t = Instant::now();
39 let result = agent.system_one(&state, &questions)?;
40 println!("forward in {:?}\n", t.elapsed());
41 println!("{}", serde_json::to_string_pretty(&result.to_json())?);
42
43 // Sanity: every probability distribution should sum to ~1.
44 for (qid, ans) in &result.answers {
45 if let Some(probs) = ans.get("probabilities").and_then(|p| p.as_object()) {
46 let sum: f64 = probs.values().filter_map(|v| v.as_f64()).sum();
47 assert!((sum - 1.0).abs() < 1e-2, "{qid} probabilities sum to {sum}");
48 }
49 }
50 println!("\nOK: probability distributions sum to 1.");
51 Ok(())
52}Trait Implementations§
Source§impl Clone for SystemOneResult
impl Clone for SystemOneResult
Auto Trait Implementations§
impl Freeze for SystemOneResult
impl RefUnwindSafe for SystemOneResult
impl Send for SystemOneResult
impl Sync for SystemOneResult
impl Unpin for SystemOneResult
impl UnsafeUnpin for SystemOneResult
impl UnwindSafe for SystemOneResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more