Skip to main content

SystemOneResponse

Struct SystemOneResponse 

Source
pub struct SystemOneResponse {
    pub model: String,
    pub answers: IndexMap<String, Answer>,
    pub usage: Option<Usage>,
    pub meta: ResponseMeta,
}
Expand description

Parsed POST /v1/systemone response.

Look up typed answers with noul, choice, and score. Unknown type values are Answer::Unknown.

Fields§

§model: String

Model that produced the answers.

§answers: IndexMap<String, Answer>

Answers keyed as in the request.

§usage: Option<Usage>

Token usage, when present.

§meta: ResponseMeta

HTTP metadata filled in by the client after deserialize.

Implementations§

Source§

impl SystemOneResponse

Source

pub fn nouls(&self) -> impl Iterator<Item = (&str, NoulView)> + '_

Iterate Noul answers.

Source

pub fn choices(&self) -> impl Iterator<Item = (&str, ChoiceView<'_>)> + '_

Iterate Choice answers.

Source

pub fn scores(&self) -> impl Iterator<Item = (&str, ScoreView<'_>)> + '_

Iterate Score answers.

Source

pub fn noul(&self, key: &str) -> Option<f64>

Noul probability for key, if that answer is a Noul.

Examples found in repository?
examples/blocking.rs (line 29)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12    let rt = tokio::runtime::Builder::new_multi_thread()
13        .enable_all()
14        .build()?;
15    let mock = rt.block_on(MockServer::start());
16    mock.on_system_one().respond(json!({
17        "urgent": noul(0.91),
18    }));
19
20    let client = ClientConfig::new()
21        .api_key("test")
22        .base_url(mock.url())
23        .build_blocking()?;
24
25    let response = client.system_one(
26        "Help! My payouts have been failing for 3 days.",
27        questions! { "urgent" => Question::noul("Does this convey urgency?") },
28    )?;
29    println!("urgent noul = {:?}", response.noul("urgent"));
30
31    drop(client);
32    drop(mock);
33    drop(rt);
34    Ok(())
35}
More examples
Hide additional examples
examples/quickstart.rs (line 38)
14async fn main() -> Result<(), Box<dyn std::error::Error>> {
15    let mock = MockServer::start().await;
16    mock.on_system_one().respond(json!({
17        "urgent": noul(0.97),
18    }));
19
20    let client = Client::new(ClientConfig {
21        api_key: Some("test".into()),
22        base_url: Some(mock.url()),
23        default_model: Some("jev-latest".into()),
24        ..ClientConfig::default()
25    })?;
26
27    let response = client
28        .system_one(
29            "Help! My payouts have been failing for 3 days.",
30            questions! {
31                "urgent" => Question::noul("Does this convey urgency?")
32                    .when_true("Explicitly time-sensitive")
33                    .when_false("No time pressure"),
34            },
35        )
36        .await?;
37
38    println!("urgent noul = {:?}", response.noul("urgent"));
39    println!("request id  = {:?}", response.meta.request_id);
40    Ok(())
41}
examples/triage.rs (line 44)
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13    let mock = MockServer::start().await;
14    mock.on_system_one().respond(json!({
15        "urgent": noul(0.97),
16        "team": choice("technical", 0.82),
17        "frustration": score(1.6, 0.78),
18    }));
19
20    let client = ClientConfig::new()
21        .api_key("test")
22        .base_url(mock.url())
23        .build()?;
24
25    let response = client
26        .system_one(
27            "Help! My payouts have been failing for 3 days.",
28            questions! {
29                "urgent" => Question::noul("Does this convey urgency?")
30                    .when_true("Explicitly time-sensitive")
31                    .when_false("No time pressure"),
32                "team" => Question::choice("Which team should handle this?")
33                    .option("billing", "Payments, invoicing, refunds")
34                    .option("technical", "Bugs, outages, integrations")
35                    .option("sales", "Pricing, upgrades, new accounts"),
36                "frustration" => Question::score("How frustrated is the customer?")
37                    .level("Calm")
38                    .level("Frustrated")
39                    .level("Very angry"),
40            },
41        )
42        .await?;
43
44    println!("urgent      = {:?}", response.noul("urgent"));
45    println!(
46        "team        = {:?}",
47        response.choice("team").map(|c| c.choice)
48    );
49    println!(
50        "frustration = {:?}",
51        response.score("frustration").map(|s| s.score)
52    );
53    Ok(())
54}
Source

