Getting Started with DSPy.rb
Welcome to DSPy.rb! This guide will help you get up and running with building reliable LLM applications in Ruby.
What is DSPy.rb?
DSPy.rb is a Ruby framework for building predictable LLM applications using composable, type-safe modules. Instead of wrestling with prompt engineering, you define clear interfaces and let the framework handle the complexity.
Key Features
- Type-safe interfaces using Sorbet for compile-time checking
- Composable modules for building complex reasoning chains
- Systematic testing with comprehensive test coverage
- Production-ready with Rails and Ruby ecosystem integration
Quick Example
Here’s a simple example of defining an LLM interface with DSPy.rb:
class EmailCategory < T::Enum
enums do
Technical = new('technical')
Billing = new('billing')
General = new('general')
end
end
class EmailClassifier < DSPy::Signature
input do
const :subject, String
const :body, String
end
output do
const :category, EmailCategory
const :confidence, Float
end
end
# Use the classifier
classifier = DSPy::Predict.new(EmailClassifier)
result = classifier.call(
subject: "Invoice for March 2024",
body: "Please find attached your invoice..."
)
puts result.category # => EmailCategory::Billing
puts result.confidence # => 0.95