dsir 0.1.1

DSPy-shaped library for programming language models in Rust.
Documentation

dsir

Program—don't prompt—language models in Rust.

dsir is a DSPy-shaped library for building composable LM pipelines: typed signatures, modules (Predict, ChainOfThought, ReAct, agents), evaluation, and self-improving prompts (few-shot bootstrap + instruction search). Runtime programs use DynSignature, ProgramGraph, and the self-improvement lab.

Install

[dependencies]
dsir = "0.1.1"
tokio = { version = "1", features = ["full"] }

Requires latest stable Rust (see rust-toolchain.toml).

Quickstart

use dsir::{configure, ChatAdapter, LM, Predict, Signature};

/// Answer questions accurately and concisely.
#[derive(Signature, Clone, Debug)]
struct QA {
    #[input]
    question: String,
    #[output]
    answer: String,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    configure(
        LM::builder()
            .model("openai:gpt-4o-mini".to_string())
            .build()
            .await?,
        ChatAdapter,
    );

    let predict = Predict::<QA>::new();
    let out = predict
        .call(QAInput {
            question: "What is the capital of France?".into(),
        })
        .await?;
    println!("{}", out.answer);
    Ok(())
}
cargo run -p dsir --example 01_predict   # requires OPENAI_API_KEY

Library surface

Area Types
Signatures Signature, #[derive(Signature)], DynSignature (JSON / string DSL)
Modules Predict, DynPredict, ChainOfThought, ReAct, Agent, BestOfN, Refine
Graphs ProgramGraph, StrategyFactory, StructuralOptimizer
Optimize LabeledFewShot, BootstrapFewShot, COPRO, MIPROv2, GEPA (+ compile_dyn)
Evaluate TypedMetric, DynMetric, Evaluate, evaluate_trainset
Lab Lab, local/remote registry, promote/compare
Persist save_program / load_program, GraphState

Optimizers at a glance

Optimizer Best for
LabeledFewShot Fast demo assignment from labeled data
BootstrapFewShot Self-improvement from successful traces
COPRO Quick instruction search, limited compute
MIPROv2 Best instruction quality, 15+ examples
GEPA Tasks needing textual feedback

See optimizers overview.

Examples

Example Command Notes
Predict cargo run -p dsir --example 01_predict Live LM
Chain of thought cargo run -p dsir --example 02_cot Live LM
Bootstrap cargo run -p dsir --example 04_bootstrap Offline
Lab cargo run -p dsir --example 05_lab Offline
Program graph cargo run -p dsir --example 06_graph Offline

Companion binaries: dsir-registry (HTTP run registry), dsir-lab-ui (experiment dashboard).

Documentation

Documentation hub — user guides and architecture notes.

Quick links:

Maintainer docs: goals, architecture, roadmap.

License

Apache-2.0. See LICENSE and NOTICE. Core LM pieces adapted from DSRs; see vendor notes.