Skip to content

Commit 4d3b7ea

Browse files
committed
rewrite docs
1 parent c0dc08b commit 4d3b7ea

File tree

9 files changed

+1965
-519
lines changed

9 files changed

+1965
-519
lines changed

README.md

Lines changed: 121 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,55 @@
11
# dspy-cli
22

3-
A command-line interface tool for creating and serving DSPy projects, inspired by Ruby on Rails.
3+
Deploy DSPy programs as HTTP APIs with standard containerization, routing, and OpenAPI specifications. Setup time: 3-5 minutes.
44

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

7-
```bash
8-
uv add dspy-cli
9-
```
10-
11-
### Installing for Development/Testing
12-
13-
If you're testing or developing dspy-cli itself:
7+
**Problem:** Prototype DSPy modules work locally but require Docker configs, API boilerplate, and route management to deploy. This creates friction between development and production.
148

15-
```bash
16-
# Clone or navigate to the dspy-cli repository
17-
cd /path/to/dspy-cli
18-
19-
# Sync dependencies
20-
uv sync --extra dev
21-
22-
# Now the dspy-cli command is available
23-
dspy-cli --help
24-
```
9+
**Solution:** Convention-based project structure with auto-discovery. Define signatures, implement modules, deploy. Infrastructure handled automatically.
2510

2611
## Quick Start
2712

28-
### Create a new DSPy project
29-
3013
```bash
31-
dspy-cli new my-project
32-
cd my-project
33-
```
14+
# Install
15+
uv tool install dspy-cli
3416

35-
### Create a project with a custom program name
17+
# Create project
18+
dspy-cli new blog-tagger -s "post -> tags: list[str]"
19+
cd blog-tagger
3620

37-
```bash
38-
dspy-cli new my-project -p custom_program
21+
# Serve locally
22+
dspy-cli serve
3923
```
4024

41-
### Create a project with a custom signature
25+
Test the endpoint:
4226

4327
```bash
44-
dspy-cli new blog-tagger -s "post -> tags: list[str]"
28+
curl -X POST http://localhost:8000/BlogTaggerPredict \
29+
-H "Content-Type: application/json" \
30+
-d '{"post": "How to build Chrome extensions with AI..."}'
4531
```
4632

47-
### Serve your DSPy programs as an API
33+
Response:
4834

