@tryhamster/gerbil 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +253 -0
- package/bin/cli.js +2 -0
- package/dist/auto-update-BbNHbSU1.mjs +3 -0
- package/dist/browser/index.d.mts +262 -0
- package/dist/browser/index.d.mts.map +1 -0
- package/dist/browser/index.mjs +755 -0
- package/dist/browser/index.mjs.map +1 -0
- package/dist/chrome-backend-C5Un08O4.mjs +771 -0
- package/dist/chrome-backend-C5Un08O4.mjs.map +1 -0
- package/dist/chrome-backend-CtwPENIW.mjs +3 -0
- package/dist/chunk-Ct1HF2bE.mjs +7 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +7078 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/frameworks/express.d.mts +22 -0
- package/dist/frameworks/express.d.mts.map +1 -0
- package/dist/frameworks/express.mjs +123 -0
- package/dist/frameworks/express.mjs.map +1 -0
- package/dist/frameworks/fastify.d.mts +11 -0
- package/dist/frameworks/fastify.d.mts.map +1 -0
- package/dist/frameworks/fastify.mjs +73 -0
- package/dist/frameworks/fastify.mjs.map +1 -0
- package/dist/frameworks/hono.d.mts +14 -0
- package/dist/frameworks/hono.d.mts.map +1 -0
- package/dist/frameworks/hono.mjs +82 -0
- package/dist/frameworks/hono.mjs.map +1 -0
- package/dist/frameworks/next.d.mts +31 -0
- package/dist/frameworks/next.d.mts.map +1 -0
- package/dist/frameworks/next.mjs +116 -0
- package/dist/frameworks/next.mjs.map +1 -0
- package/dist/frameworks/react.d.mts +56 -0
- package/dist/frameworks/react.d.mts.map +1 -0
- package/dist/frameworks/react.mjs +172 -0
- package/dist/frameworks/react.mjs.map +1 -0
- package/dist/frameworks/trpc.d.mts +12 -0
- package/dist/frameworks/trpc.d.mts.map +1 -0
- package/dist/frameworks/trpc.mjs +80 -0
- package/dist/frameworks/trpc.mjs.map +1 -0
- package/dist/gerbil-BfnsFWRE.mjs +644 -0
- package/dist/gerbil-BfnsFWRE.mjs.map +1 -0
- package/dist/gerbil-BjW-z7Fq.mjs +5 -0
- package/dist/gerbil-DZ1k3ChC.d.mts +138 -0
- package/dist/gerbil-DZ1k3ChC.d.mts.map +1 -0
- package/dist/index.d.mts +223 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/dist/integrations/ai-sdk.d.mts +78 -0
- package/dist/integrations/ai-sdk.d.mts.map +1 -0
- package/dist/integrations/ai-sdk.mjs +199 -0
- package/dist/integrations/ai-sdk.mjs.map +1 -0
- package/dist/integrations/langchain.d.mts +41 -0
- package/dist/integrations/langchain.d.mts.map +1 -0
- package/dist/integrations/langchain.mjs +93 -0
- package/dist/integrations/langchain.mjs.map +1 -0
- package/dist/integrations/llamaindex.d.mts +45 -0
- package/dist/integrations/llamaindex.d.mts.map +1 -0
- package/dist/integrations/llamaindex.mjs +86 -0
- package/dist/integrations/llamaindex.mjs.map +1 -0
- package/dist/integrations/mcp-client.d.mts +206 -0
- package/dist/integrations/mcp-client.d.mts.map +1 -0
- package/dist/integrations/mcp-client.mjs +507 -0
- package/dist/integrations/mcp-client.mjs.map +1 -0
- package/dist/integrations/mcp.d.mts +177 -0
- package/dist/integrations/mcp.d.mts.map +1 -0
- package/dist/integrations/mcp.mjs +8 -0
- package/dist/mcp-R8kRLIKb.mjs +348 -0
- package/dist/mcp-R8kRLIKb.mjs.map +1 -0
- package/dist/models-DKULvhOr.mjs +136 -0
- package/dist/models-DKULvhOr.mjs.map +1 -0
- package/dist/models-De2-_GmQ.d.mts +22 -0
- package/dist/models-De2-_GmQ.d.mts.map +1 -0
- package/dist/one-liner-BUQR0nqq.mjs +98 -0
- package/dist/one-liner-BUQR0nqq.mjs.map +1 -0
- package/dist/skills/index.d.mts +390 -0
- package/dist/skills/index.d.mts.map +1 -0
- package/dist/skills/index.mjs +7 -0
- package/dist/skills-D3CEpgDc.mjs +630 -0
- package/dist/skills-D3CEpgDc.mjs.map +1 -0
- package/dist/tools-BsiEE6f2.mjs +567 -0
- package/dist/tools-BsiEE6f2.mjs.map +1 -0
- package/dist/types-BS1N92Jt.d.mts +183 -0
- package/dist/types-BS1N92Jt.d.mts.map +1 -0
- package/dist/utils-7vXqtq2Q.mjs +63 -0
- package/dist/utils-7vXqtq2Q.mjs.map +1 -0
- package/docs/ai-sdk.md +80 -0
- package/docs/architecture/README.md +84 -0
- package/docs/architecture/caching.md +227 -0
- package/docs/architecture/inference.md +176 -0
- package/docs/architecture/overview.md +179 -0
- package/docs/architecture/streaming.md +261 -0
- package/docs/architecture/webgpu.md +213 -0
- package/docs/browser.md +328 -0
- package/docs/cli.md +155 -0
- package/docs/frameworks.md +90 -0
- package/docs/mcp-client.md +224 -0
- package/docs/mcp.md +109 -0
- package/docs/memory.md +229 -0
- package/docs/repl.md +473 -0
- package/docs/skills.md +261 -0
- package/docs/tools.md +304 -0
- package/package.json +207 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Wheel Go Fast.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://em-content.zobj.net/source/twitter/408/hamster_1f439.png" width="80" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Gerbil</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Local LLM inference for Node.js. GPU-accelerated. Zero config.</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="#install">Install</a> •
|
|
13
|
+
<a href="#quick-start">Quick Start</a> •
|
|
14
|
+
<a href="#skills">Skills</a> •
|
|
15
|
+
<a href="./docs/ai-sdk.md">AI SDK</a> •
|
|
16
|
+
<a href="./docs/frameworks.md">Frameworks</a> •
|
|
17
|
+
<a href="./docs/cli.md">CLI</a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<p align="center">
|
|
21
|
+
<img src="https://img.shields.io/npm/v/@tryhamster/gerbil?style=flat-square" alt="npm version" />
|
|
22
|
+
<img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="license" />
|
|
23
|
+
<img src="https://img.shields.io/badge/node-%3E%3D18-green?style=flat-square" alt="node version" />
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<p align="center">
|
|
27
|
+
<img src="https://img.shields.io/badge/AI_SDK-black?style=flat-square&logo=vercel" alt="AI SDK" />
|
|
28
|
+
<img src="https://img.shields.io/badge/Next.js-black?style=flat-square&logo=next.js" alt="Next.js" />
|
|
29
|
+
<img src="https://img.shields.io/badge/Express-black?style=flat-square&logo=express" alt="Express" />
|
|
30
|
+
<img src="https://img.shields.io/badge/React-black?style=flat-square&logo=react" alt="React" />
|
|
31
|
+
<img src="https://img.shields.io/badge/LangChain-black?style=flat-square" alt="LangChain" />
|
|
32
|
+
<img src="https://img.shields.io/badge/Hono-black?style=flat-square" alt="Hono" />
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import gerbil from "@tryhamster/gerbil";
|
|
39
|
+
|
|
40
|
+
const text = await gerbil("Explain recursion in one sentence");
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Why Gerbil?
|
|
44
|
+
|
|
45
|
+
- **Zero Config** — `npx @tryhamster/gerbil "your prompt"` just works
|
|
46
|
+
- **Local & Private** — No API keys, no data leaves your machine
|
|
47
|
+
- **GPU Accelerated** — WebGPU with CPU fallback
|
|
48
|
+
- **Framework Ready** — AI SDK v5, Next.js, Express, LangChain
|
|
49
|
+
- **Skills System** — Built-in + custom skills with Zod validation
|
|
50
|
+
- **Tool Calling** — Agentic capabilities with Qwen3 models
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Try without installing (one-off usage)
|
|
56
|
+
npx @tryhamster/gerbil
|
|
57
|
+
|
|
58
|
+
# Install globally
|
|
59
|
+
npm install -g @tryhamster/gerbil
|
|
60
|
+
|
|
61
|
+
# Or install in your project
|
|
62
|
+
npm install @tryhamster/gerbil
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
After global install, use `gerbil` directly instead of `npx @tryhamster/gerbil`.
|
|
66
|
+
|
|
67
|
+
## Quick Start
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Gerbil } from "@tryhamster/gerbil";
|
|
71
|
+
|
|
72
|
+
const g = new Gerbil();
|
|
73
|
+
await g.loadModel("qwen3-0.6b");
|
|
74
|
+
|
|
75
|
+
// Generate
|
|
76
|
+
const result = await g.generate("Write a haiku");
|
|
77
|
+
console.log(result.text);
|
|
78
|
+
|
|
79
|
+
// Stream
|
|
80
|
+
for await (const chunk of g.stream("Tell me a story")) {
|
|
81
|
+
process.stdout.write(chunk);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Thinking mode (Qwen3)
|
|
85
|
+
const math = await g.generate("What is 127 × 43?", { thinking: true });
|
|
86
|
+
console.log(math.thinking); // Shows reasoning
|
|
87
|
+
console.log(math.text); // "5461"
|
|
88
|
+
|
|
89
|
+
// Structured JSON
|
|
90
|
+
const data = await g.json("Extract: John, 32, NYC", {
|
|
91
|
+
schema: z.object({ name: z.string(), age: z.number(), city: z.string() }),
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Skills
|
|
96
|
+
|
|
97
|
+
Built-in AI skills with Zod-validated inputs:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { commit, summarize, explain, review } from "@tryhamster/gerbil/skills";
|
|
101
|
+
|
|
102
|
+
const msg = await commit({ type: "conventional" });
|
|
103
|
+
const summary = await summarize({ content: doc, length: "short" });
|
|
104
|
+
const explanation = await explain({ content: code, level: "beginner" });
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Custom Skills
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { defineSkill, loadSkills, useSkill } from "@tryhamster/gerbil/skills";
|
|
111
|
+
|
|
112
|
+
// Define inline
|
|
113
|
+
const sentiment = defineSkill({
|
|
114
|
+
name: "sentiment",
|
|
115
|
+
description: "Analyze text sentiment",
|
|
116
|
+
input: z.object({ text: z.string() }),
|
|
117
|
+
async run(input, gerbil) {
|
|
118
|
+
return gerbil.json(`Sentiment of: ${input.text}`, { schema: outputSchema });
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Or load from files
|
|
123
|
+
await loadSkills("./skills"); // loads *.skill.ts
|
|
124
|
+
const skill = useSkill("my-skill");
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
📖 **[Full Skills Documentation →](./docs/skills.md)**
|
|
128
|
+
|
|
129
|
+
## Tools & Agents
|
|
130
|
+
|
|
131
|
+
Gerbil supports tool calling with Qwen3 models for agentic workflows:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { defineTool, executeToolCall } from "@tryhamster/gerbil";
|
|
135
|
+
|
|
136
|
+
const weatherTool = defineTool({
|
|
137
|
+
name: "get_weather",
|
|
138
|
+
description: "Get weather for a city",
|
|
139
|
+
parameters: z.object({ city: z.string() }),
|
|
140
|
+
execute: async ({ city }) => `Weather in ${city}: 72°F, sunny`,
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Built-in tools:**
|
|
145
|
+
- `gerbil_docs` — Search Gerbil documentation
|
|
146
|
+
- `run_skill` — Execute any Gerbil skill
|
|
147
|
+
|
|
148
|
+
In the REPL, **Agent mode** is on by default and enables tool calling:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npx @tryhamster/gerbil repl
|
|
152
|
+
# Press ⌘A to toggle agent mode on/off
|
|
153
|
+
# Ask: "how do I use gerbil with next.js?"
|
|
154
|
+
# Gerbil will call the docs tool and synthesize an answer
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
📖 **[Full Tools Documentation →](./docs/tools.md)**
|
|
158
|
+
|
|
159
|
+
## CLI
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Without installing (use npx)
|
|
163
|
+
npx @tryhamster/gerbil # Interactive REPL (default)
|
|
164
|
+
npx @tryhamster/gerbil "Write a haiku" # Generate text
|
|
165
|
+
|
|
166
|
+
# After installing globally (npm i -g @tryhamster/gerbil)
|
|
167
|
+
gerbil # Interactive REPL
|
|
168
|
+
gerbil "Write a haiku" # Generate text
|
|
169
|
+
gerbil commit # Commit message from staged changes
|
|
170
|
+
gerbil summarize README.md # Summarize file
|
|
171
|
+
gerbil chat --thinking # Interactive chat
|
|
172
|
+
gerbil serve --mcp # MCP server for Claude/Cursor
|
|
173
|
+
gerbil update # Update to latest version
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
> **Updates**: Gerbil checks for updates but never installs without permission. Press `u` in REPL or run `gerbil update`.
|
|
177
|
+
|
|
178
|
+
📖 **[Full CLI Documentation →](./docs/cli.md)**
|
|
179
|
+
|
|
180
|
+
## Browser Usage
|
|
181
|
+
|
|
182
|
+
Run LLMs directly in the browser with WebGPU — no server required:
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import { useChat } from "@tryhamster/gerbil/browser";
|
|
186
|
+
|
|
187
|
+
function Chat() {
|
|
188
|
+
const { messages, input, setInput, handleSubmit, isLoading } = useChat();
|
|
189
|
+
|
|
190
|
+
if (isLoading) return <div>Loading model...</div>;
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<form onSubmit={handleSubmit}>
|
|
194
|
+
{messages.map(m => <div key={m.id}>{m.role}: {m.content}</div>)}
|
|
195
|
+
<input value={input} onChange={e => setInput(e.target.value)} />
|
|
196
|
+
</form>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
📖 **[Full Browser Documentation →](./docs/browser.md)**
|
|
202
|
+
|
|
203
|
+
## Integrations
|
|
204
|
+
|
|
205
|
+
| Integration | Import | Docs |
|
|
206
|
+
|-------------|--------|------|
|
|
207
|
+
| **Browser** | `@tryhamster/gerbil/browser` | [📖 Browser Guide](./docs/browser.md) |
|
|
208
|
+
| **AI SDK v5** | `@tryhamster/gerbil/ai` | [📖 AI SDK Guide](./docs/ai-sdk.md) |
|
|
209
|
+
| **Next.js** | `@tryhamster/gerbil/next` | [📖 Frameworks](./docs/frameworks.md) |
|
|
210
|
+
| **Express** | `@tryhamster/gerbil/express` | [📖 Frameworks](./docs/frameworks.md) |
|
|
211
|
+
| **React** | `@tryhamster/gerbil/react` | [📖 Frameworks](./docs/frameworks.md) |
|
|
212
|
+
| **LangChain** | `@tryhamster/gerbil/langchain` | [📖 Frameworks](./docs/frameworks.md) |
|
|
213
|
+
| **MCP Server** | `npx @tryhamster/gerbil serve --mcp` | [📖 MCP Guide](./docs/mcp.md) |
|
|
214
|
+
| **MCP Client** | `@tryhamster/gerbil/mcp-client` | [📖 MCP Client](./docs/mcp-client.md) |
|
|
215
|
+
|
|
216
|
+
## Models
|
|
217
|
+
|
|
218
|
+
| Model | Size | Best For |
|
|
219
|
+
|-------|------|----------|
|
|
220
|
+
| `qwen3-0.6b` | ~400MB | General use, reasoning (thinking mode) |
|
|
221
|
+
| `qwen2.5-coder-0.5b` | ~400MB | Code generation |
|
|
222
|
+
| `smollm2-135m` | ~100MB | Quick completions |
|
|
223
|
+
|
|
224
|
+
Use any HuggingFace model: `npx @tryhamster/gerbil -m hf:org/model "prompt"`
|
|
225
|
+
|
|
226
|
+
## Documentation
|
|
227
|
+
|
|
228
|
+
| Guide | Description |
|
|
229
|
+
|-------|-------------|
|
|
230
|
+
| [📖 Browser](./docs/browser.md) | WebGPU inference in the browser |
|
|
231
|
+
| [📖 Skills](./docs/skills.md) | Built-in skills, custom skill development, registry API |
|
|
232
|
+
| [📖 Tools](./docs/tools.md) | Tool calling, agentic workflows, custom tools |
|
|
233
|
+
| [📖 REPL](./docs/repl.md) | Interactive terminal dashboard |
|
|
234
|
+
| [📖 AI SDK](./docs/ai-sdk.md) | Vercel AI SDK v5 integration |
|
|
235
|
+
| [📖 Frameworks](./docs/frameworks.md) | Next.js, Express, React, Fastify, Hono, tRPC, LangChain |
|
|
236
|
+
| [📖 CLI](./docs/cli.md) | All CLI commands and options |
|
|
237
|
+
| [📖 MCP Server](./docs/mcp.md) | MCP server setup for Claude Desktop & Cursor |
|
|
238
|
+
| [📖 MCP Client](./docs/mcp-client.md) | Connect to external MCP servers |
|
|
239
|
+
|
|
240
|
+
## Requirements
|
|
241
|
+
|
|
242
|
+
- Node.js 18+
|
|
243
|
+
- For GPU: WebGPU-compatible environment
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
MIT
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
<p align="center">
|
|
252
|
+
<sub>Part of the <a href="https://tryhamster.com">Hamster</a> family 🐹</sub>
|
|
253
|
+
</p>
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { _ as SystemInfo, a as GenerateOptions, c as GerbilModelSettings, d as LoadOptions, f as ModelConfig, g as SessionStats, h as ProgressInfo, i as FallbackConfig, l as GerbilProviderSettings, m as ModelStats, n as EmbedOptions, o as GenerateResult, p as ModelSource, r as EmbedResult, s as GerbilConfig, t as CacheConfig, u as JsonOptions } from "../types-BS1N92Jt.mjs";
|
|
2
|
+
import { t as BUILTIN_MODELS } from "../models-De2-_GmQ.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/browser/index.d.ts
|
|
5
|
+
|
|
6
|
+
type WorkerProgress = {
|
|
7
|
+
status: "loading" | "downloading" | "ready" | "error";
|
|
8
|
+
message?: string;
|
|
9
|
+
file?: string;
|
|
10
|
+
progress?: number;
|
|
11
|
+
/** Number of files being downloaded (0 = loading from cache) */
|
|
12
|
+
downloadCount?: number;
|
|
13
|
+
/** Total files to process */
|
|
14
|
+
totalFiles?: number;
|
|
15
|
+
error?: string;
|
|
16
|
+
};
|
|
17
|
+
type WorkerToken = {
|
|
18
|
+
status: "token";
|
|
19
|
+
text: string;
|
|
20
|
+
state: "thinking" | "answering";
|
|
21
|
+
numTokens: number;
|
|
22
|
+
tps: number;
|
|
23
|
+
};
|
|
24
|
+
type WorkerComplete = {
|
|
25
|
+
status: "complete";
|
|
26
|
+
text: string;
|
|
27
|
+
numTokens: number;
|
|
28
|
+
totalTime: number;
|
|
29
|
+
tps: number;
|
|
30
|
+
};
|
|
31
|
+
type GerbilWorkerOptions = {
|
|
32
|
+
/** Model ID to load (default: "qwen3-0.6b") */
|
|
33
|
+
modelId?: string;
|
|
34
|
+
/** Called during model loading with progress updates */
|
|
35
|
+
onProgress?: (progress: WorkerProgress) => void;
|
|
36
|
+
/** Called for each token during streaming generation */
|
|
37
|
+
onToken?: (token: WorkerToken) => void;
|
|
38
|
+
/** Called when generation is complete */
|
|
39
|
+
onComplete?: (result: WorkerComplete) => void;
|
|
40
|
+
/** Called on errors */
|
|
41
|
+
onError?: (error: string) => void;
|
|
42
|
+
/** Worker script URL (auto-detected if not provided) */
|
|
43
|
+
workerUrl?: string;
|
|
44
|
+
};
|
|
45
|
+
type GenerateStreamOptions = {
|
|
46
|
+
/** Maximum tokens to generate */
|
|
47
|
+
maxTokens?: number;
|
|
48
|
+
/** Temperature for sampling (0 = deterministic) */
|
|
49
|
+
temperature?: number;
|
|
50
|
+
/** Top-p nucleus sampling */
|
|
51
|
+
topP?: number;
|
|
52
|
+
/** Top-k sampling */
|
|
53
|
+
topK?: number;
|
|
54
|
+
/** Enable thinking mode (Qwen3) */
|
|
55
|
+
thinking?: boolean;
|
|
56
|
+
/** System prompt */
|
|
57
|
+
system?: string;
|
|
58
|
+
};
|
|
59
|
+
type GerbilWorker = {
|
|
60
|
+
/** Generate text with streaming */
|
|
61
|
+
generate: (prompt: string, options?: GenerateStreamOptions) => Promise<string>;
|
|
62
|
+
/** Interrupt current generation */
|
|
63
|
+
interrupt: () => void;
|
|
64
|
+
/** Reset conversation cache */
|
|
65
|
+
reset: () => void;
|
|
66
|
+
/** Terminate the worker */
|
|
67
|
+
terminate: () => void;
|
|
68
|
+
/** Check if model is loaded */
|
|
69
|
+
isReady: () => boolean;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Create a Gerbil worker for streaming WebGPU inference
|
|
73
|
+
*
|
|
74
|
+
* Uses a Web Worker to keep the UI responsive during model loading
|
|
75
|
+
* and text generation, with real-time token streaming.
|
|
76
|
+
*/
|
|
77
|
+
declare function createGerbilWorker(options?: GerbilWorkerOptions): Promise<GerbilWorker>;
|
|
78
|
+
/** Message in a chat conversation */
|
|
79
|
+
type Message = {
|
|
80
|
+
id: string;
|
|
81
|
+
role: "user" | "assistant";
|
|
82
|
+
content: string;
|
|
83
|
+
thinking?: string;
|
|
84
|
+
};
|
|
85
|
+
/** Loading progress state */
|
|
86
|
+
type LoadingProgress = {
|
|
87
|
+
status: "loading" | "downloading" | "ready" | "error";
|
|
88
|
+
message?: string;
|
|
89
|
+
file?: string;
|
|
90
|
+
progress?: number;
|
|
91
|
+
/** Number of files being downloaded (0 = loading from cache) */
|
|
92
|
+
downloadCount?: number;
|
|
93
|
+
/** Total files to process */
|
|
94
|
+
totalFiles?: number;
|
|
95
|
+
};
|
|
96
|
+
/** Options for useChat hook */
|
|
97
|
+
type UseChatOptions = {
|
|
98
|
+
/** Model ID (default: "qwen3-0.6b") */
|
|
99
|
+
model?: string;
|
|
100
|
+
/** System prompt */
|
|
101
|
+
system?: string;
|
|
102
|
+
/** Enable thinking mode (Qwen3) */
|
|
103
|
+
thinking?: boolean;
|
|
104
|
+
/** Max tokens per response */
|
|
105
|
+
maxTokens?: number;
|
|
106
|
+
/** Temperature (0-2) */
|
|
107
|
+
temperature?: number;
|
|
108
|
+
/** Initial messages */
|
|
109
|
+
initialMessages?: Message[];
|
|
110
|
+
/** Auto-load model on mount (default: false - loads on first generate or load()) */
|
|
111
|
+
autoLoad?: boolean;
|
|
112
|
+
/** Called when model is ready */
|
|
113
|
+
onReady?: () => void;
|
|
114
|
+
/** Called on error */
|
|
115
|
+
onError?: (error: string) => void;
|
|
116
|
+
};
|
|
117
|
+
/** Return type for useChat hook */
|
|
118
|
+
type UseChatReturn = {
|
|
119
|
+
/** Chat messages */
|
|
120
|
+
messages: Message[];
|
|
121
|
+
/** Current input value */
|
|
122
|
+
input: string;
|
|
123
|
+
/** Set input value */
|
|
124
|
+
setInput: (value: string) => void;
|
|
125
|
+
/** Submit current input */
|
|
126
|
+
handleSubmit: (e?: {
|
|
127
|
+
preventDefault?: () => void;
|
|
128
|
+
}) => void;
|
|
129
|
+
/** Whether model is loading */
|
|
130
|
+
isLoading: boolean;
|
|
131
|
+
/** Loading progress */
|
|
132
|
+
loadingProgress: LoadingProgress | null;
|
|
133
|
+
/** Whether generating a response */
|
|
134
|
+
isGenerating: boolean;
|
|
135
|
+
/** Current thinking content (streaming) */
|
|
136
|
+
thinking: string;
|
|
137
|
+
/** Stop generation */
|
|
138
|
+
stop: () => void;
|
|
139
|
+
/** Clear all messages */
|
|
140
|
+
clear: () => void;
|
|
141
|
+
/** Current tokens per second */
|
|
142
|
+
tps: number;
|
|
143
|
+
/** Whether model is ready */
|
|
144
|
+
isReady: boolean;
|
|
145
|
+
/** Error message if any */
|
|
146
|
+
error: string | null;
|
|
147
|
+
/** Load the model (only needed if lazy: true) */
|
|
148
|
+
load: () => void;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* React hook for chat with local LLM
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```tsx
|
|
155
|
+
* import { useChat } from "@tryhamster/gerbil/browser";
|
|
156
|
+
*
|
|
157
|
+
* function Chat() {
|
|
158
|
+
* const { messages, input, setInput, handleSubmit, isLoading, isGenerating } = useChat();
|
|
159
|
+
*
|
|
160
|
+
* if (isLoading) return <div>Loading model...</div>;
|
|
161
|
+
*
|
|
162
|
+
* return (
|
|
163
|
+
* <div>
|
|
164
|
+
* {messages.map(m => (
|
|
165
|
+
* <div key={m.id}>{m.role}: {m.content}</div>
|
|
166
|
+
* ))}
|
|
167
|
+
* <form onSubmit={handleSubmit}>
|
|
168
|
+
* <input value={input} onChange={e => setInput(e.target.value)} />
|
|
169
|
+
* <button disabled={isGenerating}>Send</button>
|
|
170
|
+
* </form>
|
|
171
|
+
* </div>
|
|
172
|
+
* );
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function useChat(options?: UseChatOptions): UseChatReturn;
|
|
177
|
+
/** Options for useCompletion hook */
|
|
178
|
+
type UseCompletionOptions = {
|
|
179
|
+
/** Model ID (default: "qwen3-0.6b") */
|
|
180
|
+
model?: string;
|
|
181
|
+
/** System prompt */
|
|
182
|
+
system?: string;
|
|
183
|
+
/** Enable thinking mode (Qwen3) */
|
|
184
|
+
thinking?: boolean;
|
|
185
|
+
/** Max tokens */
|
|
186
|
+
maxTokens?: number;
|
|
187
|
+
/** Temperature (0-2) */
|
|
188
|
+
temperature?: number;
|
|
189
|
+
/** Auto-load model on mount (default: false - loads on first complete() or load()) */
|
|
190
|
+
autoLoad?: boolean;
|
|
191
|
+
/** Called when model is ready */
|
|
192
|
+
onReady?: () => void;
|
|
193
|
+
/** Called on error */
|
|
194
|
+
onError?: (error: string) => void;
|
|
195
|
+
};
|
|
196
|
+
/** Return type for useCompletion hook */
|
|
197
|
+
type UseCompletionReturn = {
|
|
198
|
+
/** Generated completion */
|
|
199
|
+
completion: string;
|
|
200
|
+
/** Thinking content (if enabled) */
|
|
201
|
+
thinking: string;
|
|
202
|
+
/** Generate completion */
|
|
203
|
+
complete: (prompt: string) => Promise<string>;
|
|
204
|
+
/** Whether model is loading */
|
|
205
|
+
isLoading: boolean;
|
|
206
|
+
/** Loading progress */
|
|
207
|
+
loadingProgress: LoadingProgress | null;
|
|
208
|
+
/** Whether generating */
|
|
209
|
+
isGenerating: boolean;
|
|
210
|
+
/** Stop generation */
|
|
211
|
+
stop: () => void;
|
|
212
|
+
/** Current tokens per second */
|
|
213
|
+
tps: number;
|
|
214
|
+
/** Whether model is ready */
|
|
215
|
+
isReady: boolean;
|
|
216
|
+
/** Error message if any */
|
|
217
|
+
error: string | null;
|
|
218
|
+
/** Load the model (only needed if lazy: true) */
|
|
219
|
+
load: () => void;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* React hook for text completion with local LLM
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```tsx
|
|
226
|
+
* import { useCompletion } from "@tryhamster/gerbil/browser";
|
|
227
|
+
*
|
|
228
|
+
* function App() {
|
|
229
|
+
* const { complete, completion, isLoading, isGenerating } = useCompletion();
|
|
230
|
+
*
|
|
231
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
232
|
+
*
|
|
233
|
+
* return (
|
|
234
|
+
* <div>
|
|
235
|
+
* <button onClick={() => complete("Write a haiku")}>Generate</button>
|
|
236
|
+
* <p>{completion}</p>
|
|
237
|
+
* </div>
|
|
238
|
+
* );
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
declare function useCompletion(options?: UseCompletionOptions): UseCompletionReturn;
|
|
243
|
+
/**
|
|
244
|
+
* Check if WebGPU is supported
|
|
245
|
+
*/
|
|
246
|
+
declare function isWebGPUSupported(): boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Get WebGPU adapter info
|
|
249
|
+
*/
|
|
250
|
+
declare function getWebGPUInfo(): Promise<{
|
|
251
|
+
supported: boolean;
|
|
252
|
+
adapter?: string;
|
|
253
|
+
device?: string;
|
|
254
|
+
} | null>;
|
|
255
|
+
declare const _default: {
|
|
256
|
+
isWebGPUSupported: typeof isWebGPUSupported;
|
|
257
|
+
getWebGPUInfo: typeof getWebGPUInfo;
|
|
258
|
+
createGerbilWorker: typeof createGerbilWorker;
|
|
259
|
+
};
|
|
260
|
+
//#endregion
|
|
261
|
+
export { BUILTIN_MODELS, CacheConfig, EmbedOptions, EmbedResult, FallbackConfig, GenerateOptions, GenerateResult, GenerateStreamOptions, GerbilConfig, GerbilModelSettings, GerbilProviderSettings, GerbilWorker, GerbilWorkerOptions, JsonOptions, LoadOptions, LoadingProgress, Message, ModelConfig, ModelSource, ModelStats, ProgressInfo, SessionStats, SystemInfo, UseChatOptions, UseChatReturn, UseCompletionOptions, UseCompletionReturn, WorkerComplete, WorkerProgress, WorkerToken, createGerbilWorker, _default as default, getWebGPUInfo, isWebGPUSupported, useChat, useCompletion };
|
|
262
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/browser/index.ts"],"sourcesContent":[],"mappings":";;;;;KA6DY,cAAA;;;;;;;;;;;KAYA,WAAA;;;;;;;KAQA,cAAA;;;;;;;KAQA,mBAAA;;;;0BAIc;;oBAEN;;wBAEI;;;;;;KAOZ,qBAAA;;;;;;;;;;;;;;KAeA,YAAA;;uCAE2B,0BAA0B;;;;;;;;;;;;;;;;iBAqB3C,kBAAA,WAA4B,sBAA2B,QAAQ;;KAwTzE,OAAA;;;;;;;KAQA,eAAA;;;;;;;;;;;KAYA,cAAA;;;;;;;;;;;;oBAYQ;;;;;;;;;KAUR,aAAA;;YAEA;;;;;;;;;;;;mBAUO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6CH,OAAA,WAAiB,iBAAsB;;KAmQ3C,oBAAA;;;;;;;;;;;;;;;;;;;KAoBA,mBAAA;;;;;;gCAMoB;;;;mBAIb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoCH,aAAA,WAAuB,uBAA4B;;;;iBAqMnD,iBAAA,CAAA;;;;iBAUM,aAAA,CAAA,GAAiB;;;;;cAwBtC"}
|