Skip to main content

Crate guideme

Crate guideme 

Source
Expand description

Type-safe inline judgments from TypeSafe Jev.

use guideme::{choose, noul, score, Choice, Guide, Levels, Policy};

#[derive(Choice, Clone, Copy, PartialEq, Eq, Debug)]
enum Department {
    /// Payments, invoicing, refunds
    Billing,
    /// Bugs, outages, integrations
    Technical,
    /// Pricing, upgrades, new accounts
    #[guide(fallback)]
    Sales,
}

#[derive(Levels, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
enum Frustration {
    /// Calm and polite
    Calm,
    /// Frustrated
    Frustrated,
    /// Very angry
    VeryAngry,
}

let guide = Guide::from_env()?; // TYPESAFE_API_KEY

if guide.ask(noul("Should this ticket be escalated?"), ticket).await? {
    // escalate
}

match guide.ask(choose::<Department>("Which team should handle this?"), ticket).await? {
    Department::Billing => {}
    Department::Technical => {}
    Department::Sales => {}
}

if guide.ask(score::<Frustration>("How frustrated is the customer?"), ticket).await?
    >= Frustration::Frustrated
{
    // prioritise
}

// three judgments, one request, one span
let (urgent, dept, mood) = guide
    .ask(
        (
            noul("Is this urgent?").yes_above(0.7).no_below(0.3).or(false),
            choose::<Department>("Which team?").with(Policy::new().min_confidence(0.6)),
            score::<Frustration>("How frustrated?").detail(),
        ),
        ticket,
    )
    .await?;

Re-exports§

pub use api::ModelInfo;
pub use api::Usage;
pub use policy::Policy;
pub use policy::Thresholds;
pub use policy::Verdict;

Modules§

api
Exact typed mirror of POST /v1/systemone and GET /v1/models.
policy
The pure decision layer: thresholds in, labelled outcome out. No I/O, no generics. spec/vectors/policy.json pins its behaviour for every guideme SDK.

Structs§

ApiKey
A TypeSafe API key. Debug never prints it.
Choose
One of C’s options.
Confidence
A confidence in 0..=1, validated once at the wire. Absent on noul answers.
Detailed
K with the detailed output. Never fails on unsure.
Guide
A configured entry point to Jev. Cheap to clone; share it.
GuideBuilder
Configures a Guide.
Instructions
The question text, or a structured object holding the question plus data it references.
Key
A runtime option key. Only meaningful through choose_among: its RUBRIC is empty, so choose::<Key>(..) is rejected with Error::Config when asked.
Model
A model name or alias accepted by the model field.
Noul
Yes/no.
Probability
A probability in 0..=1, validated once at the wire.
Question
A question plus its local policy patch. Inert until a crate::Guide asks it; build it once and clone it per ask.
Rank
A runtime level index. Only meaningful through score_levels: its LEVELS is empty, so score::<Rank>(..) is rejected with Error::Config when asked.
Ranked
A choice answer in full: the pick, its confidence, and the whole distribution.
Receipt
An answer with what the request cost and which model produced it.
Rubric
A description with examples, for the rubric positions that are not an enum.
Score
A level of L.
Scored
A score answer in full: expected value, argmax level, confidence, distribution.
State
The content the model evaluates: text, or any JSON-serialisable structure.

Enums§

Error
Everything that can go wrong, from the wire to the policy.

Traits§

Ask
Sealed. Output has the same shape as the input, each question replaced by its answer.
Binary
Kinds judged by a yes/no probability: yes_above / no_below apply.
Confident
Kinds judged by a reported confidence: min_confidence applies.
Fallible
Kinds whose plain output can fail with Error::Unsure and therefore accept .or() / .detail().
IntoRubric
What a rubric position accepts: a description — anything String converts from, so every call written against impl Into<String> still compiles — or a Rubric carrying examples.
Kind
A question kind: how to put it on the wire and how to read the outcome back.
Levels
Implemented by #[derive(Levels)]. Level order is declaration order.
Options
Implemented by #[derive(Choice)]. Hand-implement for dynamic option sets.

Functions§

choose
Pick one of C’s options. Plain output: C.
choose_among
Pick one of runtime options (key, rubric). Plain output: Key.
noul
A yes/no question. Plain output: bool.
score
Rate on L’s levels. Plain output: the argmax level L.
score_levels
Rate on runtime levels, low to high. Plain output: Rank.

Derive Macros§

Choice
Derive guideme::Options for a unit-variant enum.
Levels
Derive guideme::Levels for a unit-variant enum.