pub fn choice(&self, key: &str) -> Option<ChoiceView<'_>>

Choice view for key, if that answer is a Choice.

Examples found in repository?
examples/triage.rs (line 47)
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13    let mock = MockServer::start().await;
14    mock.on_system_one().respond(json!({
15        "urgent": noul(0.97),
16        "team": choice("technical", 0.82),
17        "frustration": score(1.6, 0.78),
18    }));
19
20    let client = ClientConfig::new()
21        .api_key("test")
22        .base_url(mock.url())
23        .build()?;
24
25    let response = client
26        .system_one(
27            "Help! My payouts have been failing for 3 days.",
28            questions! {
29                "urgent" => Question::noul("Does this convey urgency?")
30                    .when_true("Explicitly time-sensitive")
31                    .when_false("No time pressure"),
32                "team" => Question::choice("Which team should handle this?")
33                    .option("billing", "Payments, invoicing, refunds")
34                    .option("technical", "Bugs, outages, integrations")
35                    .option("sales", "Pricing, upgrades, new accounts"),
36                "frustration" => Question::score("How frustrated is the customer?")
37                    .level("Calm")
38                    .level("Frustrated")
39                    .level("Very angry"),
40            },
41        )
42        .await?;
43
44    println!("urgent      = {:?}", response.noul("urgent"));
45    println!(
46        "team        = {:?}",
47        response.choice("team").map(|c| c.choice)
48    );
49    println!(
50        "frustration = {:?}",
51        response.score("frustration").map(|s| s.score)
52    );
53    Ok(())
54}
Source

pub fn score(&self, key: &str) -> Option<ScoreView<'_>>

Score view for key, if that answer is a Score.

Examples found in repository?
examples/triage.rs (line 51)
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13    let mock = MockServer::start().await;
14    mock.on_system_one().respond(json!({
15        "urgent": noul(0.97),
16        "team": choice("technical", 0.82),
17        "frustration": score(1.6, 0.78),
18    }));
19
20    let client = ClientConfig::new()
21        .api_key("test")
22        .base_url(mock.url())
23        .build()?;
24
25    let response = client
26        .system_one(
27            "Help! My payouts have been failing for 3 days.",
28            questions! {
29                "urgent" => Question::noul("Does this convey urgency?")
30                    .when_true("Explicitly time-sensitive")
31                    .when_false("No time pressure"),
32                "team" => Question::choice("Which team should handle this?")
33                    .option("billing", "Payments, invoicing, refunds")
34                    .option("technical", "Bugs, outages, integrations")
35                    .option("sales", "Pricing, upgrades, new accounts"),
36                "frustration" => Question::score("How frustrated is the customer?")
37                    .level("Calm")
38                    .level("Frustrated")
39                    .level("Very angry"),
40            },
41        )
42        .await?;
43
44    println!("urgent      = {:?}", response.noul("urgent"));
45    println!(
46        "team        = {:?}",
47        response.choice("team").map(|c| c.choice)
48    );
49    println!(
50        "frustration = {:?}",
51        response.score("frustration").map(|s| s.score)
52    );
53    Ok(())
54}
Source

pub fn answer(&self, key: &str) -> Option<&Answer>

Borrow the answer for key.

Trait Implementations§

Source§

impl Clone for SystemOneResponse

Source§

fn clone(&self) -> SystemOneResponse

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SystemOneResponse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SystemOneResponse

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more