Skip to content

AI-Maker-Space/DSPyEvent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DSPy GEPA Optimization Tutorial

What is DSPy?

DSPy is a framework for programming—not prompting—language models. Instead of writing brittle prompts that break with model updates, you write modular Python code that DSPy compiles into optimized prompts or finetunes.

Think of it as moving from "prompt engineering" to "prompt programming."

What is GEPA?

GEPA (Generalized Evolutionary Prompt Adaptation) is DSPy's reflective prompt optimizer. It works by:

  1. Running your program on training examples
  2. Analyzing which attempts succeed and which fail
  3. Reflecting on patterns in successes/failures
  4. Evolving the prompt to incorporate winning strategies

As the DSPy documentation puts it: GEPA can "precompute reasoning" to come up with a good plan for future task instances.

About This Notebook

This notebook (dspy-gepa-tutorial.ipynb) provides hands-on experience with DSPy's GEPA optimizer through two practical examples:

Example 1: Chain of Thought Optimization

  • Optimize a simple dspy.ChainOfThought program on AIME (American Invitational Mathematics Examination) problems
  • Learn how GEPA automatically discovers effective problem-solving strategies
  • See 10%+ improvement in accuracy through optimization

Example 2: Agent with Code Execution

  • Build a dspy.ReAct agent with access to a Python code execution tool
  • Learn how GEPA can optimize when and how agents use tools
  • Understand the interplay between reasoning and tool use

Prerequisites

  • Python 3.13+
  • OpenAI API key
  • Basic familiarity with Python

Setup

  1. Install dependencies with uv:
uv sync
  1. Start MLFlow UI (in a separate terminal):
mlflow ui --port 5000 --backend-store-uri sqlite:///mlruns.db
  1. Open the notebook and run the cells:
jupyter notebook dspy-gepa-tutorial.ipynb

What You'll Learn

By the end of this notebook, you'll understand:

  • How to define DSPy programs with Signatures and Modules
  • How to create evaluation metrics (including feedback metrics for GEPA)
  • How to use GEPA to automatically optimize prompts
  • How to build and optimize tool-using agents
  • How to track experiments with MLFlow

References

About

DSPy Prompt Optimization Event

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published