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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# dspy-cli

[![Documentation](https://img.shields.io/badge/docs-cmpnd--ai.github.io-blue)](https://cmpnd-ai.github.io/dspy-cli-tool/)
[![Documentation](https://img.shields.io/badge/docs-cmpnd--ai.github.io-blue)](https://cmpnd-ai.github.io/dspy-cli/)
[![PyPI](https://img.shields.io/pypi/v/dspy-cli)](https://pypi.org/project/dspy-cli/)

`dspy-cli` is a tool for creating, developing, testing, and deploying [DSPy](https://dspy.ai) programs as HTTP APIs. `dspy-cli` auto-generates endpoints, OpenAPI specs, and Docker configs.
Expand Down Expand Up @@ -203,7 +203,7 @@ We've built out a lot of quality of life features in `dspy-cli`, including:
- **MCP tool support:** Pass in `--mcp` while calling `serve` to stand up an MCP server for your program.
- **Docker configuration:** Running `new` creates a Dockerfile, which can be used to quickly stand up your program in Docker.

Check out [the full docs](https://cmpnd-ai.github.io/dspy-cli-tool/) to learn more.
Check out [the full docs](https://cmpnd-ai.github.io/dspy-cli/) to learn more.

### License

Expand Down
5 changes: 5 additions & 0 deletions docs/OPENAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ description: A set of functions for a content management system.
```

Fallback defaults if not specified:

- **title**: "DSPy API"
- **description**: "Automatically generated API for DSPy programs"
- **version**: "0.1.0"
Expand Down Expand Up @@ -96,6 +97,7 @@ spec = generate_openapi_spec(app)
### Interactive Documentation

FastAPI provides:

- **Swagger UI**: `http://localhost:8000/docs`
- **ReDoc**: `http://localhost:8000/redoc`

Expand Down Expand Up @@ -132,16 +134,19 @@ Options:
## Troubleshooting

**Spec not generated:**

1. Verify `--no-save-openapi` wasn't used
2. Check write permissions
3. Check server logs

**Missing program schemas:**

1. Ensure modules subclass `dspy.Module`
2. Verify `forward()` has type annotations
3. Check modules are in `src/<package>/modules/`

**Incorrect metadata:**

1. Check `app_id` in `dspy.config.yaml`
2. Verify `description` field
3. Ensure config file is in project root
Expand Down
2 changes: 2 additions & 0 deletions docs/commands/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ dspy-cli g scaffold agent -m ReAct -s "task, tools: list[str] -> action, result"
## Output Structure

Creates two files:

- `signatures/{name}.py` - Input/output schema
- `modules/{name}_{type}.py` - Module implementation (e.g., analyzer_predict.py, reasoner_cot.py)

## Endpoint Naming

Endpoints are derived from the generated module class name. For example:

- **Predict**: `analyzer` → `AnalyzerPredict` → `POST /AnalyzerPredict`
- **CoT**: `reasoner -m CoT` → `ReasonerCoT` → `POST /ReasonerCoT`
- **ReAct**: `agent -m ReAct` → `AgentReAct` → `POST /AgentReAct`
Expand Down
63 changes: 38 additions & 25 deletions docs/commands/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ dspy-cli new email-summarizer -s "email: str -> summary: str, key_points: list[s

# Specify program name
dspy-cli new notion-tools -p emoji_picker -s "context: str -> emoji: str"

# Specify module type and model
dspy-cli new chat-bot -m CoT --model anthropic/claude-3-sonnet
```

## Description
Expand All @@ -31,14 +34,47 @@ Creates project with standard directory layout, dependency configuration, and in
|--------|-------|---------|-------------|
| `--program-name` | `-p` | Derived from project name | Name of initial program module |
| `--signature` | `-s` | `question -> answer` | Input/output signature defining the program interface |
| `--module-type` | `-m` | `Predict` | DSPy module type (Predict, CoT, ReAct, etc.) |
| `--model` | - | `openai/gpt-5-mini` | LLM model string (e.g. `openai/gpt-4o`) |
| `--api-key` | - | - | API key for the LLM provider |

## Arguments

- `PROJECT_NAME` - Name of the project directory to create (required)

## Generated Structure
## Interactive Mode

Running `dspy-cli new` without arguments will start an interactive mode where you can specify the project name, program name, signature, module type, and model.

Expected Outputs:

```
What is your project name? [my-project]: email-subject
Would you like to specify your first program? [Y/n]: Y
What is the name of your first DSPy program? [my_program]: email_subject
Choose a module type:
1. Predict - Basic prediction module (default)
2. ChainOfThought (CoT) - Step-by-step reasoning with chain of thought
3. ProgramOfThought (PoT) - Generates and executes code for reasoning
4. ReAct - Reasoning and acting with tools
5. MultiChainComparison - Compare multiple reasoning paths
6. Refine - Iterative refinement of outputs
Enter number or name [1]: 1
Enter your signature or type '?' for guided input:
Examples: 'question -> answer', 'post:str -> tags:list[str], category:str'
Signature [question:str -> answer:str]: body, sender, context -> subject, tone, priority
Enter your model (LiteLLM format):
Examples: 'anthropic/claude-sonnet-4-5', 'openai/gpt-4o', 'ollama/llama2'
Model [openai/gpt-5-mini]: openai/gpt-5-mini
Enter your OpenAI API key:
(This will be stored in .env as OPENAI_API_KEY)
Press Enter to skip and set it manually later
OPENAI_API_KEY: your_key_here
```

## Generated Structure

```bash
my-feature/
├── src/
│ └── my_feature/
Expand All @@ -60,29 +96,6 @@ my-feature/

Format: `input -> output` with optional type annotations. See [dspy-cli generate](generate.md) for complete syntax reference.

## Examples

### Email Summarizer

```bash
dspy-cli new email-summarizer -s "email: str -> summary: str, key_points: list[str]"
```

Generates:
- Signature: `EmailSummarizerSignature` with `email` input, `summary` and `key_points` outputs
- Module: `EmailSummarizerPredict`
- Endpoint: `/EmailSummarizerPredict`

### Multi-Input Analyzer

```bash
dspy-cli new code-reviewer -s "code: str, language: str -> issues: list[str], suggestions: str"
```

Creates module accepting two inputs (`code`, `language`) and returning two outputs (`issues`, `suggestions`).

### Custom Program Name

```bash
dspy-cli new blog-tools -p tagger -s "blog_post: str -> tags: list[str]"
```
Expand All @@ -93,7 +106,7 @@ Project named `blog-tools`, initial program named `TaggerPredict`. Additional pr

1. Configure `.env` with API key
2. Install dependencies: `uv sync`
3. Start server: `dspy-cli serve --ui`
3. Start server: `dspy-cli serve`

## See Also

Expand Down
5 changes: 4 additions & 1 deletion docs/commands/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Every deployment provides:
| `/openapi.json` | GET | OpenAPI specification |

With `--mcp` enabled:

- `/mcp` provides Model Context Protocol server

## Logging
Expand All @@ -72,7 +73,9 @@ Logs to console by default. Use `--logs-dir` to write per-module JSON logs with
dspy-cli serve
```

Server starts on `http://localhost:8000`. Call modules:
Assuming that there exists a module with the name `SummarizerPredict`, and it has a signature of `blog_post, summary_length, tone -> summary`.

The server starts on `http://localhost:8000`. Call `SummarizerPredict`:

```bash
curl -X POST http://localhost:8000/SummarizerPredict \
Expand Down
35 changes: 15 additions & 20 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,24 @@ program_models:

## Fields

**`app_id`** (required) - Unique identifier

**`models.default`** (required) - Default model alias

**`models.registry`** (required) - Available models
| Field | Required | Description |
|-------|----------|-------------|
| `app_id` | Yes | Unique identifier |
| `models.default` | Yes | Default model alias |
| `models.registry` | Yes | Available models |
| `program_models` | No | Per-program model overrides |

### Registry Entry

**`model`** (required) - Provider/model name (e.g., `openai/gpt-5-mini`)

**`env`** (optional) - Environment variable for API key

**`api_key`** (optional) - Direct API key (use `env` for security)

**`api_base`** (optional) - Custom API endpoint

**`max_tokens`** (optional) - Max response tokens

**`temperature`** (optional) - Sampling temperature (0.0-2.0)

**`model_type`** (optional) - `chat` or `responses` (default: `chat`)

**`program_models`** (optional) - Per-program model overrides
| Field | Required | Description |
|-------|----------|-------------|
| `model` | Yes | Provider/model name (e.g., `openai/gpt-5-mini`) |
| `env` | No | Environment variable for API key |
| `api_key` | No | Direct API key (use `env` for security) |
| `api_base` | No | Custom API endpoint |
| `max_tokens` | No | Max response tokens |
| `temperature` | No | Sampling temperature (0.0-2.0) |
| `model_type` | No | `chat` or `responses` (default: `chat`) |

## API Keys

Expand Down
Loading