Expand description
§jevrs-core
Use this crate when your runtime or HTTP stack is not supported by jevrs.
It contains the request builder, typed answer validation, and JSON codecs, but
performs no I/O and works without std.
Build a Questions batch and keep its typed Handle values. Call
encode to create the POST /v1/systemone body. Send those bytes with your
HTTP implementation, then call decode for a successful response or
classify for an unsuccessful status. You only need to implement the HTTP
exchange and any retry policy.
use jevrs_core::{Model, Questions, decode, encode};
let mut questions = Questions::new();
let urgent = questions.noul_with(
"is_urgent",
"Does this convey urgency?",
"Explicitly time-sensitive",
"No urgency expressed",
)?;
let request = encode(
&Model::LATEST,
&"Help! My payouts have been failing for 3 days.",
&questions,
)?;
assert!(!request.is_empty());
let response = br#"{
"model":"jev-1.13.0",
"answers":{"is_urgent":{"type":"noul","noul":0.95}},
"usage":{"input_tokens":414,"output_tokens":73}
}"#;
let answers = decode(&questions, response)?;
assert!(answers.get(urgent).is_yes(0.9));Use Options and Levels implementations for compile-time criteria. Pass
runtime criteria straight to Questions::choice_dyn and
Questions::score_dyn; they validate the items and name the question in
Error::InvalidCriteria. Use DynOptions and DynLevels to validate
once up front and reuse the criteria across batches. Implement QuestionSet
when you want a reusable typed group; jevrs also provides derives for these
traits.
Transport adapters should preserve error details for callers:
use core::time::Duration;
use jevrs_core::{Error, classify};
let error = classify(
429,
br#"{"detail":"Try again later"}"#,
Some(Duration::from_secs(2)),
Some("req_123"),
);
assert!(matches!(error, Error::RateLimited { .. }));Structs§
- Answered
- A typed question-set result together with response metadata.
- Answers
- Eagerly decoded answers for one
Questionsbatch. - Array
Map - Dense per-key storage for a static
OptionsorLevelsimplementation. - Choice
Answer - The selected option and probability distribution for a static choice.
- ChoiceQ
- Marker to use when
Optionsdefine a choice at compile time. - Confidence
- A model confidence constrained to the inclusive range from zero to one.
- DynChoice
Answer - The selected option and probability distribution for a dynamic choice.
- DynChoiceQ
- Marker returned for a choice built with runtime-defined
crate::DynOptions. - DynLevels
- A runtime-defined ordered scoring scale.
- DynOptions
- A runtime-defined set of named choices.
- DynScore
Answer - The expected score and probability distribution for dynamic levels.
- DynScoreQ
- Marker returned for a score built with runtime-defined
crate::DynLevels. - Error
Detail - Information recovered from an unsuccessful API response body.
- Handle
- A typed reference to one question in a
Questionsbatch. - Instructions
- Guidance supplied with a Jev question as a JSON value.
- Model
- A Jev model name used for requests and reported by responses.
- Noul
Answer - The probability assigned to a yes/no question’s positive outcome.
- NoulQ
- Marker to use for a yes/no question in a typed handle or
QuestionSet. - Probability
- A probability constrained to the inclusive range from zero to one.
- Questions
- An insertion-ordered collection of questions sent in one Jev request.
- Score
Answer - The expected score and probability distribution for static levels.
- ScoreQ
- Marker to use when
Levelsdefine a score scale at compile time. - Usage
- Token counts consumed while producing a Jev response.
Enums§
- Error
- An error produced while constructing, sending, or decoding a Jev request.
Traits§
- Indexed
- A finite set whose values have a dense canonical order.
- Levels
- A statically defined ordered scoring scale.
- Options
- A statically defined set of named choices.
- Question
- Binds a question marker to the answer type returned for it.
- Question
Set - Defines a reusable, statically typed set of Jev questions.
Functions§
- classify
- Classifies an unsuccessful HTTP response and preserves its API details.
- decode
- Decodes and validates a Jev response for
questionswithout network I/O. - encode
- Encodes a Jev request body without performing network I/O.
Type Aliases§
- Choice
- Readable alias to use for a static choice field in a
crate::QuestionSet. - Noul
- Readable alias to use for a yes/no field in a
crate::QuestionSet. - Score
- Readable alias to use for a static score field in a
crate::QuestionSet.