|
1 | | -# 🌐 Browser LLM Chat |
| 1 | +# Browser LLM Chat |
2 | 2 |
|
3 | | -A high-performance, **100% local-first** React application designed to run Large Language Models directly in your browser. Leveraging **WebGPU** via `@huggingface/transformers`, this experiment brings powerful inference to the client-side with no backend required. |
| 3 | +Browser LLM Chat is a fully local-first React application that runs language and vision models directly in the browser with WebGPU. There is no backend inference layer, no API key requirement, and no server-side chat state. |
4 | 4 |
|
5 | | - |
6 | | - |
7 | | - |
| 5 | +## Highlights |
8 | 6 |
|
9 | | ---- |
| 7 | +- Local-first inference with `@huggingface/transformers` |
| 8 | +- Web Worker based model loading and token streaming |
| 9 | +- Shared app state managed with Zustand |
| 10 | +- Chat history persisted locally with IndexedDB and localStorage fallback |
| 11 | +- Curated browser-ready models plus searchable Hugging Face discovery |
| 12 | +- Built-in settings for generation controls and downloaded-model cleanup |
10 | 13 |
|
11 | | -## ✨ Key Features |
| 14 | +## Stack |
12 | 15 |
|
13 | | -- **🚀 100% Local Inference**: Your prompts, images, and model outputs never leave your browser. Privacy is built-in by design. |
14 | | -- **⚡ WebGPU Accelerated**: Utilizes your GPU's power for near-native performance on compatible browsers (Chrome/Edge Desktop). |
15 | | -- **🧠 Advanced Model Support**: Access to specialized browser-friendly models, including: |
16 | | - - **Balanced (Gemma 3 1B)**: A balanced desktop default for everyday browser chat. |
17 | | - - **Reasoning (DeepSeek R1 1.5B)**: Built-in reasoning capabilities for complex logic via distillation. |
18 | | - - **Coding (Qwen 2.5 Coder)**: Compact coding helpers for quick edits and code explanations. |
19 | | - - **Vision (Qwen 3.5 Vision)**: Fully multimodal support for image-to-text tasks. |
20 | | - - **Fast / Mobile-Safe**: SmolLM2 (360M) and Qwen 2.5 (0.5B) for ultra-quick response times. |
21 | | -- **⚙️ Generation Parameter Controls**: Fine-grained control over model temperature, top-p, and token limits via an intuitive settings dialog. |
22 | | -- **💾 Storage & Chat Management**: Automatic Hugging Face caching, clear chat history, and robust data management to delete offline model files directly from the UI. |
23 | | -- **🧵 Worker-Based Architecture**: Heavy computation happens in a dedicated Web Worker to keep the UI smooth and responsive. |
| 16 | +- React 19 |
| 17 | +- Vite |
| 18 | +- TypeScript |
| 19 | +- Vanilla CSS |
| 20 | +- `@huggingface/transformers` `4.0.0-next.x` |
24 | 21 |
|
25 | | ---- |
| 22 | +## Prerequisites |
26 | 23 |
|
27 | | -## 🛠 Tech Stack |
| 24 | +- Node.js `22.x` |
| 25 | +- A WebGPU-capable browser |
| 26 | + Recommended: recent Chrome or Edge desktop builds |
28 | 27 |
|
29 | | -- **Core**: [React 19](https://react.dev/), Vite, TypeScript |
30 | | -- **Inference**: [@huggingface/transformers (v4.0.0-next)](https://github.com/huggingface/transformers.js) |
31 | | -- **Styling**: Vanilla CSS (Custom UI with glassmorphism and modern aesthetics) |
32 | | -- **Formatting**: `react-markdown` with `remark-gfm` for rich text and reasoning blocks. |
| 28 | +## Getting Started |
33 | 29 |
|
34 | | ---- |
| 30 | +```bash |
| 31 | +npm install |
| 32 | +npm run dev |
| 33 | +``` |
35 | 34 |
|
36 | | -## 🚀 Getting Started |
| 35 | +Open [http://localhost:5173](http://localhost:5173). |
37 | 36 |
|
38 | | -### Prerequisites |
| 37 | +## Scripts |
39 | 38 |
|
40 | | -- A browser with **WebGPU support** (Recommended: Chrome 113+ or Edge 113+ on Desktop). |
41 | | -- [Node.js](https://nodejs.org/) installed. |
| 39 | +- `npm run dev`: start the Vite dev server |
| 40 | +- `npm run build`: typecheck and build the production bundle |
| 41 | +- `npm run preview`: preview the production build locally |
| 42 | +- `npm run lint`: run ESLint with zero warnings allowed |
| 43 | +- `npm run lint:fix`: apply safe ESLint autofixes |
| 44 | +- `npm run format`: format the repo with Prettier |
| 45 | +- `npm run format:check`: verify formatting without rewriting files |
| 46 | +- `npm run typecheck`: run TypeScript without emitting |
| 47 | +- `npm run test`: run the Vitest suite |
| 48 | +- `npm run test:watch`: run Vitest in watch mode |
| 49 | +- `npm run check`: run lint, typecheck, tests, and build |
42 | 50 |
|
43 | | -### Installation |
| 51 | +## Architecture Notes |
44 | 52 |
|
45 | | -1. **Clone the repository**: |
46 | | - ```bash |
47 | | - git clone <repository-url> |
48 | | - cd web-llm |
49 | | - ``` |
| 53 | +- `src/App.tsx` is the top-level composition layer for the SPA shell. |
| 54 | +- Shared cross-screen UI, chat, and model state lives in `src/store/app-store.ts`. |
| 55 | +- Heavy inference work stays in `src/model.worker.ts` plus the focused worker helpers in `src/worker/`. |
| 56 | +- Chat persistence is handled locally through `src/chat-store.ts`. |
| 57 | +- Lightweight preferences, storage helpers, and storage feedback live in `src/storage.ts`. |
| 58 | +- Tests live in `src/test/` so contributors have one place to look for coverage. |
| 59 | +- There is intentionally no router or backend inference path. |
50 | 60 |
|
51 | | -2. **Install dependencies**: |
52 | | - ```bash |
53 | | - npm install |
54 | | - ``` |
| 61 | +## Quality Gates |
55 | 62 |
|
56 | | -3. **Run the development server**: |
57 | | - ```bash |
58 | | - npm run dev |
59 | | - ``` |
| 63 | +Pull requests are expected to pass: |
60 | 64 |
|
61 | | -4. **Open in Browser**: Navigate to `http://localhost:5173`. |
| 65 | +- `npm run lint` |
| 66 | +- `npm run typecheck` |
| 67 | +- `npm run test` |
| 68 | +- `npm run build` |
62 | 69 |
|
63 | | ---- |
| 70 | +GitHub Actions runs the same checks automatically. |
64 | 71 |
|
65 | | -## 📝 Notes & Limitations |
| 72 | +## Documentation |
66 | 73 |
|
67 | | -- **First Load**: The initial model download (200MB - 900MB depending on the model) may take some time depending on your connection. |
68 | | -- **VRAM**: Older GPUs with limited VRAM may struggle with the Vision/Thinking models. |
69 | | -- **Environment**: This is an experimental proof-of-concept. |
| 74 | +- [Architecture overview](docs/architecture.md) |
| 75 | +- [Model details](docs/models.md) |
| 76 | +- [Contributor guide](CONTRIBUTING.md) |
| 77 | +- [Agent context](AGENTS.md) |
70 | 78 |
|
71 | | ---- |
| 79 | +## Limitations |
72 | 80 |
|
73 | | -## 🤝 Credits |
| 81 | +- First-time model downloads can be large and slow on constrained networks. |
| 82 | +- Larger models remain sensitive to browser, VRAM, and device class. |
| 83 | +- WebGPU support is required for the supported experience. |
74 | 84 |
|
75 | | -Special thanks to the **Hugging Face** team for the amazing [transformers.js](https://huggingface.co/docs/transformers.js/index) library and the open-source community for the quantized ONNX models. |
| 85 | +## License |
76 | 86 |
|
77 | | ---- |
78 | | - |
79 | | -Built with ❤️ for the future of free, private AI. |
80 | | - |
81 | | ---- |
82 | | - |
83 | | -## 📚 Documentation |
84 | | - |
85 | | -- [**🏗️ Architecture & Privacy**](docs/architecture.md): Deep dive into our local-first, WebGPU-powered engine. |
86 | | -- [**🧠 Model Details**](docs/models.md): Understanding the SmolLM and Qwen configurations. |
87 | | -- [**🤖 AI Agent Context**](AGENTS.md): Contextual information for AI coding assistants. |
88 | | - |
89 | | ---- |
90 | | - |
91 | | -## 🤝 Community & Support |
92 | | - |
93 | | -- [**Contributing Guidelines**](CONTRIBUTING.md): How to help improve Browser LLM Chat. |
94 | | -- [**Code of Conduct**](CODE_OF_CONDUCT.md): Our commitment to a welcoming environment. |
95 | | -- [**License**](LICENSE): This project is released under the MIT License. |
| 87 | +MIT |
0 commit comments