This directory contains Python script versions of the tutorial notebooks, suitable for running directly or studying the code.
General introduction to Mellea with basic examples.
Email generation example - the classic "Hello World" of Mellea.
Walkthrough of the instruct-validate-repair paradigm.
Tutorial on composing generative functions.
Working with contexts and context management.
Using document MObjects for text processing.
Working with table data structures.
Configuring model options and parameters.
Building a sentiment classification system.
Model Context Protocol integration examples.
Each file in this directory corresponds to a Jupyter notebook in notebooks/:
example.py↔example.ipynbsimple_email.py↔simple_email.ipynbinstruct_validate_repair.py↔instruct_validate_repair.ipynb- etc.
# Run any example directly
python docs/examples/tutorial/simple_email.py
# Or with uv
uv run docs/examples/tutorial/simple_email.pyRecommended order for learning Mellea:
- simple_email.py - Start here for basic concepts
- instruct_validate_repair.py - Core paradigm
- compositionality_with_generative_stubs.py - Building blocks
- context_example.py - Context management
- model_options_example.py - Configuration
- sentiment_classifier.py - Complete application
- document_mobject.py - Working with documents
- table_mobject.py - Working with structured data
- mcp_example.py - Advanced integration
- Sessions: Creating and managing Mellea sessions
- Instructions: Generating text with natural language instructions
- Requirements: Constraining outputs with validation
- Validation: Checking outputs against requirements
- Repair: Automatically fixing invalid outputs
- Generative Stubs: Type-safe LLM functions
- Contexts: Managing conversation and generation history
- Model Options: Configuring model behavior
- MObjects: Working with structured data types
- No Interactive Output: Scripts don't show intermediate results
- Linear Execution: Runs from top to bottom
- Easier to Version Control: Plain Python files
- Better for CI/CD: Can be run in automated pipelines
- Easier to Import: Can import functions from these files
To convert a script to a notebook:
# Install jupytext
uv pip install jupytext
# Convert
jupytext --to notebook docs/examples/tutorial/simple_email.py- See
notebooks/for interactive Jupyter versions - See other example directories for specialized topics
- See main README.md for getting started guide