Dspy (dspy v0.1.0)
View SourceElixir implementation of DSPy - a framework for algorithmically optimizing LM prompts and weights.
DSPy provides a unified interface for composing LM programs with automatic optimization.
Core Components
Dspy.Signature- Define typed input/output interfaces for LM callsDspy.Module- Composable building blocks for LM programsDspy.Predict- Basic prediction modulesDspy.ChainOfThought- Step-by-step reasoningDspy.LM- Language model client abstractionDspy.Example- Training examples and data structuresDspy.Teleprompter- Prompt optimization algorithms
Quick Start
# Configure language model
Dspy.configure(lm: %Dspy.LM.OpenAI{model: "gpt-4.1"})
# Define signature
defmodule QA do
use Dspy.Signature
input_field :question, :string, "Question to answer"
output_field :answer, :string, "Answer to the question"
end
# Create and use module
predict = Dspy.Predict.new(QA)
result = Dspy.Module.forward(predict, %{question: "What is 2+2?"})
Summary
Functions
Configure global DSPy settings.
Create a new Example with the given attributes.
Create a new Prediction with the given attributes.
Get current DSPy configuration.
Functions
Configure global DSPy settings.
Options
:lm- Language model client (required):max_tokens- Maximum tokens per generation (default: 2048):temperature- Sampling temperature (default: 0.0):cache- Enable response caching (default: true)
Create a new Example with the given attributes.
Create a new Prediction with the given attributes.
Get current DSPy configuration.