A lightweight, persistent chatbot with:
- SQLite storage (no data loss across runs)
- A simple CLI
- Two web UIs: Flask and FastAPI + HTMX
- Create a virtual environment (recommended)
python -m venv .venv
# PowerShell
.\\.venv\\Scripts\\Activate.ps1
# or CMD
.\\.venv\\Scripts\\activate.bat- Install dependencies
pip install -r requirements.txt- Run the CLI
python chatbot.py- Run the Flask web UI
python webapp/app.py
# open http://127.0.0.1:8000- Run the FastAPI + HTMX UI
python -m uvicorn fastapi_app.main:app --reload
# open http://127.0.0.1:8000The first run creates database.sqlite3. CLI and both UIs share the same knowledge base.
CHATBOT_DB_PATH– Path to the SQLite database file (default:./database.sqlite3).CHATBOT_READ_ONLY– Iftrue, disables training (default:false).
Example (PowerShell):
$env:CHATBOT_DB_PATH = "C:\\path\\to\\mydb.sqlite3"
$env:CHATBOT_READ_ONLY = "true"- Clean web UIs (Flask or FastAPI + HTMX)
- Per-session conversation history (Flask) and HTMX incremental updates (FastAPI)
- Clear chat and reset training (delete DB)
- Teach-a-pair panel to add Q/A training examples on the fly
Build and run the FastAPI variant:
# Build image
docker build -t supportbot:latest .
# Persist DB to a local folder (PowerShell)
mkdir data
# Run container (maps http://localhost:8000)
docker run --rm -p 8000:8000 -v ${PWD}\\data:/data -e CHATBOT_DB_PATH=/data/database.sqlite3 supportbot:latestOr pull a published image from GHCR (after the CI publishes at least once):
# Pull latest image
docker pull ghcr.io/swoet/ai-driven-chatbot-python-chatterbot:latest
# Run it
docker run --rm -p 8000:8000 -v ${PWD}\\data:/data -e CHATBOT_DB_PATH=/data/database.sqlite3 ghcr.io/swoet/ai-driven-chatbot-python-chatterbot:latestStop with Ctrl+C and the DB remains in the local data folder.
A static project site lives in docs/ and is deployed via GitHub Pages (see .github/workflows/pages.yml). If not already enabled:
- In repository settings → Pages → Source: GitHub Actions
- Push to master to trigger deployment; the workflow publishes docs/.
chatbot.py– CLI entrypointbot_core.py– Bot engine (SQLite + difflib) and bootstrap trainingwebapp/app.py– Flask web UIwebapp/templates/andwebapp/static/– UI templates and stylesfastapi_app/main.py– FastAPI + HTMX web UIfastapi_app/templates/andfastapi_app/static/– UI templates and stylestests/– Unit tests.github/workflows/tests.yml– CI for tests
- Corpus-based training flows
- Export/import knowledge base snapshots
- Linting (ruff), type checking, and pre-commit hooks
- Docker for the FastAPI variant
- Optional Streamlit UI (re-add
streamlitwhen platform provides prebuiltpyarrow)