Skip to content

Repository files navigation

LawAdviser ⚖️

An AI legal-advisory assistant built on the OpenAI Assistants API, with a FastAPI backend, async SQLAlchemy + PostgreSQL persistence, and a Streamlit chat UI. Multiple configurable agents are stored in the database, each mapped to an OpenAI Assistant with its own instructions and tools.

Architecture

┌────────────┐     ┌──────────────────┐     ┌───────────────────┐
│ Streamlit  │────▶│  FastAPI (REST)  │────▶│ OpenAI Assistants │
│  chat UI   │     │  agents / chat   │     │  (threads, tools) │
└────────────┘     └────────┬─────────┘     └───────────────────┘
                            │ async SQLAlchemy
                            ▼
                   ┌──────────────────┐
                   │   PostgreSQL     │
                   │  agent registry  │
                   └──────────────────┘
  • main.py — FastAPI app: agent CRUD + question endpoints
  • ai.pyAgentManagerAI: OpenAI Assistants thread/run lifecycle, streaming, tool calls
  • models/ schemas/ crud/ — SQLAlchemy models, Pydantic schemas, DB operations
  • app.py — Streamlit chat frontend with file upload and streaming responses
  • database.py — async engine/session manager (asyncpg)

Quick start

Docker (recommended)

export OPENAI_API_KEY=sk-...   # your key
docker compose up --build

API on http://localhost:8030, PostgreSQL on 5432.

Local

  1. Create an assistant at platform.openai.com/assistants and note the assistant ID
  2. Create a .env file:
    DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/lawadviser
    OPENAI_API_KEY=sk-...
  3. Install and run:
    pip install -r requirements.txt   # or: poetry install
    uvicorn main:app --reload --port 8030
  4. Register an agent row (assistant ID + instructions) via the API, then chat.

Configuration

Variable Purpose
DATABASE_URL Async PostgreSQL DSN (postgresql+asyncpg://...)
OPENAI_API_KEY OpenAI API key

Stack

Python · FastAPI · OpenAI Assistants API · SQLAlchemy (async) + asyncpg · PostgreSQL · Pydantic v2 · Streamlit · Docker

About

AI legal-advisory assistant — OpenAI Assistants API, FastAPI, async SQLAlchemy/PostgreSQL, Streamlit chat UI

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages