typesayer
Typed structured prediction for Rust language-model applications.
Typesayer turns a declared input/output signature into provider-neutral messages, parses the response into typed values, supports incremental streaming, evaluates programs, persists state, and optimizes instructions and demonstrations.
Crates
| Crate | Purpose |
|---|---|
typesayer |
Prediction, adapters, evaluation, modules, state, and optimizers |
typesayer-types |
Fields, values, signatures, media values, and errors |
typesayer-parser |
Push-driven streaming structured-output parser |
Bayesian optimization is supplied by the independent
parzen crate. Provider clients and shared model types
come from modelplease.
modelplease ──→ typesayer-types ──→ typesayer-parser
│ │
└─────────────────┴─────────→ typesayer ←── parzen
Structured prediction
use ;
use ;
use ;
use ;
# async
OpenAI-backed applications
Enable typesayer/openai and construct an OpenAiLanguageModel from modelplease. Typesayer
accepts any Arc<dyn LanguageModelProvider>, so Anthropic, Ollama, Bedrock, custom providers, and
test doubles use the same prediction API.
[]
= { = "0.1.0", = ["openai"] }
= { = "0.1.0", = ["openai"] }
= { = "0.12", = false, = ["rustls-tls"] }
use Arc;
use ;
#
Streaming parsing
use ChatStreamParser;
use ;
let signature = builder
.input
.output
.build
.unwrap;
let mut parser = new;
let mut events = parser.push;
events.extend;
events.extend;
assert!;
Optimization and state
BootstrapFewShot, LabeledFewShot, and MIPROv2 optimize demonstrations and instructions.
The complete deterministic MIPRO example is runnable with:
Modules save DSPy-compatible JSON through Module::save and restore it through Module::load.
New files record the typesayer crate version. Typesayer 0.1 also reads state emitted by the
original prediction crate, ignores unknown metadata keys, and preserves the existing state wire
format.
Compatibility and license
The synchronized crate family begins at 0.1.0 and requires Rust 1.94.1 because it depends on
modelplease. Licensed under either MIT or Apache-2.0 at your option.