typesafe/lib.rs
1//! A Rust client for [TypeSafe](https://docs.typesafe.ai/)'s System One API,
2//! the API behind **Jev**. It is unofficial. Its behaviour follows the
3//! official Python SDK: the same environment variables and defaults, the same
4//! retry policy, and the same error kinds.
5//!
6//! System One models don't generate text. You send some state and a set of
7//! typed questions, and get back one typed answer per question, with
8//! probabilities your code acts on:
9//!
10//! | Question | Asks | Answer |
11//! | --- | --- | --- |
12//! | [`Noul`] | whether a condition holds | [`NoulAnswer`]: the probability of yes |
13//! | [`Choice`] | which one of a defined set | [`ChoiceAnswer`]: option, probabilities, confidence |
14//! | [`Score`] | how far along ordered levels | [`ScoreAnswer`]: weighted level, probabilities, confidence |
15//!
16//! ```no_run
17//! use serde_json::json;
18//! use typesafe::{Choice, Noul, Questions, Score};
19//!
20//! # #[cfg(feature = "blocking")]
21//! # fn main() -> Result<(), typesafe::Error> {
22//! let client = typesafe::blocking::Client::new(); // reads TYPESAFE_API_KEY
23//!
24//! let questions = Questions::new()
25//! .ask("billing", Noul::new("Is this ticket about billing?"))
26//! .ask("tone", Choice::new("What is the customer's tone?").options(["calm", "frustrated", "angry"]))
27//! .ask("urgency", Score::new("How urgent is this ticket?", ["Can wait", "This week", "Today"]));
28//!
29//! let response = client.system_one(
30//! &json!({"ticket": "I was charged twice. Please fix this ASAP."}),
31//! &questions,
32//! )?;
33//!
34//! let tone = response.choice("tone").unwrap();
35//! if response.noul("billing").unwrap().yes() && tone.confidence > 0.5 {
36//! println!("billing, {} ({:.2})", tone.choice, tone.confidence);
37//! }
38//! # Ok(())
39//! # }
40//! # #[cfg(not(feature = "blocking"))]
41//! # fn main() {}
42//! ```
43//!
44//! # Features
45//!
46//! - `async` (default): [`Client`], for a tokio runtime
47//! - `blocking`: [`blocking::Client`], for synchronous code
48//! - `rustls` (default) or `native-tls`: the TLS backend
49
50mod answer;
51mod config;
52mod error;
53mod question;
54mod request;
55mod response;
56mod retry;
57
58#[cfg(feature = "blocking")]
59pub mod blocking;
60#[cfg(feature = "async")]
61mod client;
62
63pub use answer::{Answer, ChoiceAnswer, NoulAnswer, ScoreAnswer};
64#[cfg(feature = "async")]
65pub use client::Client;
66pub use config::{
67 CallOptions, Config, DEFAULT_BASE_URL, DEFAULT_MODEL, DEFAULT_TIMEOUT, ENV_API_KEY,
68 ENV_BASE_URL, ENV_DEFAULT_MODEL,
69};
70pub use error::{Error, ErrorKind};
71pub use question::{Choice, Noul, Question, Questions, Score};
72pub use response::{Model, Response, Usage};
73pub use retry::RetryPolicy;