1use serde_json::json;
8use typesafe_rs::{ClientConfig, Question, questions};
9use typesafe_rs_mock::{MockServer, choice, noul, score};
10
11#[tokio::main]
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}