typesafe_systemone/lib.rs
1//! Async Rust client for the [TypeSafe](https://typesafe.ai) System One API.
2//!
3//! System One models (Jev) evaluate a `state` against typed questions and return
4//! calibrated probabilities instead of generated text. Three primitives exist:
5//!
6//! * [`Question::noul`] — a yes/no judgment, answered with the probability of "yes".
7//! * [`Question::choice`] — pick one option from a set, answered with a full distribution.
8//! * [`Question::score`] — a position on an ordered rubric, answered with a weighted score.
9//!
10//! ```no_run
11//! use typesafe_systemone::Client;
12//!
13//! # async fn run() -> Result<(), typesafe_systemone::Error> {
14//! let client = Client::from_env()?; // reads TYPESAFE_API_KEY
15//! let response = client
16//! .system_one()
17//! .field("message", "Help! My payouts have been failing for 3 days.")
18//! .noul("is_urgent", "Does `message` convey urgency?")
19//! .choice("department", "Which team should handle `message`?", |c| {
20//! c.option("billing", "Payments, invoicing, refunds")
21//! .option("technical", "Bugs, outages, integrations")
22//! .none_of_the_above("No listed team fits")
23//! })
24//! .score("frustration", "How frustrated is the customer?", ["Calm", "Frustrated", "Very angry"])
25//! .send()
26//! .await?;
27//!
28//! let urgent = response.noul("is_urgent")?;
29//! let team = response.choice("department")?;
30//! println!("urgent={urgent:.2} team={} confidence={:.2}", team.choice, team.confidence);
31//! # Ok(()) }
32//! ```
33//!
34//! `state` is whatever your questions refer to: pass your own `Serialize` struct with
35//! [`SystemOneRequest::state`], or assemble an object with [`SystemOneRequest::field`].
36//! Callers that already hold a question map use [`Client::evaluate`] directly.
37//!
38//! This is an unofficial client. The API contract it follows is documented at
39//! <https://docs.typesafe.ai/api>.
40
41mod answer;
42mod client;
43mod error;
44mod question;
45mod request;
46mod retry;
47
48pub use answer::{Answer, ChoiceAnswer, ModelInfo, NoulAnswer, ScoreAnswer, SystemOneResponse, Usage};
49pub use client::{Client, ClientBuilder, DEFAULT_BASE_URL, DEFAULT_MODEL};
50pub use error::{Error, Result};
51pub use question::{NONE_OF_THE_ABOVE, NoulCriteria, Question};
52pub use request::{ChoiceBuilder, SystemOneRequest};
53pub use retry::RetryPolicy;