jevapi 0.1.0

An asynchronous, typed Rust client for the TypeSafe AI evaluation API
Documentation
use jevapi::{Answer, Client, Content, EvaluationRequest, NoulCriteria, Question};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::from_env()?;
    let request = EvaluationRequest::new(Content::try_from(json!({
        "message": "Our production payment service is down. Please help immediately.",
        "source": "support_ticket"
    }))?)
    .question(
        "urgent",
        Question::noul_with_criteria(
            "Is this request urgent?",
            NoulCriteria::default()
                .yes("Immediate action needed")
                .no("Can wait"),
        ),
    )
    .question(
        "team",
        Question::choice(
            "Which team should handle this?",
            [
                ("engineering", Some("Service outages and bugs".into())),
                ("sales", Some("New purchases".into())),
                ("other", None),
            ],
        ),
    )
    .question(
        "severity",
        Question::score(
            "How severe is the issue?",
            [
                "Minor inconvenience",
                "Partial loss of functionality",
                "Production outage",
            ],
        ),
    );

    let response = client.evaluate(&request).await?;
    println!("Model: {}", response.model);
    for (id, answer) in &response.answers {
        match answer {
            Answer::Noul { noul } => println!("{id}: probability={noul:.3}"),
            Answer::Choice {
                choice, confidence, ..
            } => println!("{id}: {choice}, confidence={confidence:.3}"),
            Answer::Score {
                score, confidence, ..
            } => println!("{id}: score={score:.3}, confidence={confidence:.3}"),
        }
    }
    println!(
        "Tokens: {} input, {} output",
        response.usage.input_tokens, response.usage.output_tokens
    );
    Ok(())
}