Skip to main content

Crate kunobi_jev

Crate kunobi_jev 

Source
Expand description

Rust client for the TypeSafe System One API.

Send state and typed questions to Jev; get structured answers with probabilities and confidence that code can act on directly.

  • noul: a yes/no question, answered with the probability of yes.
  • choice: pick one label, answered with probabilities and confidence.
  • score: rate against ordered levels, answered with an expected score.
use kunobi_jev::{Client, Questions, SystemOneRequest, choice_labels, noul, score};

let client = Client::new()?; // reads TYPESAFE_API_KEY

let mut questions = Questions::new();
let billing = questions.add("billing", noul("Is this ticket about billing?"));
let tone = questions.add("tone", choice_labels("What is the tone?", ["calm", "frustrated", "angry"]));
let urgency = questions.add("urgency", score("How urgent?", ["can wait", "today", "right now"]));

let result = client
    .system_one(SystemOneRequest::new("I was charged twice. Fix this ASAP.", questions))
    .await?;

let tone = result.answer(&tone)?;
if tone.confidence > 0.6 {
    println!("tone: {}", tone.choice);
}
println!("billing: {:.2}", result.answer(&billing)?.noul);
println!("urgency: {:.2}", result.answer(&urgency)?.score);

Calls retry 408, 429 and 5xx responses, connection errors and timeouts with capped exponential backoff, honoring Retry-After. See RetryPolicy. Requests log through tracing: summaries at info and redacted headers at debug. Bodies are logged only with ClientBuilder::log_bodies.

Authenticate with an API key, or with a CredentialProvider when the client runs on user machines and must not hold a TypeSafe key. See credentials.

Re-exports§

pub use answers::Answer;
pub use answers::AnswerKind;
pub use answers::ChoiceAnswer;
pub use answers::NoulAnswer;
pub use answers::ScoreAnswer;
pub use answers::SystemOneResult;
pub use answers::TypedChoiceAnswer;
pub use client::Call;
pub use client::Client;
pub use client::ClientBuilder;
pub use client::DEFAULT_BASE_URL;
pub use client::DEFAULT_MODEL;
pub use client::ENV_API_KEY;
pub use client::ENV_BASE_URL;
pub use client::ENV_DEFAULT_MODEL;
pub use client::Models;
pub use client::RawResponse;
pub use client::WithResponse;
pub use credentials::BoxError;
pub use credentials::CredentialProvider;
pub use credentials::TokenFuture;
pub use error::ApiError;
pub use error::ApiErrorKind;
pub use error::Error;
pub use error::ErrorBody;
pub use error::REQUEST_ID_HEADER;
pub use error::Result;
pub use labels::Labels;
pub use questions::AnswerKey;
pub use questions::ChoiceQuestion;
pub use questions::NoulCriteria;
pub use questions::NoulQuestion;
pub use questions::Question;
pub use questions::QuestionKind;
pub use questions::Questions;
pub use questions::ScoreQuestion;
pub use questions::TypedChoice;
pub use questions::choice;
pub use questions::choice_labels;
pub use questions::choice_of;
pub use questions::noul;
pub use questions::score;
pub use request::SystemOneRequest;
pub use retry::DEFAULT_TIMEOUT;
pub use retry::DEFAULT_TOTAL_TIMEOUT;
pub use retry::RetryPolicy;
pub use retry::parse_retry_after;
pub use system_one::AskFuture;
pub use system_one::SystemOne;
pub use types::Entry;
pub use types::ModelCard;
pub use types::Usage;
pub use reqwest;

Modules§

answers
Answer types and the systemone result.
blockingblocking
A blocking client, for code that is not async. Enabled by the blocking feature.
client
The API client.
credentials
Credentials: a static API key, or a provider that supplies a bearer token per attempt.
error
Error types.
labels
Typed choice labels.
questions
Question types, builders and typed answer keys.
request
The systemone request.
retry
Retry policy, delay calculation and Retry-After parsing.
system_one
The SystemOne trait, so code can depend on “something that answers questions”.
testingtesting
A scripted SystemOne for tests. Enabled by the testing feature.
types
Values shared by requests and responses.

Macros§

labels
Declare an enum of choice labels.

Constants§

VERSION
This crate’s version.

Traits§

ExposeSecret
Expose a reference to an inner secret

Type Aliases§

SecretString
Secret string type.