|
| 1 | +# Docker Usage Guide |
| 2 | + |
| 3 | +This guide shows how to use Docker with the structured-output-cookbook project using the **correct CLI parameters**. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Set your OpenAI API key: |
| 8 | +```bash |
| 9 | +export OPENAI_API_KEY='your-api-key-here' |
| 10 | +``` |
| 11 | + |
| 12 | +## Docker Setup Options |
| 13 | + |
| 14 | +### 1. Quick Start with Helper Scripts (Recommended) |
| 15 | + |
| 16 | +**For Development:** |
| 17 | +```bash |
| 18 | +./scripts/docker-dev.sh |
| 19 | +``` |
| 20 | +This starts an interactive development environment where you can run commands like: |
| 21 | +```bash |
| 22 | +uv run structured-output list-templates |
| 23 | +uv run structured-output extract recipe --input-file examples/recipe.txt |
| 24 | +uv run pytest |
| 25 | +uv run ruff check . |
| 26 | +``` |
| 27 | + |
| 28 | +**For Production Use:** |
| 29 | +```bash |
| 30 | +# Show help |
| 31 | +./scripts/docker-run.sh |
| 32 | + |
| 33 | +# Extract using a template (correct syntax) |
| 34 | +./scripts/docker-run.sh extract recipe --input-file examples/recipe.txt |
| 35 | + |
| 36 | +# Extract with custom schema |
| 37 | +./scripts/docker-run.sh extract-custom news_article --input-file examples/news_article.txt |
| 38 | + |
| 39 | +# Batch processing |
| 40 | +./scripts/docker-run.sh batch-extract examples/recipe.txt examples/product_review.txt recipe |
| 41 | + |
| 42 | +# List available templates |
| 43 | +./scripts/docker-run.sh list-templates |
| 44 | + |
| 45 | +# Validate schemas |
| 46 | +./scripts/docker-run.sh validate-schemas |
| 47 | +``` |
| 48 | + |
| 49 | +### 2. Using Docker Compose |
| 50 | + |
| 51 | +**Production service:** |
| 52 | +```bash |
| 53 | +# Build and show help |
| 54 | +docker compose up structured-output-cookbook |
| 55 | + |
| 56 | +# Run specific commands (correct syntax) |
| 57 | +docker compose run --rm structured-output-cookbook structured-output extract recipe --input-file examples/recipe.txt |
| 58 | +docker compose run --rm structured-output-cookbook structured-output list-templates |
| 59 | +docker compose run --rm structured-output-cookbook structured-output extract-custom customer_support --input-file examples/email.txt |
| 60 | +``` |
| 61 | + |
| 62 | +**Development service:** |
| 63 | +```bash |
| 64 | +# Start interactive development environment |
| 65 | +docker compose run --rm dev |
| 66 | +``` |
| 67 | + |
| 68 | +### 3. Direct Docker Commands |
| 69 | + |
| 70 | +**Build the image:** |
| 71 | +```bash |
| 72 | +docker build -t structured-output-cookbook:latest . |
| 73 | +``` |
| 74 | + |
| 75 | +**Run commands:** |
| 76 | +```bash |
| 77 | +# Show help |
| 78 | +docker run --rm \ |
| 79 | + -e OPENAI_API_KEY="$OPENAI_API_KEY" \ |
| 80 | + -v "$(pwd)/data:/app/data" \ |
| 81 | + -v "$(pwd)/config:/app/config" \ |
| 82 | + -v "$(pwd)/examples:/app/examples:ro" \ |
| 83 | + structured-output-cookbook:latest |
| 84 | + |
| 85 | +# Extract with template (correct syntax) |
| 86 | +docker run --rm \ |
| 87 | + -e OPENAI_API_KEY="$OPENAI_API_KEY" \ |
| 88 | + -v "$(pwd)/data:/app/data" \ |
| 89 | + -v "$(pwd)/config:/app/config" \ |
| 90 | + -v "$(pwd)/examples:/app/examples:ro" \ |
| 91 | + structured-output-cookbook:latest \ |
| 92 | + structured-output extract recipe --input-file examples/recipe.txt |
| 93 | + |
| 94 | +# Extract with custom schema |
| 95 | +docker run --rm \ |
| 96 | + -e OPENAI_API_KEY="$OPENAI_API_KEY" \ |
| 97 | + -v "$(pwd)/data:/app/data" \ |
| 98 | + -v "$(pwd)/config:/app/config" \ |
| 99 | + -v "$(pwd)/examples:/app/examples:ro" \ |
| 100 | + structured-output-cookbook:latest \ |
| 101 | + structured-output extract-custom news_article --input-file examples/news_article.txt |
| 102 | +``` |
| 103 | + |
| 104 | +## Correct CLI Parameter Reference |
| 105 | + |
| 106 | +### extract command |
| 107 | +```bash |
| 108 | +structured-output extract <TEMPLATE> --input-file <FILE> [OPTIONS] |
| 109 | +``` |
| 110 | +- Template is a **positional argument** (recipe, job, product-review, email, event) |
| 111 | +- Use `--input-file` (not `--file`) |
| 112 | +- Use `--output` for output file (not `--output-format`) |
| 113 | + |
| 114 | +### extract-custom command |
| 115 | +```bash |
| 116 | +structured-output extract-custom <SCHEMA_NAME> --input-file <FILE> [OPTIONS] |
| 117 | +``` |
| 118 | +- Schema name is a **positional argument** |
| 119 | +- Use `--input-file` (not `--file`) |
| 120 | + |
| 121 | +### batch-extract command |
| 122 | +```bash |
| 123 | +structured-output batch-extract <INPUT_FILES...> <TEMPLATE> [OPTIONS] |
| 124 | +``` |
| 125 | +- Input files are **positional arguments** (multiple files allowed) |
| 126 | +- Template is the **last positional argument** |
| 127 | +- Use `--output-dir` for output directory |
| 128 | + |
| 129 | +### validate-schemas command |
| 130 | +```bash |
| 131 | +structured-output validate-schemas [--config-dir <DIR>] |
| 132 | +``` |
| 133 | +- Use `--config-dir` (not `--schema-dir`) |
| 134 | + |
| 135 | +## Environment Variables |
| 136 | + |
| 137 | +- `OPENAI_API_KEY` (required) |
| 138 | +- `OPENAI_MODEL` (default: gpt-4o-mini) |
| 139 | +- `LOG_LEVEL` (default: INFO for production, DEBUG for dev) |
| 140 | +- `MAX_TOKENS` (default: 4000) |
| 141 | +- `TEMPERATURE` (default: 0.1) |
| 142 | + |
| 143 | +## Volume Mounts |
| 144 | + |
| 145 | +The Docker setup automatically mounts: |
| 146 | +- `./data` → `/app/data` (for output files) |
| 147 | +- `./config` → `/app/config` (for custom schemas) |
| 148 | +- `./examples` → `/app/examples` (read-only, for input files) |
| 149 | + |
| 150 | +## Complete Examples |
| 151 | + |
| 152 | +**Extract a recipe:** |
| 153 | +```bash |
| 154 | +./scripts/docker-run.sh extract recipe --input-file examples/recipe.txt --pretty |
| 155 | +``` |
| 156 | + |
| 157 | +**Extract with custom schema:** |
| 158 | +```bash |
| 159 | +./scripts/docker-run.sh extract-custom product_review --input-file examples/product_review.txt --output data/custom_result.json |
| 160 | +``` |
| 161 | + |
| 162 | +**Batch processing:** |
| 163 | +```bash |
| 164 | +./scripts/docker-run.sh batch-extract examples/recipe.txt examples/product_review.txt recipe --output-dir data/batch_results |
| 165 | +``` |
| 166 | + |
| 167 | +**Validate all schemas:** |
| 168 | +```bash |
| 169 | +./scripts/docker-run.sh validate-schemas --config-dir config/schemas |
| 170 | +``` |
| 171 | + |
| 172 | +**Get session statistics:** |
| 173 | +```bash |
| 174 | +./scripts/docker-run.sh session-stats |
| 175 | +``` |
| 176 | + |
| 177 | +**Cost analysis:** |
| 178 | +```bash |
| 179 | +./scripts/docker-run.sh cost-analysis |
| 180 | +``` |
| 181 | + |
| 182 | +## Common Mistakes to Avoid |
| 183 | + |
| 184 | +❌ **Wrong:** `--file examples/recipe.txt` |
| 185 | +✅ **Correct:** `--input-file examples/recipe.txt` |
| 186 | + |
| 187 | +❌ **Wrong:** `extract --template recipe --file examples/recipe.txt` |
| 188 | +✅ **Correct:** `extract recipe --input-file examples/recipe.txt` |
| 189 | + |
| 190 | +❌ **Wrong:** `batch-extract --input-dir examples --template recipe` |
| 191 | +✅ **Correct:** `batch-extract examples/*.txt recipe` |
| 192 | + |
| 193 | +❌ **Wrong:** `validate-schemas --schema-dir config/schemas` |
| 194 | +✅ **Correct:** `validate-schemas --config-dir config/schemas` |
0 commit comments