Details
DSPy is a declarative framework for building modular AI software. It allows you to iterate fast on structured code, rather than brittle strings, and offers algorithms that compile AI programs into effective prompts and weights for your language models, whether you're building simple classifiers, sophisticated RAG pipelines, or Agent loops.
Instead of wrangling prompts or training jobs, DSPy (Declarative Self-improving Python) enables you to build AI software from natural-language modules and to generically compose them with different models, inference strategies, or learning algorithms. This makes AI software more reliable, maintainable, and portable across models and strategies.
Table of Contents
- Setup and Bootstrapping DSPy
- LLM powered Q&A Machine
- Key DSPy concepts via code snippets
Core Concepts
- Signatures & Optimizers
- Modules (e.g., Predict, ChainOfThought, ReAct, ProgramOfThought, MultiChainComparison)
- Pipelines / Text-transformation graphs
- Teleprompter
- Optimizers (prompt & weight optimizers)
- Compiler (declarative-to-prompt/train code compiler)
- Self‑improving (bootstrapping prompts/weights via feedback)
- Assertions (computational constraints for module outputs)
- Metrics (for evaluation and optimization targets)
- Adapters (model-specific formatters and parser logic)
- Inference strategies (e.g., few-shot, chain-of-thought, ReAct)
Design Principles
- Composability / Modularity
- Model agnosticism (swap models without rewrites)
- End-to-end application building