Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 17 additions & 169 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# dspy-cli

Deploy DSPy programs as HTTP APIs with standard containerization, routing, and OpenAPI specifications. Setup time: 3-5 minutes.
CLI for deploying DSPy programs as HTTP APIs. Auto-generates endpoints, OpenAPI specs, and Docker configs.

**For:** Developers embedding AI features in existing applications (Chrome extensions, Notion automations, web apps) who need HTTP endpoints without manual infrastructure work.

**Problem:** Prototype DSPy modules work locally but require Docker configs, API boilerplate, and route management to deploy. This creates friction between development and production.

**Solution:** Convention-based project structure with auto-discovery. Define signatures, implement modules, deploy. Infrastructure handled automatically.
Reduces deployment setup from hours to minutes for developers embedding LLM features in applications.

## Quick Start

Expand Down Expand Up @@ -40,177 +36,29 @@ Response:

## Features

- **Auto-discovery** - Modules in `src/*/modules/` automatically exposed as HTTP endpoints
- **Standard containers** - Docker image generation with FastAPI server included
- **OpenAPI specs** - Auto-generated from DSPy signatures for integration with tools and clients
- **Hot reload** - Edit modules without restarting the development server
- **Model configuration** - Switch LLMs via config file without code changes
- **MCP tool integration** - Served programs work as MCP tools for AI assistants
- **Convention-based structure** - Organized directories for modules, signatures, optimizers, metrics

## Project Structure

```
my-project/
├── pyproject.toml
├── dspy.config.yaml # Model registry and configuration
├── .env # API keys and secrets
├── README.md
├── src/
│ └── dspy_project/ # Importable package
│ ├── __init__.py
│ ├── modules/ # DSPy program implementations
│ ├── signatures/ # Reusable signatures
│ ├── optimizers/ # Optimizer configurations
│ ├── metrics/ # Evaluation metrics
│ └── utils/ # Shared helpers
├── data/
├── logs/
└── tests/
```
- Auto-discovery of modules as HTTP endpoints
- Docker configs and OpenAPI specs generated
- Hot reload development server
- Model switching via config file
- MCP tool support

## Commands

### Create Project

```bash
dspy-cli new PROJECT_NAME [OPTIONS]
```

Options:
- `-s, --signature TEXT` - Inline signature (e.g., `"question -> answer"`)
- `-p, --program-name TEXT` - Initial program name

### Generate Components

```bash
dspy-cli generate scaffold PROGRAM_NAME [OPTIONS]
```

Options:
- `-m, --module TEXT` - Module type (`Predict`, `ChainOfThought`, `ReAct`)
- `-s, --signature TEXT` - Inline signature (e.g. "question -> answer")

### Serve Locally

```bash
dspy-cli serve [--port PORT] [--host HOST]
```

Auto-generated endpoints:
- `GET /programs` - List all programs with schemas
- `POST /{program}` - Execute program with JSON payload

### Deploy

```bash
flyctl launch
flyctl secrets set OPENAI_API_KEY=your-key-here
flyctl deploy
```

See [Deployment Guide](docs/deployment.md) for detailed instructions and other platforms.

## Configuration

### Model Settings

`dspy.config.yaml`:

```yaml
models:
default: openai:gpt-4o-mini
registry:
openai:gpt-4o-mini:
model: openai/gpt-4o-mini
env: OPENAI_API_KEY
max_tokens: 16000
temperature: 1.0
model_type: chat

# Per-program overrides
program_models:
MySpecialProgram: anthropic:sonnet-4-5
```

### Environment Variables

`.env`:

```
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
```

See [Configuration Guide](docs/configuration.md) for complete settings reference.

## Integration Examples

### Chrome Extension

```javascript
async function summarizePage(content) {
const response = await fetch('https://your-app.fly.dev/summarizer', {
method: 'POST',
body: JSON.stringify({ content }),
headers: { 'Content-Type': 'application/json' }
});
return response.json();
}
```

### Python Client

```python
import requests

def tag_content(page_content):
response = requests.post(
'https://your-app.fly.dev/BlogTaggerPredict',
json={'post': page_content}
)
return response.json()['tags']
```

### JavaScript/TypeScript

```javascript
fetch('https://your-app.fly.dev/analyzer', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: document.body.innerText,
context: ['documentation', 'technical']
})
})
.then(res => res.json())
.then(data => console.log(data.summary, data.sentiment));
```

## Development Installation

For contributing or testing dspy-cli itself:

```bash
cd /path/to/dspy-cli
uv sync --extra dev
dspy-cli --help
dspy-cli new <name> [-s "input -> output"] # Create project
dspy-cli serve [--ui] # Start HTTP server
dspy-cli g scaffold <program> [-m CoT] # Add module to project
Comment on lines 47 to +50
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove nonexistent --ui flag from Quick Start command

The Quick Start now recommends running dspy-cli serve [--ui], but the serve command no longer defines a --ui option—the CLI always starts the web UI and unrecognized flags will cause Click to exit with an error. The options list in src/dspy_cli/commands/serve.py shows the only accepted flags and none mention --ui. Users following the README will hit a failure before getting the server running.

Useful? React with 👍 / 👎.

```

Run tests:

```bash
cd dspy-cli
uv run pytest
```
See [Command Reference](docs/commands/) for complete documentation.

## Next Steps
## Documentation

- [Architecture Overview](docs/architecture.md) - Project structure and design decisions
- [CLI Reference](docs/cli-reference.md) - Complete command documentation
- [Configuration Guide](docs/configuration.md) - Model settings and environment variables
- [Deployment Guide](docs/deployment.md) - Production deployment workflows
- [MCP Integration](docs/mcp-integration.md) - Using with AI assistants
- [Getting Started](docs/getting-started.md) - Quickstart guide
- [Commands](docs/commands/) - CLI reference
- [Deployment](docs/deployment.md) - Production deployment
- [Configuration](docs/configuration.md) - Model and environment settings
- [Examples](examples/) - Sample projects

## License

Expand Down
Loading