How harvard-lil/olaw works
Project type and purpose
• OLAW is a full-stack web application (Flask + Python backend; JS/CSS frontend) that implements a tool-based Retrieval-Augmented Generation (RAG) pipeline for legal research.
• It provides both a browser-based chat UI and a REST API to orchestrate three stages: (a) extract a search statement, (b) perform a search against a legal API, (c) send context+history to an LLM and stream back the completion.
File structure
• Top–level:
• wsgi.py – Flask WSGI entry point
• pyproject.toml / setup.cfg – build & dependency config
• .env.example – environment variable template
• olaw/ (Python package)
• views/ui.py – serves index.html and static assets
• views/api/*.py – REST endpoints (/api/models, /api/extract-search-statement, /api/search, /api/complete)
• search_targets/ – plugin modules for each legal search target (e.g., courtlistener.py)
• utils/ – env checks, rate-limiter factory, model list discovery
• static/ – JS components (ChatBubble, ChatFlow, ChatInput, dialogs), CSS, state management
• templates/index.html – single‐page shell
README for architectural insights
• Pipeline stages and endpoints are documented in “Interacting with the API”
• Describes interchangeable LLM backends (OpenAI vs. Ollama) and pluggable search targets
• Highlights modularity and ease of adding new tools via search_targets
Main components & interactions
a. Frontend (Browser)
• index.html + JS/CSS components present chat UI, handle user input & confirmations, display streaming text
b. Backend (Flask App)
• UI controller: serves static assets and template
• API controllers:
• extract-search-statement → calls LLM with prompt to generate {search_target, search_statement}
• search → loads appropriate SearchTarget class → performs HTTP call to legal API (e.g., CourtListener)
• complete → collates message, history, and search results → calls LLM endpoint (OpenAI/Ollama) → streams response
• Utils: environment/config loader, rate limiter, available models enumerator
c. External Services
• CourtListener API (or any other legal search target)
• LLM backends: OpenAI’s completions API or local Ollama server
Architectural patterns & design principles
• MVC‐style separation: views/ui.py (V), static components (C), views/api (C) & business logic in olaw/utils & olaw/search_targets (M)
• Plugin pattern: each search_targets/*.py implements a uniform interface for adding new legal APIs
• Pipeline orchestration: sequential stages (extract → search → complete) with confirmation step in the UI
• Environment-driven configuration: .env controls LLM endpoints, model choices, prompts