File size: 7,524 Bytes
31241d9
 
 
 
 
 
 
 
 
 
 
 
 
 
fd2b7a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
---
tags:
  - transformers.js
  - webassembly
  - browser-llm
  - function-calling
  - gorilla
  - local-ai
license: mit
language: en
pipeline_tag: text-generation
library_name: transformers.js
---

# PROJECT: BOB

**Local-first, serverless, tool-calling AI running entirely in your browser via WebAssembly.**

![Demo](https://img.shields.io/badge/Demo-Live-brightgreen?style=for-the-badge&logo=githubpages)
![Model](https://img.shields.io/badge/Model-Gorilla_3B-orange?style=for-the-badge&logo=huggingface)
![License](https://img.shields.io/badge/License-MIT-blue?style=for-the-badge)

---

## What is Bob?

Bob is a personal AI assistant that runs **100% locally in your browser**. No servers, no cloud, no tracking, no API keys required after initial model download (~600MB). Built with [Transformers.js](https://github.com/xenova/transformers.js) and [Gorilla OpenFunctions](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v2).

### Key Features

- πŸ”’ **Zero Server** β€” Runs entirely client-side via WebAssembly
- πŸ›  **Tool Calling** β€” Native function calling: `get_crypto_price`, `multiply_numbers`
- 🌐 **Offline-Capable** β€” Works after first load (model cached in IndexedDB)
- ⚑ **Instant Deploy** β€” Static files on GitHub Pages
- 🎨 **Stark UI** β€” Pure black/white high-contrast interface

---

## Live Demo

**https://yummyfiles.github.io/Project-Bob/**

---

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      BROWSER (Client)                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  index.html  β†’  app.js  β†’  @xenova/transformers (WASM)      β”‚
β”‚                              ↓                               β”‚
β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                      β”‚
β”‚                    β”‚  Gorilla-3B-4bit β”‚  ← Cached in         β”‚
β”‚                    β”‚  (ONNX quantized)β”‚  ← IndexedDB         β”‚
β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                      β”‚
β”‚                             β”‚                                β”‚
β”‚                    <call_tool> detection                     β”‚
β”‚                             ↓                                β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚              β–Ό                             β–Ό                 β”‚
β”‚      get_crypto_price()            multiply_numbers()       β”‚
β”‚      (CoinGecko API)               (local JS math)          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## Quick Start

### Use Online (No Setup)
Visit **https://yummyfiles.github.io/Project-Bob/** β€” loads model on first visit.

### Run Locally
```bash
git clone https://github.com/yummyfiles/Project-Bob
cd Project-Bob
npx serve  # or python -m http.server 8000
# Open http://localhost:3000
```

---

## Model

| Component | Details |
|-----------|---------|
| **Base** | `gorilla-llm/gorilla-openfunctions-v2` (3B params) |
| **Format** | ONNX INT4 quantized via Optimum |
| **Runtime** | Transformers.js (ONNX Runtime Web + WebAssembly) |
| **Size** | ~600MB download, cached after first load |
| **Capabilities** | Function calling, chat, reasoning |

### Why Gorilla?
- Trained specifically for **function calling** (API interaction)
- Open-source, Apache 2.0 license
- Works well quantized to 4-bit
- Small enough for browser inference

---

## Tool System

Bob detects `<call_tool>` tags in model output and executes matching JavaScript functions.

### Built-in Tools

| Tool | Description | Example |
|------|-------------|---------|
| `get_crypto_price(symbol)` | Fetches live crypto price from CoinGecko | `"BTC"` β†’ `"$67,420"` |
| `multiply_numbers(a, b)` | Multiplies two numbers locally | `144, 37` β†’ `5328` |

### Adding Tools

```javascript
// In app.js, extend customTools object:
const customTools = {
  get_crypto_price: async (symbol) => { ... },
  multiply_numbers: (a, b) => a * b,
  // Add yours here:
  my_custom_tool: async (arg1, arg2) => { ... }
};
```

Model prompt includes tool schemas β€” it learns to call them automatically.

---

## Project Structure

```
Project-Bob/
β”œβ”€β”€ index.html          # Stark black/white UI
β”œβ”€β”€ app.js              # Transformers.js runtime + tool engine
β”œβ”€β”€ dataset.jsonl       # Fine-tuning examples (QLoRA format)
β”œβ”€β”€ colab_training_notebook.py  # Google Colab training script
β”œβ”€β”€ push_assets.py      # Deploy to GitHub Pages + HF Hub
└── README.md           # This file
```

---

## Fine-Tuning Your Own Bob

Train a specialized version on your data:

1. **Open Colab**: Upload `colab_training_notebook.ipynb`
2. **GPU Runtime**: Runtime β†’ Change runtime type β†’ T4 GPU
3. **Secrets**: Add `HF_TOKEN` (write access)
4. **Run All**: ~15 minutes on T4
5. **Result**: Trained LoRA + ONNX 4-bit pushed to `yummyfiles/Bob`

### Dataset Format (dataset.jsonl)

```jsonl
{"text": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>What is the current price of Bitcoin?<|eot_id|><|start_header_id|>assistant<|end_header_id|><call_tool>get_crypto_price({\"symbol\": \"BTC\"})</call_tool><|eot_id|>"}
{"text": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>Multiply 42 by 58 for me.<|eot_id|><|start_header_id|>assistant<|end_header_id|><call_tool>multiply_numbers({\"a\": 42, \"b\": 58})</call_tool><|eot_id|>"}
```

---

## Deployment

### GitHub Pages (Frontend)
```bash
python push_assets.py
# Pushes index.html, app.js β†’ yummyfiles/Project-Bob (main branch)
# Enable Pages in repo settings: Source = main branch
```

### Hugging Face Hub (Model)
```bash
python push_assets.py
# Uploads model artifacts β†’ yummyfiles/Bob
```

---

## Tech Stack

| Layer | Technology |
|-------|------------|
| **ML Runtime** | Transformers.js 2.17+ (ONNX Runtime Web + WASM) |
| **Model** | Gorilla OpenFunctions v2 (3B, INT4) |
| **Tools** | Native JS async functions |
| **Frontend** | Vanilla HTML/CSS/JS (ES Modules) |
| **Hosting** | GitHub Pages (static) |
| **Model Hub** | Hugging Face Hub |

---

## Browser Support

| Browser | Support |
|---------|---------|
| Chrome 94+ | βœ… Full |
| Firefox 93+ | βœ… Full |
| Safari 15.4+ | βœ… Full |
| Edge 94+ | βœ… Full |

Requires: `SharedArrayBuffer`, `WebAssembly`, `WebGL`/`WebGPU`

---

## Privacy

- **No telemetry**
- **No external requests** except:
  - Model download (once, from HF CDN)
  - `get_crypto_price` β†’ CoinGecko public API
- **All inference local** β€” your prompts never leave your device

---

## License

MIT β€” Free for any use.

---

## Credits

- [Transformers.js](https://github.com/xenova/transformers.js) by Xenova
- [Gorilla OpenFunctions](https://huggingface.co/gorilla-llm/gorilla-openfunctions-v2) by Gorilla LLM team
- [Optimum](https://github.com/huggingface/optimum) for ONNX export
- [CoinGecko](https://www.coingecko.com/api) for crypto prices

---

**Built for local-first AI. No cloud required.**