Skip to main content

Crate typesafe_systemone

Crate typesafe_systemone 

Source
Expand description

Async Rust client for the TypeSafe System One API.

System One models (Jev) evaluate a state against typed questions and return calibrated probabilities instead of generated text. Three primitives exist:

  • Question::noul — a yes/no judgment, answered with the probability of “yes”.
  • Question::choice — pick one option from a set, answered with a full distribution.
  • Question::score — a position on an ordered rubric, answered with a weighted score.
use typesafe_systemone::Client;

let client = Client::from_env()?; // reads TYPESAFE_API_KEY
let response = client
    .system_one()
    .field("message", "Help! My payouts have been failing for 3 days.")
    .noul("is_urgent", "Does `message` convey urgency?")
    .choice("department", "Which team should handle `message`?", |c| {
        c.option("billing", "Payments, invoicing, refunds")
            .option("technical", "Bugs, outages, integrations")
            .none_of_the_above("No listed team fits")
    })
    .score("frustration", "How frustrated is the customer?", ["Calm", "Frustrated", "Very angry"])
    .send()
    .await?;

let urgent = response.noul("is_urgent")?;
let team = response.choice("department")?;
println!("urgent={urgent:.2} team={} confidence={:.2}", team.choice, team.confidence);

state is whatever your questions refer to: pass your own Serialize struct with SystemOneRequest::state, or assemble an object with SystemOneRequest::field. Callers that already hold a question map use Client::evaluate directly.

This is an unofficial client. The API contract it follows is documented at https://docs.typesafe.ai/api.

Structs§

ChoiceAnswer
Answer to a Question::Choice.
ChoiceBuilder
Option set of a Choice, built inside SystemOneRequest::choice.
Client
Client for the TypeSafe System One API. Cheap to clone; shares one HTTP pool.
ClientBuilder
Builder for Client. Explicit values win over environment variables.
ModelInfo
One entry from GET /v1/models.
NoulAnswer
Answer to a Question::Noul.
NoulCriteria
Optional descriptions of what a “yes” and a “no” mean for a Question::Noul.
RetryPolicy
Retry behaviour for transient failures.
ScoreAnswer
Answer to a Question::Score.
SystemOneRequest
A POST /v1/systemone call under construction. Created by Client::system_one.
SystemOneResponse
Response from POST /v1/systemone.
Usage
Token usage for one request. Output tokens are not billed.

Enums§

Answer
One answer, tagged with the type of the question that produced it.
Error
Errors returned by Client.
Question
A typed question evaluated against the request state.

Constants§

DEFAULT_BASE_URL
Production API root.
DEFAULT_MODEL
Model used when none is configured: the latest stable Jev release.
MAX_CHOICE_OPTIONS
Options one Choice may carry, per the API. Counting the abstain option.
NONE_OF_THE_ABOVE
Conventional name of the abstain option in a Choice. The model always picks some option, so give it one that means “nothing here fits”.

Type Aliases§

Result
Result alias for this crate.