Skip to main content

Crate typesafe_ai

Crate typesafe_ai 

Source
Expand description

Blocking and asynchronous clients for TypeSafe’s System One API.

Requests contain shared Request::state and one or more typed Questions. The service evaluates those questions independently and returns an Answer under each caller-selected question ID.

The default reqwest feature provides the asynchronous ReqwestClient. Enable the ureq feature for the blocking UreqClient. The rustls-tls feature enables rustls on each selected backend. With no backend feature, the data types and client traits remain available without an HTTP implementation.

§Request example

The same request can be passed to either backend:

use std::collections::BTreeMap;

use serde_json::json;
use typesafe_ai::{Question, Request};

let request = Request::new("Help! My payouts have been failing for three days.")
    .with_question(
        "is_urgent",
        Question::noul("Does the customer convey urgency?"),
    )
    .with_question(
        "department",
        Question::choice(
            "Which team should handle this?",
            BTreeMap::from([
                ("billing".into(), json!("Payments and invoices")),
                ("technical".into(), json!("Bugs and outages")),
            ]),
        ),
    )
    .with_question(
        "frustration",
        Question::score(
            "How frustrated is the customer?",
            vec![json!("Calm"), json!("Frustrated"), json!("Very angry")],
        ),
    );

assert_eq!(request.model, "jev-latest");
assert_eq!(request.questions.len(), 3);

Structs§

ClientConfig
Configuration shared by the blocking and asynchronous HTTP clients.
EvaluationFailure
A failed attempt and its scheduled retry, if any.
NoulCriteria
Criteria defining the positive and negative sides of a Noul question.
Request
State and typed questions sent to the System One evaluation endpoint.
ReqwestClient
Asynchronous TypeSafe client backed by reqwest.
Response
A successful System One response.
UreqClient
Blocking TypeSafe client backed by ureq.
Usage
Token counts reported for a request.

Enums§

Answer
A typed answer returned by System One.
Error
Errors returned while configuring or using a client.
EvaluationEvent
An observable outcome while evaluating a request.
Question
A typed judgment for System One to make against request state.

Traits§

AsyncClient
A backend-neutral asynchronous TypeSafe client.
Stream
A stream of values produced asynchronously.
SyncClient
A backend-neutral blocking TypeSafe client.

Type Aliases§

ReqwestError
Errors returned by ReqwestClient.
UreqError
Errors returned by UreqClient.