dspy-production-deployment

Solid

This skill should be used when the user asks to "deploy DSPy", "save and load a DSPy program", "configure DSPy cache", "harden pickle cache", "track DSPy token usage", "run DSPy asynchronously", "stream DSPy output", mentions `configure_cache`, `restrict_pickle`, `track_usage`, `acall`, `asyncify`, `streamify`, `StreamListener`, MLflow deployment, or needs production runtime guidance for a DSPy application.

AI & Automation 78 stars 10 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 90/100

Stars 20%
63
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# DSPy Production Deployment ## Goal Prepare a DSPy program for repeatable, observable, scalable, and safer production execution. ## Cache Hardening DSPy enables memory and disk caches by default. Disk cache deserialization uses pickle unless restricted. Enable the allowlist mode in production: ```python import dspy dspy.configure_cache(restrict_pickle=True) ``` Register trusted custom cache types only when needed: ```python dspy.configure_cache( restrict_pickle=True, safe_types=[MyResult, Metadata], ) ``` Disable a cache layer explicitly when a deployment cannot persist data or requires fresh model responses: ```python dspy.configure_cache( enable_disk_cache=False, enable_memory_cache=True, ) ``` ## Save and Load Prefer state-only JSON for readable, safer artifacts: ```python compiled.save("./artifacts/program.json", save_program=False) loaded = MyProgram() loaded.load("./artifacts/program.json") ``` Use whole-program save only for trusted artifacts. It uses cloudpickle: ```python compiled.save("./artifacts/program/", save_program=True) loaded = dspy.load("./artifacts/program/") ``` Keep the DSPy major version compatible when loading saved programs. ## Usage Tracking ```python dspy.configure( lm=dspy.LM("openai/gpt-4o-mini"), track_usage=True, ) prediction = program(question="What is DSPy?") print(prediction.get_lm_usage()) ``` Cached calls return no new token usage. ## Async Execution Most built-in modules support `acall()`: `...

Details

Author
OmidZamani
Repository
OmidZamani/dspy-skills
Created
5 months ago
Last Updated
1 weeks ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category