Skip to content

Commit 0e0d311

Browse files
williamcabanclaude
andcommitted
feat: Add MLflow Prompt Registry provider (squashed commit)
Add a new remote provider that integrates MLflow's Prompt Registry with Llama Stack's prompts API, enabling centralized prompt management and versioning using MLflow as the backend. Features: - Full implementation of Llama Stack Prompts protocol - Support for prompt versioning and default version management - Automatic variable extraction from Jinja2-style templates - MLflow tag-based metadata for efficient prompt filtering - Flexible authentication (config, environment variables, per-request) - Bidirectional ID mapping (pmpt_<hex> ↔ llama_prompt_<hex>) - Comprehensive error handling and validation Implementation: - Remote provider: src/llama_stack/providers/remote/prompts/mlflow/ - Inline reference provider: src/llama_stack/providers/inline/prompts/reference/ - MLflow 3.4+ required for Prompt Registry API support - Deterministic ID mapping ensures consistency across conversions Testing: - 15 comprehensive unit tests (config validation, ID mapping) - 18 end-to-end integration tests (full CRUD workflows) - GitHub Actions workflow for automated CI testing with MLflow server - Integration test fixtures with automatic server setup Documentation: - Complete provider configuration reference - Setup and usage examples with code samples - Authentication options and security best practices Signed-off-by: William Caban <[email protected]> Co-Authored-By: Claude <[email protected]>
1 parent aac494c commit 0e0d311

File tree

24 files changed

+3598
-229
lines changed

24 files changed

