use typesafe_system_one::{Choice, Client, Noul, Score, SystemOneRequest};
#[tokio::main]
async fn main() -> Result<(), typesafe_system_one::Error> {
let client = Client::from_env()?;
let request = SystemOneRequest::new(
"Subject: refund\nBody: You charged me twice for the same subscription. \
This is ridiculous and I want my money back TODAY.",
)
.question(
"team",
Choice::new("Which team should handle this?")
.option("billing", "Charges, refunds, subscriptions, invoices")
.option("tech", "Bugs, outages, broken features")
.option("legal", "Compliance, legal threats, regulation"),
)
.question(
"urgency",
Score::new(
"How urgent is this?",
[
"Can wait",
"Needs attention this week",
"Needs attention today",
],
),
)
.question("refund", Noul::new("Is the customer asking for a refund?"));
let response = client.system_one(request).await?;
let team = match response.choice("team") {
Some(choice) if choice.confidence >= 0.7 => choice.choice.clone(),
_ => "general".to_owned(), };
let needs_today = response
.score("urgency")
.is_some_and(|score| score.confidence >= 0.6 && score.score >= 2.0);
let wants_refund = response
.noul("refund")
.map(|noul| noul.noul > 0.5)
.unwrap_or(false);
println!("route to: {team}");
println!("needs attention today: {needs_today}");
println!("wants refund: {wants_refund}");
println!(
"usage: {} in / {} out",
response.usage.input_tokens, response.usage.output_tokens
);
Ok(())
}