Skip to main content

Crate laya

Crate laya 

Source
Expand description

Laya typed decisions in Rust.

An independent Rust port of the Laya decision models: a bidirectional encoder answers constrained questions — a choice, a rubric score, or the probability of a proposition — in one forward pass, with no token-by-token decoding and no generated JSON.

use laya::Agent;
use serde_json::json;

let agent = Agent::from_pretrained("aac6fef/laya-mlx")?;
let result = agent.predict(
    &json!("I was billed twice. Please refund the duplicate."),
    &json!({
        "department": {
            "type": "choice",
            "instructions": "Who should handle this?",
            "criteria": ["billing", "technical", "sales"]
        }
    }),
)?;
println!("{}", result.answers["department"]);

Unlike the MLX package this is ported from, inference runs on CPU, CUDA and Metal. Build with --features metal or --features cuda for GPU support.

Re-exports§

pub use agent::Agent;
pub use agent::AgentBuilder;
pub use agent::Answer;
pub use agent::Prediction;
pub use config::AgentConfig;
pub use config::EncoderConfig;
pub use model::DecisionModel;
pub use model::ModernBert;
pub use router::ModelName;
pub use router::RouteDecision;
pub use router::Router;

Modules§

agent
The public inference runtime. Prompt and result formats follow upstream Laya.
calibrate
Temperature calibration and the confidence metric, ported from upstream.
config
Checkpoint configuration, validated exactly as upstream validates it.
convert
Export a standalone checkpoint with canonical parameter names and a dtype.
email
Email utilities for cleaning and structuring email inputs.
hub
Checkpoint resolution against the Hugging Face Hub.
lang
Dependency-free script and language detection used to route between checkpoints.
model
ModernBERT encoder and Laya decision heads, in candle.
presets
Ready-to-use question presets for common production decision workflows.
prompt
Prompt construction.
question
Typed question definitions, validated and rendered exactly as upstream does.
router
Route a request to the checkpoint best suited to it.
weights
Parameter-name mapping.

Structs§

Question
A question after validation, equivalent to upstream’s internal {"t": ..., "ins": ..., "crit": ...} triple.
Tokenizer
A loaded tokenizer plus the four special tokens upstream requires.

Enums§

Criteria
Validated criteria, in label order.
Error
Errors raised by the runtime.
QuestionKind
Question type, and the integer the model’s type embedding expects.

Type Aliases§

Result