49-
```bash
50-
dspy-cli serve --port 8000 --host 0.0.0.0
35+
```json
36+
{
37+
"tags": ["chrome-extensions", "ai", "development", "javascript"]
38+
}
5139
```
5240

5341
## Features
5442

55-
- **Project scaffolding**: Generate a complete DSPy project structure with boilerplate code
56-
- **Code generation**: Quickly scaffold new DSPy programs with signatures and modules using Rails-style generators
57-
- **Convention over configuration**: Organized directory structure for modules, signatures, optimizers, and metrics
58-
- **HTTP API server**: Automatically serve your DSPy programs as REST endpoints
59-
- **Flexible configuration**: YAML-based model configuration with environment variable support
60-
- **Logging**: Request logging to both STDOUT and per-module log files
43+
- **Auto-discovery** - Modules in `src/*/modules/` automatically exposed as HTTP endpoints
44+
- **Standard containers** - Docker image generation with FastAPI server included
45+
- **OpenAPI specs** - Auto-generated from DSPy signatures for integration with tools and clients
46+
- **Hot reload** - Edit modules without restarting the development server
47+
- **Model configuration** - Switch LLMs via config file without code changes
48+
- **MCP tool integration** - Served programs work as MCP tools for AI assistants
49+
- **Convention-based structure** - Organized directories for modules, signatures, optimizers, metrics
6150

6251
## Project Structure
6352

64-
When you create a new project, dspy-cli generates the following structure:
65-
6653
```
6754
my-project/
6855
├── pyproject.toml
@@ -84,85 +71,51 @@ my-project/
8471

8572
## Commands
8673

87-
### `new`
88-
89-
Create a new DSPy project with boilerplate structure.
74+
### Create Project
9075

9176
```bash
92-
dspy-cli new [PROJECT_NAME] [OPTIONS]
77+
dspy-cli new PROJECT_NAME [OPTIONS]
9378
```
9479

95-
**Options:**
96-
- `-p, --program-name TEXT`: Name of the initial program (default: converts project name)
97-
- `-s, --signature TEXT`: Inline signature string (e.g., `"question -> answer"` or `"post -> tags: list[str]"`)
80+
Options:
81+
- `-s, --signature TEXT` - Inline signature (e.g., `"question -> answer"`)
82+
- `-p, --program-name TEXT` - Initial program name
9883

99-
**Examples:**
100-
101-
```bash
102-
# Basic project
103-
dspy-cli new my-project
104-
105-
# With custom program name
106-
dspy-cli new my-project -p custom_program
107-
108-
# With custom signature
109-
dspy-cli new blog-tagger -s "post -> tags: list[str]"
110-
111-
# With both program name and signature
112-
dspy-cli new analyzer -p text_analyzer -s "text, context: list[str] -> summary, sentiment: bool"
113-
```
114-
115-
### `generate` (alias: `g`)
116-
117-
Generate new components in an existing DSPy project.
84+
### Generate Components
11885

11986
```bash
12087
dspy-cli generate scaffold PROGRAM_NAME [OPTIONS]
121-
dspy-cli g scaffold PROGRAM_NAME [OPTIONS]
12288
```
12389

124-
**Options:**
125-
- `-m, --module TEXT`: DSPy module type to use (default: Predict)
126-
- Available: `Predict`, `ChainOfThought` (or `CoT`), `ProgramOfThought` (or `PoT`), `ReAct`, `MultiChainComparison`, `Refine`
127-
- `-s, --signature TEXT`: Inline signature string (e.g., `"question -> answer"`)
90+
Options:
91+
- `-m, --module TEXT` - Module type (`Predict`, `ChainOfThought`, `ReAct`)
92+
- `-s, --signature TEXT` - Inline signature (e.g. "question -> answer")
12893

129-
**Examples:**
94+
### Serve Locally
13095

13196
```bash
132-
# Basic scaffold with default Predict module
133-
dspy-cli g scaffold categorizer
134-
135-
# Scaffold with ChainOfThought
136-
dspy-cli g scaffold categorizer -m CoT
137-
138-
# Scaffold with custom signature
139-
dspy-cli g scaffold qa -m CoT -s "question -> answer"
140-
141-
# Complex signature with types
142-
dspy-cli g scaffold search -s "query, context: list[str] -> answer, confidence: float"
97+
dspy-cli serve [--port PORT] [--host HOST]
14398
```
14499

145-
### `serve`
100+
Auto-generated endpoints:
101+
- `GET /programs` - List all programs with schemas
102+
- `POST /{program}` - Execute program with JSON payload
146103

147-
Start an HTTP API server that exposes your DSPy programs.
104+
### Deploy
148105

149106
```bash
150-
dspy-cli serve [OPTIONS]
107+
flyctl launch
108+
flyctl secrets set OPENAI_API_KEY=your-key-here
109+
flyctl deploy
151110
```
152111

153-
**Options:**
154-
- `--port INTEGER`: Port to run the server on (default: 8000)
155-
- `--host TEXT`: Host to bind to (default: 0.0.0.0)
156-
157-
**Endpoints:**
158-
- `GET /programs`: List all discovered programs with their schemas
159-
- `POST /{program}`: Execute a program with JSON payload
112+
See [Deployment Guide](docs/deployment.md) for detailed instructions and other platforms.
160113

161114
## Configuration
162115

163-
### dspy.config.yaml
116+
### Model Settings
164117

165-
Configure your language models and routing:
118+
`dspy.config.yaml`:
166119

167120
```yaml
168121
models:
@@ -174,25 +127,91 @@ models:
174127
max_tokens: 16000
175128
temperature: 1.0
176129
model_type: chat
177-
anthropic:sonnet-4-5:
178-
model: anthropic/claude-sonnet-4-5
179-
env: ANTHROPIC_API_KEY
180-
model_type: chat
181130

182-
# Optional: per-program model overrides
131+
# Per-program overrides
183132
program_models:
184133
MySpecialProgram: anthropic:sonnet-4-5
185134
```
186135
187-
### .env
136+
### Environment Variables
188137
189-
Store your API keys and secrets:
138+
`.env`:
190139

191140
```
192141
OPENAI_API_KEY=sk-...
193142
ANTHROPIC_API_KEY=sk-ant-...
194143
```
195144
145+
See [Configuration Guide](docs/configuration.md) for complete settings reference.
146+
147+
## Integration Examples
148+
149+
### Chrome Extension
150+
151+
```javascript
152+
async function summarizePage(content) {
153+
const response = await fetch('https://your-app.fly.dev/summarizer', {
154+
method: 'POST',
155+
body: JSON.stringify({ content }),
156+
headers: { 'Content-Type': 'application/json' }
157+
});
158+
return response.json();
159+
}
160+
```
161+
162+
### Python Client
163+
164+
```python
165+
import requests
166+
167+
def tag_content(page_content):
168+
response = requests.post(
169+
'https://your-app.fly.dev/BlogTaggerPredict',
170+
json={'post': page_content}
171+
)
172+
return response.json()['tags']
173+
```
174+
175+
### JavaScript/TypeScript
176+
177+
```javascript
178+
fetch('https://your-app.fly.dev/analyzer', {
179+
method: 'POST',
180+
headers: { 'Content-Type': 'application/json' },
181+
body: JSON.stringify({
182+
text: document.body.innerText,
183+
context: ['documentation', 'technical']
184+
})
185+
})
186+
.then(res => res.json())
187+
.then(data => console.log(data.summary, data.sentiment));
188+
```
189+
190+
## Development Installation
191+
192+
For contributing or testing dspy-cli itself:
193+
194+
```bash
195+
cd /path/to/dspy-cli
196+
uv sync --extra dev
197+
dspy-cli --help
198+
```
199+
200+
Run tests:
201+
202+
```bash
203+
cd dspy-cli
204+
uv run pytest
205+
```
206+
207+
## Next Steps
208+
209+
- [Architecture Overview](docs/architecture.md) - Project structure and design decisions
210+
- [CLI Reference](docs/cli-reference.md) - Complete command documentation
211+
- [Configuration Guide](docs/configuration.md) - Model settings and environment variables
212+
- [Deployment Guide](docs/deployment.md) - Production deployment workflows
213+
- [MCP Integration](docs/mcp-integration.md) - Using with AI assistants
214+
196215
## License
197216

198217
MIT

0 commit comments

Comments
 (0)