Run a real LLM 100% inside your browser โ free, private, and fully offline after the first load. No server, no API key, no install. Includes a chat app and an arcade game where the AI is the villain.
Built with WebLLM (WebGPU) and wllama (llama.cpp โ WASM, CPU) โ automatic fallback, so it works on any modern browser, with or without a GPU.
| ๐ฌ Chat | ๐พ AI Overlord |
|---|---|
![]() |
![]() |
| Page | What it does |
|---|---|
index.html |
๐ฌ Minimal chat UI with streaming replies |
game.html |
๐พ AI Overlord โ a canvas space shooter where the LLM designs every enemy wave live (count, speed, attack pattern, taunt) and gloats when you die |
engine.js |
Shared loader: probes for a real WebGPU adapter โ WebLLM; otherwise llama.cpp WASM on CPU |
sw.js |
Service worker so the app shell works offline (models are cached by the engines themselves) |
| Model | Size (Q4) | Best for |
|---|---|---|
| SmolLM2-360M-Instruct | ~260MB | Fast replies, low-end machines |
| Qwen2.5-1.5B-Instruct | ~1GB | Noticeably smarter chat |
Weights download once from Hugging Face, then live in browser storage (Cache API / IndexedDB) โ turn off wifi and everything keeps working.
git clone https://github.com/oyekamal/offline-llm-chat.git
cd offline-llm-chat
python3 -m http.server 8787 # any static server works (service workers need localhost or https)Open http://localhost:8787 โ pick a model โ Load model โ chat. Or open http://localhost:8787/game.html โ Load AI โ Start game.
Small models are slow (seconds per reply on CPU) and unreliable (they ignore "reply with JSON only" half the time). The game is designed around that:
- JS owns all game state โ the model can never break a round
- The next wave is generated while you fight the current one โ latency is hidden, you never wait
- Lenient parsing โ strict JSON first, then regex field-scraping, then clamped defaults ("backup wave") if the model rambled
- The model contributes creativity (wave design, taunts, game-over gloats), not correctness
This pattern โ LLM as content director, JS as referee โ is the useful takeaway for building on top of tiny in-browser models.
- With GPU (WebGPU): Chrome/Edge 113+, recent Firefox/Safari โ fast (WebLLM, ~80% native speed)
- Without GPU: any browser with WASM SIMD โ slower but works (wllama, CPU). Force it with
?cpuin the URL - Keep models โค2GB: Firefox caps per-site storage at 2GB
- Chat history persistence (localStorage)
- More game modes (LLM-generated boss fights, power-up descriptions)
- Voice input via Web Speech API
- PWA install prompt + proper icons
- RAG over local files with transformers.js embeddings
MIT โ do whatever you want.
#webllm #wllama #llamacpp #webgpu #wasm #offline-ai #local-llm #browser-llm #smollm #qwen #no-server #privacy #ai-game

