RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /First Local Chatbot
  6. /Ch. 15
First Local Chatbot

15. Chatbot Project Wrap-up

Chapter 15 of 15 · 15 min
KEY INSIGHT

The whole chatbot is under 300 lines of code. Complexity is a choice, not a requirement—start simple and add only what you need.

The complete project structure:

chatbot/
├── Dockerfile
├── docker-compose.yml
├── app/
│   ├── main.py           # FastAPI app, routes
│   ├── ollama_client.py  # Ollama HTTP client
│   └── templates/
│       └── index.html    # Single-file frontend
└── venv/                 # Python virtual environment

What works: Streaming responses, multi-turn conversation memory, session management, personality configuration, multi-model selection, error handling, UI polish, LAN deployment, Docker deployment.

What is not production-ready: Session storage is in-memory (lost on restart), no authentication, no rate limiting, no message size limits, no prompt injection protection.

Next steps:

  1. Swap in-memory sessions for Redis or SQLite with session_id as the key
  2. Add HTTP Basic Auth with a middleware
  3. Add message size validation (reject prompts > 8192 tokens)
  4. Add prompt injection detection (check for repeated system-prompt override patterns)
  5. Add streaming metrics: tokens per second display

To verify the complete system works end-to-end, run:

# Terminal 1
ollama serve

# Terminal 2
cd chatbot
source venv/bin/activate
uvicorn app.main:app --reload

# Browser
# Navigate to http://localhost:8000
# Select a model, type a message, verify streaming response

The chatbot is complete. Every file is a plain text file you can read, edit, and understand. The architecture is simple enough to explain in two minutes and reliable enough to ship.

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Delete the conversation history from sessions dict in main.py (restart the server). Confirm the UI clears. Then write a sessions.json persistence layer that saves and loads sessions from disk so they survive restarts.

← Chapter 14
Docker Deployment
Course complete →
Browse all courses