pub enum Question {
Noul {
instructions: Entry,
criteria: Option<NoulCriteria>,
},
Choice {
instructions: Entry,
criteria: IndexMap<String, Entry>,
},
Score {
instructions: Entry,
criteria: Vec<Entry>,
},
}Expand description
A typed System One question.
Build with Question::noul, Question::choice, and Question::score.
Choice needs at least two options; Score needs at least two
levels. Validation runs before the request is sent.
§Examples
use typesafe_rs::Question;
let urgent = Question::noul("Does this convey urgency?")
.when_true("Explicitly time-sensitive")
.when_false("No time pressure");
let team = Question::choice("Which team?")
.option("billing", "Payments")
.option("technical", "Bugs");
let mood = Question::score("How frustrated?")
.level("Calm")
.level("Frustrated")
.level("Very angry");Variants§
Noul
Yes/no question; the answer is a probability in [0, 1].
Fields
criteria: Option<NoulCriteria>Optional descriptions of the yes and no outcomes.
Choice
Select one named option from a set.
Fields
Score
Rate the state against an ordered rubric.
Implementations§
Source§impl Question
impl Question
Sourcepub fn noul(instructions: impl Into<Entry>) -> Self
pub fn noul(instructions: impl Into<Entry>) -> Self
Build a Noul question.
Examples found in repository?
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
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}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}Sourcepub fn choice(instructions: impl Into<Entry>) -> Self
pub fn choice(instructions: impl Into<Entry>) -> Self
Build a Choice question with no options yet.
Examples found in repository?
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}Sourcepub fn score(instructions: impl Into<Entry>) -> Self
pub fn score(instructions: impl Into<Entry>) -> Self
Build a Score question with no levels yet.
Examples found in repository?
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}Sourcepub fn when_true(self, description: impl Into<Entry>) -> Self
pub fn when_true(self, description: impl Into<Entry>) -> Self
Describe the yes outcome of a Noul question.
No-op if this is not a Noul question.
Examples found in repository?
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}More examples
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}Sourcepub fn when_false(self, description: impl Into<Entry>) -> Self
pub fn when_false(self, description: impl Into<Entry>) -> Self
Describe the no outcome of a Noul question.
No-op if this is not a Noul question.
Examples found in repository?
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}More examples
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}Sourcepub fn option(
self,
key: impl Into<String>,
description: impl Into<Entry>,
) -> Self
pub fn option( self, key: impl Into<String>, description: impl Into<Entry>, ) -> Self
Add a named option to a Choice question.
No-op if this is not a Choice question.
Examples found in repository?
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}Sourcepub fn level(self, description: impl Into<Entry>) -> Self
pub fn level(self, description: impl Into<Entry>) -> Self
Append a rubric level to a Score question.
No-op if this is not a Score question.
Examples found in repository?
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}