BenderNet is an innovative chatbot that demonstrates how Small Language Models (SLMs) can produce structured output using grammar-based constraints. Built with WebLLM, LangGraph, and Lark Parser, it features the iconic Bender from Futurama as your sarcastic AI assistant.
- 🧠 Browser-based AI: Runs Qwen3-1.7B model entirely in your browser using WebLLM
- 📝 Grammar-constrained Output: Uses Lark parser to ensure structured responses from the SLM
- 🎭 Bender Personality: Sarcastic, witty responses in the style of Futurama's Bender
- 🔍 Natural Language Queries: Ask questions about product data in plain English
- ⚡ Real-time Processing: Fast query processing with visual feedback
- 🎨 Animated Avatar: Custom SVG Bender avatar with GSAP animations
- 📊 Data Visualization: Interactive table display for query results
Experience BenderNet in action: Live Demo
- Next.js 15: React framework with static export capability
- TypeScript: Type-safe development
- Tailwind CSS: Utility-first CSS framework
- @mlc-ai/web-llm: Browser-based language model execution
- @langchain/langgraph: Agent workflow orchestration
- Lark Parser: Grammar-based output parsing
- Qwen3-1.7B: Small language model (960MB)
- @assistant-ui/react: Chat interface components
- GSAP: High-performance animations
- Framer Motion: React animation library
- Radix UI: Accessible component primitives
- Pyodide: Python runtime in browser (for Lark parser)
- Web Workers: Background processing
- Zustand: State management
- Node.js 18+
- npm, yarn, pnpm, or bun
- Modern browser with WebAssembly support
- ~1GB free RAM (for model loading)
-
Clone the repository
git clone https://github.com/gajananpp/bendernet.git cd bendernet -
Install dependencies
npm install # or yarn install # or pnpm install
-
Set up environment variables (Optional)
cp .env.example .env.local
Add your OpenAI API key if you want to use OpenAI models:
OPENAI_API_KEY=sk-your-api-key-here -
Run the development server
npm run dev # or yarn dev # or pnpm dev
-
Open your browser Navigate to http://localhost:3000
BenderNet demonstrates a novel approach to getting structured output from Small Language Models:
-
Natural Input: Users ask questions in plain English
"Show me all electronics products under $50" -
Grammar-Guided Generation: The SLM generates responses following a specific Lark grammar:
start: query query: "show" columns ("where" condition)? columns: "*" | column_list column_list: IDENTIFIER ("," IDENTIFIER)* condition: IDENTIFIER OPERATOR value
-
Structured Output: The model produces grammar-compliant responses:
show name, price where category = 'electronics' and price < 50 -
Parsing & Execution: Lark parser converts this to structured data and executes the query
User Query → Classifier → Query Generator → Parser → Data Filter → Bender Response
↓ ↓ ↓ ↓ ↓ ↓
Plain Text → Intent Check → Grammar → Structured → Results → Sarcastic Reply
"Show me all products"
"What electronics do we have?"
"Find products under $100"
"Show me out of stock items"
"Display name and price for electronics under $50"
"Show products with stock greater than 10"
"Find all available products in the books category"
Bender responds with his characteristic sarcasm and attitude:
User: "Show me all products"
Bender: "Oh great, another meatbag wants to see the whole catalog. Here's your precious data..."
bender-lark/
├── app/ # Next.js app directory
│ ├── api/chat/ # Chat API endpoint
│ ├── assistant.tsx # Main chat interface
│ ├── model-loader.tsx # WebLLM model loading
│ └── web-llm-worker.ts # WebLLM web worker
├── components/ # React components
│ ├── assistant-ui/ # Chat UI components
│ ├── bender-avatar.tsx # Animated Bender SVG
│ ├── canvas.tsx # Main canvas component
│ └── ui/ # Reusable UI components
├── lib/ # Core utilities
│ ├── agent.ts # LangGraph agent logic
│ ├── lark-parser-api.ts # Lark parser integration
│ ├── ChatWebLLM.ts # WebLLM wrapper
│ └── store.ts # Zustand store
├── assets/ # Static assets
└── public/ # Public files
The project uses Qwen3-1.7B by default. To change the model, update lib/constants.ts:
export const MODEL_NAME = "Qwen3-1.7B-q4f16_1-MLC";
export const MODEL_SIZE = "960MB";Modify the Lark grammar in assets/table-operations.lark.ts to support different query types:
start: query
query: "show" columns ("where" condition)?
| "count" columns ("where" condition)?
| "sum" IDENTIFIER ("where" condition)?The project is configured for static export:
npm run buildThis generates a static site in the out/ directory that can be deployed to:
- Vercel
- Netlify
- GitHub Pages
- Any static hosting service
For production deployment, ensure you have:
- Proper CORS headers for WebAssembly
- Sufficient memory allocation for the model
- HTTPS enabled (required for some WebLLM features)
Create new personality prompts in lib/agent.ts:
const personalityPrompts = {
bender: "Sarcastic robot from Futurama...",
friendly: "Helpful and cheerful assistant...",
professional: "Formal business assistant..."
};Add new query types to the Lark grammar:
query: show_query | count_query | update_query
show_query: "show" columns ("where" condition)?
count_query: "count" ("where" condition)?
update_query: "update" IDENTIFIER "set" assignments ("where" condition)?- Model Size: 960MB (Qwen3-1.7B quantized)
- Load Time: ~30-60 seconds (first time)
- Memory Usage: ~1GB RAM
- Inference Speed: ~2-5 tokens/second (varies by device)
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Sarah Drasner's SVG Animations - SVG animation techniques
- WebLLM Documentation - Browser-based LLM execution
- Lark Parser - Grammar-based parsing
- LangGraph - Agent workflows
- Grammar-Constrained Generation: Ensuring LLM outputs follow specific formats
- Small Language Models: Efficient models for specialized tasks
- Domain Specific Languages (DSL): Custom languages for specific domains
- In-browser AI: Running ML models without server dependencies
- Ensure you have enough RAM (1GB+)
- Check browser console for WebAssembly errors
- Try refreshing the page if loading stalls
- Close other browser tabs to free memory
- Use Chrome/Edge for better WebAssembly performance
- Consider using a more powerful device for better inference speed
- Check that your queries follow the expected grammar
- Ensure the Lark parser worker is loading correctly
- Verify the grammar definition in the assets folder
This project is licensed under the MIT License - see the LICENSE file for details.
Gajanan Patil
- Email: [email protected]
- LinkedIn: gajananpp
- GitHub: gajananpp
- Futurama creators for the iconic Bender character
- MLC-AI team for WebLLM
- LangChain team for LangGraph
- Lark parser developers
- Assistant-UI contributors
- The open-source community
"Bite my shiny metal README!" - Bender 🤖