use std::time::Duration;
use typesafe::http::header::{HeaderName, HeaderValue};
use typesafe::{Client, Noul, Questions, RetryPolicy};
#[tokio::main]
async fn main() -> typesafe::Result<()> {
let http = reqwest::Client::builder()
.pool_max_idle_per_host(32)
.connect_timeout(Duration::from_secs(2))
.build()
.expect("a usable HTTP client");
let client = Client::builder()
.api_key(std::env::var("TYPESAFE_API_KEY").expect("TYPESAFE_API_KEY"))
.base_url("https://api.typesafe.ai")
.model("jev-latest")
.timeout(Duration::from_secs(5))
.retry(RetryPolicy::default().max_retries(1))
.header(
HeaderName::from_static("x-tenant"),
HeaderValue::from_static("acme"),
)
.http_client(http)
.build()?;
let res = client
.system_one(
"Our invoice says 12 seats and we have 9.",
Questions::from([("is_billing", Noul::new("This is about money"))]),
)
.model("jev-latest") .await?;
println!(
"{} says {:.3} (HTTP {}, {} attempt(s))",
res.model,
res.noul("is_billing").expect("asked, so answered").noul,
res.meta.status,
res.meta.attempts
);
Ok(())
}