Skip to content

elandy/chatbot

Repository files navigation

LangGraph Chatbot

Local chatbot built with FastAPI, LangGraph, Ollama, SQLite, and a small TypeScript frontend.

What it does

  • Creates and persists conversations in SQLite
  • Streams assistant output to the browser with Server-Sent Events
  • Stores LangGraph checkpoints separately from app data
  • Lets you rename and delete conversations
  • Resumes conversation state by reusing the conversation ID as the LangGraph thread_id

Stack

Backend

  • FastAPI
  • LangGraph
  • LangChain Core
  • LangChain Ollama
  • SQLAlchemy
  • SQLite

Frontend

  • Jinja2 templates
  • TypeScript compiled to browser ESM in static/js
  • Plain CSS

Project structure

.
|-- main.py                        # FastAPI app and HTTP routes
|-- graph.py                       # LangGraph definition and Ollama integration
|-- chat_service.py                # Chat helpers
|-- conversation_service.py        # Conversation and message persistence
|-- database.py                    # SQLAlchemy engine, session, and base
|-- models.py                      # SQLAlchemy models
|-- init_db.py                     # Creates SQLite tables
|-- chatbot.py                     # Simple CLI smoke-test entrypoint
|-- data/
|   |-- app.db                     # App data: conversations and messages
|   `-- checkpoints.db             # LangGraph checkpoint storage
|-- templates/
|   |-- index.html                 # Main page
|   `-- generation_service.py      # Background token generation for SSE
|-- static/
|   |-- css/
|   |   `-- styles.css
|   |-- ts/                        # TypeScript source
|   `-- js/                        # Compiled browser JavaScript
|-- pyproject.toml
|-- package.json
`-- tsconfig.json

How it works

  1. The browser creates or selects a conversation.
  2. A user message is saved to data/app.db.
  3. The backend starts a background generation task.
  4. LangGraph loads checkpoint state for that conversation from data/checkpoints.db.
  5. Tokens are streamed back to the browser over SSE.
  6. The completed assistant response is saved to the application database.

The app keeps two kinds of persistence:

  • app.db stores conversation metadata and message history for the UI.
  • checkpoints.db stores LangGraph execution state for resumable memory.

Requirements

  • Python 3.13+
  • Node.js, for compiling the TypeScript frontend
  • Ollama running locally
  • The model configured in graph.py: llama3.1:8b

Setup

1. Install Python dependencies

uv sync

2. Create the database tables

uv run python init_db.py

3. Compile the frontend assets

npm install
npm run build

4. Make sure Ollama is serving the configured model

ollama pull llama3.1:8b
ollama serve

Run

uv run python main.py

Then open http://127.0.0.1:8000.

Notes

  • The frontend is not using Vite. tsconfig.json compiles static/ts directly into static/js.
  • package.json is only used to manage the TypeScript toolchain.
  • chatbot.py provides a small CLI loop for backend testing without the browser.

About

A ChatGPT-style local AI assistant built with LangGraph, FastAPI, Ollama, and TypeScript, featuring streaming responses, resumable conversations, and persistent memory.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors