Dspy (dspy v0.1.0)

View Source

Elixir 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

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(opts \\ [])

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)

example(attrs \\ %{})

Create a new Example with the given attributes.

prediction(attrs \\ %{})

Create a new Prediction with the given attributes.

settings()

Get current DSPy configuration.