26 lines
797 B
Markdown
26 lines
797 B
Markdown
# Structured Output with Discriminated Union
|
|
|
|
This repository demonstrates how to parse raw API logs into typed events using **Pydantic v2** and **LangChain ≥1.0**. The solution showcases:
|
|
|
|
* A discriminated union of two event types (`HttpOkEvent` and `HttpErrorEvent`).
|
|
* Structured output from an LLM via `ChatOpenAI.with_structured_output`.
|
|
* Batch parsing of multiple log lines.
|
|
* A simple CLI that prints the parsed events and a summary table.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
# Run with the default example log
|
|
python -m src.main
|
|
|
|
# Or provide your own raw log string
|
|
python -m src.main --log "GET /api/test 200 30ms\nPOST /api/submit 500 Internal Server Error"
|
|
```
|
|
|
|
The script prints each parsed event as a dictionary and a tabular summary. |