react-web-llm-hooks is a lightweight and powerful React hook that brings Large Language Models directly to your browser. Built on top of @mlc-ai/web-llm, it enables you to integrate AI capabilities into React applications without any backend serverβeverything runs locally in the user's browser.
| Feature | Description |
|---|---|
| π Zero-Server Architecture | No API calls, no server costs, no latency. All inference happens in the browser. |
| π¦ Scalable by Design | Modular hook API that grows with your applicationβfrom simple chatbots to complex AI features. |
| β‘ High Performance | Leverages WebGPU for accelerated inference. Optimized for modern browsers. |
| π Framework Agnostic | Works seamlessly with any React setupβNext.js, Vite, Remix, CRA, and more. |
| π Privacy First | User data never leaves their device. Perfect for privacy-sensitive applications. |
| π― Production Ready | TypeScript support out of the box, battle-tested patterns, clean API surface. |
npm install @mlc-ai/web-llm react-web-llm-hooks
# or
yarn add @mlc-ai/web-llm react-web-llm-hooksimport { useWebLLM } from 'react-web-llm-hooks';
function ChatComponent() {
const { isReady, status, response, send } = useWebLLM();
const handleSend = () => {
send('Hello, world!');
};
if (!isReady) {
return <div>Loading model... {status}</div>;
}
return (
<div>
<p>Response: {response}</p>
<button onClick={handleSend}>Send Message</button>
</div>
);
}const { send } = useWebLLM({
model: 'Qwen2.5-1.5B-Instruct-q4f32_1-MLC', // Default model
temperature: 0.7,
maxTokens: 1024,
});The primary hook for integrating WebLLM into your React components.
| Option | Type | Default | Description |
|---|---|---|---|
model |
string |
'Qwen2.5-1.5B-Instruct-q4f32_1-MLC' |
The LLM model to load. See supported models. |
temperature |
number |
0.7 |
Controls randomness in output generation. Lower values = more focused. |
maxTokens |
number |
1024 |
Maximum number of tokens to generate. |
progressCallback |
function |
undefined |
Callback for model loading progress. |
| Property | Type | Description |
|---|---|---|
isReady |
boolean |
Whether the model has finished loading. |
status |
string |
Current loading status or error message. |
response |
string |
The latest generated response. |
send(message: string) |
function |
Send a message and get a response. |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your React App β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β react-web-llm-hooks β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β useWebLLM Hook ββ
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ ββ
β β β Engine β β State β β Utils β ββ
β β β Manager βββ Management βββ & Helpers β ββ
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ ββ
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β @mlc-ai/web-llm β
β (WebGPU-powered LLM inference engine) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β WebGPU β
β (Browser-native GPU acceleration) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Model | Size | Memory | Performance |
|---|---|---|---|
| Qwen2.5-1.5B-Instruct | 1.5B | ~2GB VRAM | β‘ Fast |
| Qwen2.5-3B-Instruct | 3B | ~4GB VRAM | β‘ Fast |
| Llama-3.2-3B-Instruct | 3B | ~4GB VRAM | β‘ Fast |
| Gemma-2-2B-it | 2B | ~3GB VRAM | β‘ Fast |
- Chrome 113+ (with WebGPU support)
- Edge 113+
- Firefox (WebGPU in development)
- Safari 17+ (WebGPU support)
Note: WebGPU must be enabled in your browser settings.
We welcome contributions! Whether you're fixing bugs, adding features, or improving documentationβyour help makes this project better.
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/react-web-llm-hooks.git cd react-web-llm-hooks - Install dependencies:
npm install
- Start the development server:
npm run dev
- Create a feature branch:
git checkout -b feature/amazing-new-feature
- Make your changes and commit:
git commit -m "Add amazing new feature" - Push and open a Pull Request:
git push origin feature/amazing-new-feature
- π Documentation - Improve guides, add examples, fix typos
- π Bug Fixes - Find and fix issues in the codebase
- β¨ New Features - Add model support, configuration options
- π¨ Examples - Create demo apps, integration guides
- β‘ Performance - Optimize inference, reduce memory usage
- π§ͺ Testing - Add unit tests, integration tests
Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
- Multiple model support with dynamic switching
- Streaming responses support
- Conversation history management
- Custom system prompts
- Plugin system for preprocessing/postprocessing
- React Native support
- Comprehensive test suite
- Demo application with multiple use cases
MIT License - see LICENSE for details.
- @mlc-ai/web-llm - The amazing engine that powers this project
- Vite - Next-generation frontend tooling
- Tailwind CSS - Utility-first CSS framework
If you find this project useful, please consider giving it a βοΈ star on GitHub! It helps others discover the project and motivates continued development.
Questions? Issues? Feature requests?
Open an issue on GitHubβwe'd love to hear from you!