use std::process::ExitCode;
use typesafe_sdk::{Choice, Client, Error, Noul, Questions, Score};
#[tokio::main]
async fn main() -> ExitCode {
match run().await {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
eprintln!("error: {error}");
ExitCode::FAILURE
}
}
}
async fn run() -> Result<(), Error> {
let client = Client::from_env()?;
let questions = Questions::new()
.noul("billing", Noul::new().instructions("Is this message about billing?"))
.choice("tone", Choice::new(["calm", "annoyed", "angry"]).instructions("What is the tone?"))
.score(
"urgency",
Score::new(["can wait", "this week", "today"]).instructions("How urgent is it?"),
)
.prepare()?;
let state = "I was charged twice for the same order. Please fix it before Friday.";
let response = client.system_one(state, &questions).send().await?;
println!("model: {}", response.model());
for (name, answer) in response.answers().nouls() {
println!("{name}: {:.3}", answer.noul());
}
for (name, answer) in response.answers().choices() {
println!("{name}: {} (confidence {:.3})", answer.choice(), answer.confidence());
}
for (name, answer) in response.answers().scores() {
println!("{name}: {:.3} (confidence {:.3})", answer.score(), answer.confidence());
}
if let Some(id) = response.meta().request_id() {
println!("request id: {id}");
}
Ok(())
}