Skip to content

Commit e74c3d6

Browse files
committed
Add README and enhance developer guide with custom prompt, schema, and evaluation details
1 parent 93f048a commit e74c3d6

2 files changed

Lines changed: 112 additions & 2 deletions

File tree

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# LLM Batch Pipeline
2+
3+
`llm-batch-pipeline` is a generic LLM batch processing pipeline. It discovers and parses input files via a plugin system, renders OpenAI Batch API (or Ollama) requests, validates structured JSON outputs with a Pydantic schema, evaluates predictions against ground truth, and exports results to XLSX/JSON.
4+
5+
See the **Admin Guide** for installation/deployment, and the **Developer Guide** for how to extend the pipeline with custom plugins, prompts, schemas, and evaluation.
6+
7+
## Workflow
8+
```mermaid
9+
flowchart TD
10+
A[Input Files] --> B[1. Discover]
11+
B --> C[2. Filter - pre]
12+
C --> D[3. Transform]
13+
D --> E[4. Filter - post]
14+
E --> F[5. Render JSONL]
15+
F --> G{6. Human Review}
16+
G -->|Approved| H[7. Submit to Backend]
17+
G -->|--auto-approve| H
18+
G -->|Rejected| Z[Abort]
19+
H --> I[8. Validate Results]
20+
I --> J[9. Evaluate]
21+
J --> K[10. Export]
22+
23+
subgraph Backends
24+
H --> H1[OpenAI Batch API]
25+
H --> H2[Ollama Local]
26+
end
27+
28+
H1 --> I
29+
H2 --> I
30+
31+
subgraph Outputs
32+
K --> K1[results.xlsx]
33+
K --> K2[evaluation.xlsx]
34+
K --> K3[evaluation.json]
35+
K --> K4[metrics.json]
36+
end
37+
```
38+
39+
## Admin / Install
40+
- Admin guide: [`docs/admin-guide.md`](docs/admin-guide.md)
41+
- Install (example): `uv sync`
42+
43+
## Requirements
44+
- OpenAI backend: set `OPENAI_API_KEY`.
45+
- Local LLM via Ollama: run an Ollama server (pull the model), then use `--backend ollama --base-url http://HOST:11434` (repeat `--base-url` for multi-server sharding).
46+
- OpenAI API compatible local server (if supported by your server): use `--backend openai` and configure the OpenAI SDK base URL (commonly via `OPENAI_BASE_URL`).
47+
48+
## Test / Benchmark
49+
- SpamAssassin corpus reference run: [`docs/benchmark-run.md`](docs/benchmark-run.md)
50+
51+
## Architecture
52+
- [`docs/architecture.md`](docs/architecture.md)
53+
54+
## Extend (plugins)
55+
- [`docs/developer-guide.md`](docs/developer-guide.md)
56+
- Developer guide covers: custom prompt, custom Pydantic schema, and custom evaluation.
57+
58+
## Monitor
59+
- Prometheus metrics + Grafana: [`docs/admin-guide.md`](docs/admin-guide.md)
60+
61+
## License
62+
- EUPL (v1.2): [see `LICENSE`](LICENSE)

docs/developer-guide.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class SentimentResult(BaseModel):
109109
)
110110
reason: str = Field(description="Explanation.")
111111

112-
# REQUIRED: the pipeline loads schemas by this name
112+
# REQUIRED: `schema_loader` expects a symbol named `mySchema`
113113
mySchema = SentimentResult
114114
```
115115

@@ -126,7 +126,6 @@ def register():
126126
pre_filters=[MinRowFilter(min_rows=2)],
127127
transformers=[NormalizeHeadersTransformer()],
128128
post_filters=[],
129-
default_schema_module="my_plugin.schema",
130129
))
131130
```
132131

@@ -149,6 +148,55 @@ from my_plugin.plugin import register
149148
register()
150149
```
151150

151+
## Custom Prompt, Schema, and Evaluation (per batch)
152+
153+
The plugin system controls how inputs are parsed and preprocessed. Prompt/instructions, schema validation, and evaluation configuration are provided per *batch run*.
154+
155+
### Custom prompt (instructions)
156+
157+
The LLM `instructions` text is loaded from:
158+
159+
- `--prompt-file` (CLI) or `batches/<batch>/prompt.txt` (file in the batch directory)
160+
- a built-in fallback prompt when neither exists
161+
162+
For submit-time overrides, use `--prompt-override` / `--prompt-override-file`.
163+
The backends apply this by rewriting `body.instructions` for every request right before submission.
164+
165+
Your plugin’s `FileReader.package_for_llm()` controls the per-file content injected as the `input_text` part of the prompt.
166+
167+
### Custom Pydantic schema
168+
169+
Provide a schema via one of these mechanisms:
170+
171+
- `--schema-file path/to/schema.py`
172+
- or a `schema.py` file placed in the batch directory (`batches/<batch>/schema.py`)
173+
174+
Your schema file must define `mySchema` (typically `class mySchema(BaseModel): ...` or `mySchema = SomeModel`).
175+
The pipeline converts it to a strict JSON schema for structured outputs and then validates the LLM JSON against it.
176+
177+
Evaluation field mapping defaults to `label` and `confidence`. To evaluate other schema field names, use `--label-field` and `--confidence-field`.
178+
179+
Note: evaluation auto-detection of label/confidence from the schema runs only when `--schema-file` is explicitly provided.
180+
If you rely solely on `batches/<batch>/schema.py`, set `--label-field` / `--confidence-field` explicitly.
181+
182+
### Custom evaluation
183+
184+
The built-in `evaluate` stage computes confusion matrix + precision/recall/F1 + accuracy, and optionally ROC/AUC for binary classification when `--positive-class` is set (and confidence is available).
185+
186+
It uses:
187+
188+
- Ground truth from `--ground-truth-csv` or `batches/<batch>/evaluation/ground-truth.csv`
189+
- Category map from `--category-map` or `batches/<batch>/evaluation/category-map.json`
190+
191+
Supported 'custom evaluation' via plugins:
192+
193+
- Implement `OutputTransformer` in your plugin to reshape `validated_rows` before evaluation/export (e.g. rename/move fields so they match `--label-field` / `--confidence-field`).
194+
195+
If you need entirely different evaluation metrics/logic:
196+
197+
- modify `src/llm_batch_pipeline/evaluation.py` (`evaluate()` / `EvalReport`)
198+
- and update `src/llm_batch_pipeline/stages.py` `stage_evaluate()` (plus `src/llm_batch_pipeline/export.py` if the report format changes)
199+
152200
## Plugin ABCs Reference
153201

154202
### `FileReader`

0 commit comments

Comments
 (0)