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. 1
First Local Chatbot

01. Chatbot Architecture

Chapter 1 of 15 · 15 min
KEY INSIGHT

Every component (browser, FastAPI, Ollama) speaks a different protocol; the backend is the translator between all of them.

A local chatbot has three moving parts: the frontend (HTML + JavaScript in a browser), the backend (FastAPI on a server), and the LLM engine (Ollama running a model). The browser never talks to Ollama directly. Every request flows:

Browser → FastAPI → Ollama → FastAPI → Browser

This separation lets you swap models, add auth, and control rate limiting in one place without touching the frontend.

The frontend is stateless for all data except session identity. It sends a session ID with every request so FastAPI knows which conversation history to retrieve. FastAPI stores sessions in memory as a Python dict: sessions[session_id] = [{"role": "user", "content": "..."}]. In production you would swap this for Redis, but for a first chatbot the dict is fine.

The Ollama API accepts a POST to /api/chat with a JSON body. The stream: true flag returns newline-delimited JSON chunks. Each chunk has the shape {"model": "...", "message": {"role": "...", "content": "..."}, "done": false}. FastAPI proxies this to the browser using Server-Sent Events (SSE), which is a unidirectional stream format the browser reads with EventSource. SSE was chosen over WebSocket because it requires zero additional libraries in the browser and handles reconnection automatically.

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.

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

Run curl http://localhost:11434/api/tags and confirm you see at least one model listed. If this returns a connection refused error, Ollama is not running—start it with ollama serve.

← Overview
First Local Chatbot
Chapter 2 →
FastAPI Backend Setup