+3598
-229
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: MLflow Prompts Integration Tests
2+
3+
run-name: Run the integration test suite with MLflow Prompt Registry provider
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
- 'release-[0-9]+.[0-9]+.x'
10+
pull_request:
11+
branches:
12+
- main
13+
- 'release-[0-9]+.[0-9]+.x'
14+
paths:
15+
- 'src/llama_stack/providers/remote/prompts/mlflow/**'
16+
- 'tests/integration/providers/remote/prompts/mlflow/**'
17+
- 'tests/unit/providers/remote/prompts/mlflow/**'
18+
- 'uv.lock'
19+
- 'pyproject.toml'
20+
- 'requirements.txt'
21+
- '.github/workflows/integration-mlflow-tests.yml' # This workflow
22+
schedule:
23+
- cron: '0 0 * * *' # Daily at 12 AM UTC
24+
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
test-mlflow:
31+
runs-on: ubuntu-latest
32+
strategy:
33+
matrix:
34+
python-version: ${{ github.event.schedule == '0 0 * * *' && fromJSON('["3.12", "3.13"]') || fromJSON('["3.12"]') }}
35+
fail-fast: false
36+
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
40+
41+
- name: Install dependencies
42+
uses: ./.github/actions/setup-runner
43+
with:
44+
python-version: ${{ matrix.python-version }}
45+
46+
- name: Setup MLflow Server
47+
run: |
48+
docker run --rm -d --pull always \
49+
--name mlflow \
50+
-p 5555:5555 \
51+
ghcr.io/mlflow/mlflow:latest \
52+
mlflow server \
53+
--host 0.0.0.0 \
54+
--port 5555 \
55+
--backend-store-uri sqlite:///mlflow.db \
56+
--default-artifact-root ./mlruns
57+
58+
- name: Wait for MLflow to be ready
59+
run: |
60+
echo "Waiting for MLflow to be ready..."
61+
for i in {1..60}; do
62+
if curl -s http://localhost:5555/health | grep -q '"status": "OK"'; then
63+
echo "MLflow is ready!"
64+
exit 0
65+
fi
66+
echo "Not ready yet... ($i/60)"
67+
sleep 2
68+
done
69+
echo "MLflow failed to start"
70+
docker logs mlflow
71+
exit 1
72+
73+
- name: Verify MLflow API
74+
run: |
75+
echo "Testing MLflow API..."
76+
curl -X GET http://localhost:5555/api/2.0/mlflow/experiments/list
77+
echo ""
78+
echo "MLflow API is responding!"
79+
80+
- name: Build Llama Stack
81+
run: |
82+
uv run --no-sync llama stack list-deps ci-tests | xargs -L1 uv pip install
83+
84+
- name: Install MLflow Python client
85+
run: |
86+
uv pip install 'mlflow>=3.4.0'
87+
88+
- name: Check Storage and Memory Available Before Tests
89+
if: ${{ always() }}
90+
run: |
91+
free -h
92+
df -h
93+
94+
- name: Run MLflow Integration Tests
95+
env:
96+
MLFLOW_TRACKING_URI: http://localhost:5555
97+
run: |
98+
uv run --no-sync \
99+
pytest -sv \
100+
tests/integration/providers/remote/prompts/mlflow/
101+
102+
- name: Check Storage and Memory Available After Tests
103+
if: ${{ always() }}
104+
run: |
105+
free -h
106+
df -h
107+
108+
- name: Write MLflow logs to file
109+
if: ${{ always() }}
110+
run: |
111+
docker logs mlflow > mlflow.log 2>&1 || true
112+
113+
- name: Upload all logs to artifacts
114+
if: ${{ always() }}
115+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
116+
with:
117+
name: mlflow-logs-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.python-version }}
118+
path: |
119+
*.log
120+
retention-days: 1
121+
122+
- name: Stop MLflow container
123+
if: ${{ always() }}
124+
run: |
125+
docker stop mlflow || true
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
sidebar_label: Prompts
3+
title: Prompts
4+
---
5+
6+
# Prompts
7+
8+
## Overview
9+
10+
This section contains documentation for all available providers for the **prompts** API.
11+
12+
The Prompts API enables centralized management of prompt templates with versioning, variable handling, and team collaboration capabilities.
13+
14+
## Available Providers
15+
16+
### Inline Providers
17+
18+
Inline providers run in the same process as the Llama Stack server and require no external dependencies:
19+
20+
- **[inline::reference](inline_reference.mdx)** - Reference implementation using KVStore backend (SQLite, PostgreSQL, etc.)
21+
- Zero external dependencies
22+
- Supports local SQLite or PostgreSQL storage
23+
- Full CRUD operations including deletion
24+
- Ideal for local development and single-server deployments
25+
26+
### Remote Providers
27+
28+
Remote providers connect to external services for centralized prompt management:
29+
30+
- **[remote::mlflow](remote_mlflow.mdx)** - MLflow Prompt Registry integration (requires MLflow 3.4+)
31+
- Centralized prompt management across teams
32+
- Built-in versioning and audit trail
33+
- Supports authentication (per-request, config, or environment variables)
34+
- Integrates with Databricks and enterprise MLflow deployments
35+
- Ideal for team collaboration and production environments
36+
37+
## Choosing a Provider
38+
39+
### Use `inline::reference` when:
40+
- Developing locally or deploying to a single server
41+
- You want zero external dependencies
42+
- SQLite or PostgreSQL storage is sufficient
43+
- You need full CRUD operations (including deletion)
44+
- You prefer simple configuration
45+
46+
### Use `remote::mlflow` when:
47+
- Working in a team environment with multiple users
48+
- You need centralized prompt management
49+
- Integration with existing MLflow infrastructure
50+
- You need authentication and multi-tenant support
51+
- Advanced versioning and audit trail capabilities are required
52+
53+
## Quick Start Examples
54+
55+
### Using inline::reference
56+
57+
```yaml
58+
prompts:
59+
- provider_id: local-prompts
60+
provider_type: inline::reference
61+
config:
62+
run_config:
63+
storage:
64+
stores:
65+
prompts:
66+
type: sqlite
67+
db_path: ./prompts.db
68+
```
69+
70+
### Using remote::mlflow
71+
72+
```yaml
73+
prompts:
74+
- provider_id: mlflow-prompts
75+
provider_type: remote::mlflow
76+
config:
77+
mlflow_tracking_uri: http://localhost:5555
78+
experiment_name: llama-stack-prompts
79+
auth_credential: ${env.MLFLOW_TRACKING_TOKEN}
80+
```
81+
82+
## Common Features
83+
84+
All prompt providers support:
85+
- Create and store prompts with version control
86+
- Retrieve prompts by ID and version
87+
- Update prompts (creates new versions)
88+
- List all prompts or versions of a specific prompt
89+
- Set default version for a prompt
90+
- Automatic variable extraction from `{{ variable }}` templates
91+
92+
For detailed documentation on each provider, see the individual provider pages linked above.

0 commit comments

Comments
 (0)