How haasonsaas/dspy-advanced-prompting works
Project Type and Purpose
• This is an open-source Python library/tool (not a full-stack web app).
• Purpose: Provide reusable modules (“techniques” and “prompts”) built on DSpy and LLMs (e.g., OpenAI), plus an evaluation framework, example scripts, and notebooks.
File Structure
• Top-level directories and files:
• src/ – core Python package
– prompts/ – Manager-style, role prompting, etc.
– techniques/ – escape hatches, few-shot, meta-prompting, etc.
– evaluations/ – evaluation_framework.py
• examples/ – quick_start scripts
• notebooks/ – interactive tutorials
• validate_with_dspy.py, validate_with_real_api.py – validation entry points
• main.py – interactive demo
• setup.py, requirements.txt – packaging & dependencies
• Key config: .env for API keys; .env.example as template.
README Insights
• Underlying runtime: Python + DSpy framework + OpenAI API (config via dspy.settings).
• Architectural patterns:
• Modular design (each technique is a standalone DSpy module)
• Pluggable evaluation framework (TestCase, EvaluationSuite)
• Pipelines (e.g., model_distillation pipeline)
• No web/UI layer – everything is library + CLI + notebooks.
Main Components and Relationships
a. User/Developer
– Runs CLI scripts (validate, main.py, examples)
– Writes custom configs (e.g., ManagerStylePromptConfig)
– Executes notebooks
b. Core Library (src/)
– Prompts Module
– Techniques Module
– Evaluations Module
– Model Distillation Pipeline
c. External Services
– DSpy Framework (imported library dependency)
– LLM API (OpenAI, configured via .env)
d. Examples & Tutorials
– Quick-start scripts (examples/quick_start.py)
– Jupyter notebooks
e. Packaging & Deployment
– setup.py for pip install
– requirements.txt for dependencies
Interactions:
• Developer → runs validate_with_dspy.py → invokes src.evaluations → tests modules without API
• Developer → runs validate_with_real_api.py → src invokes DSpy → OpenAI API
• main.py/examples → import from src.prompts and src.techniques → DSpy.LM call → OpenAI
• Notebooks → import src modules interactively
Architectural Patterns & Design Principles
• Modularity: each prompting technique is a discrete module
• Pluggability: new techniques can be added by dropping in another .py under src/techniques
• Pipeline abstraction: evaluation and distillation pipelines formalize multi-step workflows
• Dependency Injection: DSpy.settings.configure allows swapping LMs
• Separation of concerns: prompts vs. techniques vs. evaluations
Technologies & Frameworks to Call Out
• Python 3.x
• DSpy (core prompting framework)
• OpenAI API (LLM provider)
• Jupyter Notebooks (interactive tutorials)
• pytest (implied by test_notebooks.py)
• Packaging: setuptools via setup.py
Elements
• src.prompts
• src.techniques
• src.evaluations
• DSpy Framework
• OpenAI API
• Examples & Notebooks
• CLI scripts (main.py, validate scripts)
• Developer triggers CLI → loads modules → calls DSpy → hits OpenAI → returns results → evaluation