Skip to content

MarijanMiletic/LexAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LexAI - Production Legal Engine

LexAI is a high-performance, hybrid C++/Python system designed for automated legal adjudication under Croatian Law. It combines a deterministic C++ core for legal logic with a Python FastAPI orchestration layer, integrated with a PostgreSQL database and a local LLM (Ollama) for natural language processing.

Architecture

The system runs as a multi-container Docker application:

  1. LexAI App: FastAPI + C++ Core (Business Logic).
  2. PostgreSQL: Persistent storage for driver history (Recidivism checks).
  3. Ollama: Local LLM service running mistral for parsing case descriptions.

Features

  • C++ Core:
    • Speeding: Calculates fines/points based on config/rules.json. Checks DB for prior offenses (Recidivism doubles the fine).
    • Alcohol: Adjudicates based on driver category (Young, Professional, Standard).
    • Interest: Calculates penalty interest (Civil Obligations Act).
    • Severance: Calculates severance pay (Labor Act).
  • AI Parsing: Uses a local LLM (mistral) to parse unstructured text (e.g., "Driver was drunk, 1.5 g/kg") into structured JSON.
  • PDF Generation: Generates official verdict documents using Jinja2 and WeasyPrint.
  • Configuration: All legal parameters (fines, limits, rates) are hot-loadable from config/rules.json.

Quick Start (Docker Compose)

This is the recommended way to run the full stack.

  1. Start the System:

    docker compose up --build

    Note: The first run will take a few minutes to download the 4GB LLM model.

  2. Access the UI: Open http://localhost:8000 in your browser.

  3. Test the API:

    # Speeding (checks DB for recidivism)
    curl -X POST "http://localhost:8000/judge/speeding" \
         -H "Content-Type: application/json" \
         -d '{"measured_speed": 130, "limit": 100, "tolerance": 10, "driver_id": "recidivist_1"}'
    
    # AI Parsing
    curl -X POST "http://localhost:8000/parse" \
         -H "Content-Type: application/json" \
         -d '{"text": "Driver detected with 1.5 g/kg alcohol, young driver."}'

Directory Structure

  • src/core/: C++ business logic (Speeding, Alcohol, Interest, Severance).
  • src/api/: Python FastAPI app, PDF generator, LLM parser.
  • config/: External configuration (rules.json).
  • docker/: Dockerfile and entrypoint scripts.
  • tests/: Unit tests.

Local Development

To develop locally, you need cmake, g++, python3.11, libpqxx-dev, and nlohmann-json3-dev.

  1. Build C++ Core:

    mkdir build && cd build
    cmake .. && make
  2. Run API:

    export PYTHONPATH=$PYTHONPATH:$(pwd)/build
    uvicorn src.api.main:app --reload

    Note: Local run requires a running Postgres instance and Ollama service accessible at the URLs defined in the code.

Releases

Packages

Contributors

Languages