How katherlab/llmaixlib works
Project type and purpose
• LLMAIx is an open-source Python library (not a full-stack “app”) that provides:
• Preprocessing of documents (PDF/DOCX/TXT), with optional OCR backends.
• A wrapper for information extraction via OpenAI-API compatible LLMs, returning structured JSON.
File structure
• Top-level:
• src/llmaix – core package
– cli.py: command-line interface entrypoint
– preprocess.py & extract.py: main modules
– utils.py: shared helpers
• tests/: unit tests and test PDF samples
• pyproject.toml: build config
• GitHub workflows: CI for tests and publishing
Key components
A. User Interfaces
– CLI (llmaix command)
– Python API (import llmaix.preprocess_file, llmaix.extract_info)
B. Core Library
– Preprocess module
• PDF/Text loader
• OCR orchestrator (calls external OCR backends)
• Backend selector (pymupdf4llm, markitdown, docling)
– Extract module
• Prompt builder
• API client to OpenAI-compatible endpoints
• Pydantic model validation
– Utils module (common functions, e.g. file I/O)
C. External Dependencies
– OCR backends: Tesseract (via ocrmypdf), Surya-OCR, Docling-VLM
– PDF parsing libs: pymupdf4llm, markitdown, docling
– Cloud LLM endpoints: OpenAI API or custom base URL
– Environment variables (.env for API key, model name, base URL)
D. CI/CD & Packaging
– GitHub Actions (tests, publish)
– PyPI packaging via pyproject.toml
– Dependency groups (docling, surya)
Relationships & data flows
• User invokes CLI or Python API →
Preprocess module reads file →
If use_ocr=True: dispatch to selected OCR backend → raw text
Else: use selected PDF/Text backend → raw text
→ Hand off text to Extract module →
Build prompt + pydantic schema → call OpenAI API →
Receive LLM response → validate against schema → JSON output → return to user
Architectural patterns & principles
• Modular layering: separate CLI, preprocessing, extraction, utils
• Strategy pattern: pluggable OCR and PDF backends chosen at runtime
• Adapter/Wrapping: unify different backends under common interface
• Configuration via environment variables and dependency-group extras