Skip to content

krypticmouse/DSRs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

DSRs

A high-performance DSPy rewrite in Rust for building LLM-powered applications

License Rust Build Status


🚀 Overview

DSRs (DSPy Rust) is a ground-up rewrite of the DSPy framework in Rust, designed for building robust, high-performance applications powered by Language Models. Unlike a simple port, DSRs leverages Rust's type system, memory safety, and concurrency features to provide a more efficient and reliable foundation for LLM applications.

📦 Installation

Add DSRs to your Cargo.toml:

[dependencies]
# Option 1: Use the shorter alias (recommended)
dsrs = { package = "dspy-rs", version = "0.0.2-beta" }

# Option 2: Use the full name
dspy-rs = "0.0.2-beta"

Or use cargo:

# Option 1: Add with alias (recommended)
cargo add dsrs --package dspy-rs

# Option 2: Add with full name
cargo add dspy-rs

🔧 Quick Start

Here's a simple example to get you started:

use dsrs::prelude::*;
use std::collections::HashMap;
use indexmap::IndexMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Define a signature for Q&A
    let signature = Signature::builder()
        .name("QASignature".to_string())
        .instruction("Answer the question concisely and accurately.".to_string())
        .input_fields(IndexMap::from([(
            "question".to_string(),
            Field::InputField {
                prefix: "Question:".to_string(),
                desc: "The question to answer".to_string(),
                format: None,
                output_type: "String".to_string(),
            },
        )]))
        .output_fields(IndexMap::from([(
            "answer".to_string(),
            Field::OutputField {
                prefix: "Answer:".to_string(),
                desc: "The answer to the question".to_string(),
                format: None,
                output_type: "String".to_string(),
            },
        )]))
        .build()?;

    // Create a predictor
    let predictor = Predict { 
        signature: &signature 
    };

    // Prepare input
    let inputs = HashMap::from([
        ("question".to_string(), "What is the capital of France?".to_string())
    ]);

    // Execute prediction
    let result = predictor.forward(inputs, None, None).await?;
    
    println!("Answer: {}", result.get("answer", None));

    Ok(())
}

🧪 Testing

Run the test suite:

# All tests
cargo test

# Specific test
cargo test test_predictors

# With output
cargo test -- --nocapture

📈 Project Status

⚠️ Early Development - DSRs is actively being developed. The API may change between versions.

Core Framework

  • Metrics traits and Evaluators
  • Signature Macros
  • Structured Output Parsing
  • Adding More Predictors
    • dsrs.Refine
    • dsrs.BestOfN
    • dsrs.Retry
  • Retriever Module Support

LM Integrations

  • Ability to use native provider keys for popular clients

Data Management

  • Example Macros
  • Support for data loading from sources

Performance Optimizations

  • Batch processing for LM calls
  • Batch Input support for Module
  • Memory Analysis and Optimization
  • Caching Support for Providers
  • Performance benchmarking b/w DSPy and DSRs

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by the original DSPy framework
  • Built with the amazing Rust ecosystem

About

A DSPy rewrite to(not port) Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages