- JavaScript 37.1%
- CSS 27.4%
- Python 26.5%
- HTML 9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| docs | ||
| screenshots | ||
| static | ||
| templates | ||
| app.py | ||
| db.py | ||
| LICENSE | ||
| ollama_client.py | ||
| README.md | ||
| requirements.txt | ||
Ollama Local Chat
A lightweight, local-first AI chat web application built with Flask, SQLite, and Ollama. It provides a browser-based interface for locally installed language models, with streaming responses, model selection, and persistent conversation history.
Overview
Ollama Local Chat is a small full-stack project for interacting with local language models without requiring a hosted AI API. The Flask backend communicates with Ollama over its local HTTP API, streams NDJSON responses to the browser, and stores conversations in SQLite. The frontend is implemented with plain HTML, CSS, and JavaScript, with no Node.js build step.
Features
- Streaming chat responses — Ollama output is forwarded to the browser as it is generated.
- Local model discovery — lists installed Ollama models and filters out models that do not advertise completion capability.
- Persistent conversations — chat sessions and messages are stored locally in SQLite.
- Markdown rendering — assistant responses support Markdown, code blocks, and tables, with client-side sanitization.
- Local-first architecture — application traffic is directed to the local Ollama service by default.
- Zero frontend build step — plain HTML, CSS, and JavaScript.
- Responsive interface — sidebar-based model/chat navigation with a compact mobile layout.
Architecture
Browser
│
│ HTTP / streaming NDJSON
▼
Flask application
├── Chat/history API ───────► SQLite
│
└── Ollama client ─────────► Local Ollama API
│
▼
Local LLM
The application is separated into three backend responsibilities:
app.py— Flask routes, validation, streaming proxy, and HTTP responses.ollama_client.py— Ollama API communication and model-capability checks.db.py— SQLite persistence for chats and messages.
The browser interface lives under templates/ and static/.
Project Structure
ollama-local-chat/
├── app.py
├── db.py
├── ollama_client.py
├── requirements.txt
├── templates/
│ └── index.html
├── static/
│ ├── css/
│ │ └── style.css
│ └── js/
│ └── app.js
├── docs/
│ └── ARCHITECTURE.md
├── .gitignore
├── LICENSE
└── README.md
chats.db is created automatically when the application starts and is excluded from version control.
Requirements
- Python 3.10+
- Ollama installed and running locally
- At least one chat-capable Ollama model
For example:
ollama pull llama3.2
Installation
git clone <repository-url>
cd ollama-local-chat
python -m venv .venv
source .venv/bin/activate
On Windows:
.venv\Scripts\activate
Install the Python dependencies:
pip install -r requirements.txt
Running the Application
Make sure Ollama is running, then start the Flask application:
python app.py
Open:
http://127.0.0.1:5000
Select one of the locally installed models from the sidebar and start a conversation.
API Flow
Model discovery
The frontend calls:
GET /api/models
The backend retrieves installed models from Ollama and checks their advertised capabilities before presenting them as chat options.
Streaming chat
The frontend sends a conversation to:
POST /api/chat
The Flask backend opens a streaming request to Ollama's /api/chat endpoint and forwards each NDJSON line to the browser as soon as it arrives.
Conversation persistence
Chat metadata and messages are managed through /api/chats endpoints and stored in two SQLite tables:
chatsmessages
Messages reference their parent chat through a foreign key with cascade deletion enabled at the database level.
Markdown and Frontend Dependencies
Assistant responses are rendered as Markdown using marked and sanitized with DOMPurify. These libraries are currently loaded from a CDN by templates/index.html.
Because of these CDN assets, the model inference and chat storage are local, but the current frontend is not strictly network-isolated when loading the page for the first time. Vendor these JavaScript libraries locally if a fully offline interface is required.
Configuration
By default, the Ollama API is expected at:
OLLAMA_URL = "http://127.0.0.1:11434"
This value is defined in ollama_client.py. Change it if Ollama is running on a different host or port.
The Flask application itself listens on:
127.0.0.1:5000
Troubleshooting
| Symptom | Likely cause |
|---|---|
Could not connect to Ollama |
Ollama is not running or is using a different address. |
| No models appear | No model has been pulled yet, or Ollama cannot be reached. |
| A model is absent from the list | The model may not advertise completion capability and is therefore filtered out. |
Conversations disappear after deleting chats.db |
Chat history is stored only in the local SQLite database. |
Scope
This project is intended as a lightweight local development application rather than a production multi-user service. It binds Flask to localhost and does not implement authentication or remote-user isolation.
License
This project is licensed under the MIT License. See LICENSE for details.


