@beltoinc/slyos-sdk 1.5.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/README.md +434 -0
- package/create-chatbot.sh +634 -0
- package/dist/index.d.ts +278 -0
- package/dist/index.js +1483 -0
- package/package.json +35 -0
- package/src/index.ts +1856 -0
- package/tsconfig.json +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
# 🔥 @beltoinc/slyos-sdk
|
|
2
|
+
|
|
3
|
+
Official SDK for SlyOS on-device AI platform. Run AI models locally in browsers and Node.js.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📦 Installation
|
|
8
|
+
```bash
|
|
9
|
+
npm install @beltoinc/slyos-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
**npm:** https://www.npmjs.com/package/@beltoinc/slyos-sdk
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 🚀 Quick Start
|
|
17
|
+
```javascript
|
|
18
|
+
import SlyOS from '@beltoinc/slyos-sdk';
|
|
19
|
+
|
|
20
|
+
// 1. Initialize
|
|
21
|
+
const sdk = new SlyOS({
|
|
22
|
+
apiKey: 'sk_live_your_api_key'
|
|
23
|
+
});
|
|
24
|
+
await sdk.initialize();
|
|
25
|
+
|
|
26
|
+
// 2. Load model (downloads ~200MB once)
|
|
27
|
+
await sdk.loadModel('quantum-1.7b');
|
|
28
|
+
|
|
29
|
+
// 3. Generate responses
|
|
30
|
+
const response = await sdk.generate('quantum-1.7b',
|
|
31
|
+
'What is artificial intelligence?',
|
|
32
|
+
{
|
|
33
|
+
temperature: 0.7,
|
|
34
|
+
maxTokens: 100,
|
|
35
|
+
topP: 0.9
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
console.log(response);
|
|
40
|
+
// AI runs locally - no per-inference charges!
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 📚 API Reference
|
|
46
|
+
|
|
47
|
+
### Constructor
|
|
48
|
+
```typescript
|
|
49
|
+
new SlyOS(config: SlyOSConfig)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Config:**
|
|
53
|
+
```typescript
|
|
54
|
+
{
|
|
55
|
+
apiKey: string; // Get from dashboard
|
|
56
|
+
apiUrl?: string; // Optional, defaults to production
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### Methods
|
|
63
|
+
|
|
64
|
+
#### `initialize()`
|
|
65
|
+
Authenticates with SlyOS backend and registers device.
|
|
66
|
+
```javascript
|
|
67
|
+
await sdk.initialize();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Returns:** `Promise<DeviceProfile>`
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
#### `loadModel(modelId)`
|
|
75
|
+
Downloads and caches AI model locally.
|
|
76
|
+
```javascript
|
|
77
|
+
await sdk.loadModel('quantum-1.7b');
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Parameters:**
|
|
81
|
+
- `modelId` (string): Model identifier
|
|
82
|
+
- `quantum-1.7b` - 900MB, recommended
|
|
83
|
+
- `quantum-3b` - 1.6GB, high quality
|
|
84
|
+
- `quantum-code-3b` - 1.6GB, code-optimized
|
|
85
|
+
- `quantum-8b` - 4.2GB, best quality
|
|
86
|
+
|
|
87
|
+
**Returns:** `Promise<void>`
|
|
88
|
+
|
|
89
|
+
**First call:** Downloads model (~1-2 min)
|
|
90
|
+
**Subsequent calls:** Uses cached model (<1 sec)
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
#### `generate(modelId, prompt, options?)`
|
|
95
|
+
Generates AI response locally.
|
|
96
|
+
```javascript
|
|
97
|
+
const response = await sdk.generate('quantum-1.7b',
|
|
98
|
+
'Tell me about your menu',
|
|
99
|
+
{
|
|
100
|
+
temperature: 0.7,
|
|
101
|
+
maxTokens: 150,
|
|
102
|
+
topP: 0.9
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Parameters:**
|
|
108
|
+
- `modelId` (string): Model to use
|
|
109
|
+
- `prompt` (string): Input text
|
|
110
|
+
- `options` (object, optional):
|
|
111
|
+
- `temperature` (0-2): Creativity (default: 0.7)
|
|
112
|
+
- `maxTokens` (10-2000): Max response length (default: 100)
|
|
113
|
+
- `topP` (0-1): Nucleus sampling (default: 0.9)
|
|
114
|
+
|
|
115
|
+
**Returns:** `Promise<string>` - Generated text
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
#### `chatCompletion(options)`
|
|
120
|
+
OpenAI-compatible chat completions.
|
|
121
|
+
```javascript
|
|
122
|
+
const response = await sdk.chatCompletion({
|
|
123
|
+
model: 'quantum-3b',
|
|
124
|
+
messages: [
|
|
125
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
126
|
+
{ role: 'user', content: 'Explain quantum computing' }
|
|
127
|
+
],
|
|
128
|
+
temperature: 0.7,
|
|
129
|
+
maxTokens: 512,
|
|
130
|
+
topP: 0.9,
|
|
131
|
+
frequencyPenalty: 0,
|
|
132
|
+
presencePenalty: 0
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
console.log(response.choices[0].message.content);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Parameters:**
|
|
139
|
+
- `model` (string): Model ID to use
|
|
140
|
+
- `messages` (array): Conversation messages with role and content
|
|
141
|
+
- `temperature` (0-2, optional): Creativity control (default: 0.7)
|
|
142
|
+
- `maxTokens` (optional): Maximum response length
|
|
143
|
+
- `topP` (0-1, optional): Nucleus sampling
|
|
144
|
+
- `frequencyPenalty` (optional): Reduce repeated tokens
|
|
145
|
+
- `presencePenalty` (optional): Encourage new topics
|
|
146
|
+
|
|
147
|
+
**Returns:** `Promise<ChatCompletionResponse>`
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
#### `transcribe(modelId, audio, options?)`
|
|
152
|
+
Speech-to-text using voicecore models.
|
|
153
|
+
```javascript
|
|
154
|
+
const audioData = await fetch('audio.wav').then(r => r.arrayBuffer());
|
|
155
|
+
|
|
156
|
+
const result = await sdk.transcribe('voicecore-base', audioData, {
|
|
157
|
+
language: 'en'
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
console.log(result.text); // Transcribed text
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Parameters:**
|
|
164
|
+
- `modelId` (string): STT model (`voicecore-base` or `voicecore-small`)
|
|
165
|
+
- `audio` (ArrayBuffer): Audio data
|
|
166
|
+
- `options` (object, optional):
|
|
167
|
+
- `language` (string): Language code (default: 'en')
|
|
168
|
+
|
|
169
|
+
**Returns:** `Promise<TranscriptionResult>`
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
#### `recommendModel(category?)`
|
|
174
|
+
Returns best model for the current device's hardware.
|
|
175
|
+
```javascript
|
|
176
|
+
const recommendation = sdk.recommendModel('llm');
|
|
177
|
+
console.log(recommendation.modelId); // e.g., 'quantum-1.7b'
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
#### `searchModels(query, options?)`
|
|
183
|
+
Search HuggingFace Hub for ONNX-compatible models.
|
|
184
|
+
```javascript
|
|
185
|
+
const results = await sdk.searchModels('code generation', {
|
|
186
|
+
limit: 10
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
results.forEach(model => {
|
|
190
|
+
console.log(model.name, model.downloads);
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Parameters:**
|
|
195
|
+
- `query` (string): Search keywords
|
|
196
|
+
- `options` (object, optional):
|
|
197
|
+
- `limit` (number): Results to return (default: 5)
|
|
198
|
+
|
|
199
|
+
**Returns:** `Promise<Array<ModelSearchResult>>`
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
#### `getDeviceProfile()`
|
|
204
|
+
Returns the device's hardware profile (CPU, RAM, GPU, screen, network).
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
#### `getModelContextWindow()`
|
|
209
|
+
Returns current model's context window size in tokens.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
#### `getDeviceId()`
|
|
214
|
+
Returns the persistent device identifier.
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
#### `destroy()`
|
|
219
|
+
Flushes pending telemetry and cleans up timers. Call before shutting down.
|
|
220
|
+
```javascript
|
|
221
|
+
await sdk.destroy(); // Ensures telemetry is sent
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### `getSdkVersion()`
|
|
225
|
+
Returns the current SDK version string (e.g. `'1.4.0'`).
|
|
226
|
+
|
|
227
|
+
#### `getAvailableModels()`
|
|
228
|
+
Returns available models grouped by category (`llm`, `stt`).
|
|
229
|
+
|
|
230
|
+
#### `canRunModel(modelId, quant?)`
|
|
231
|
+
Checks if the current device can run a specific model based on hardware profile.
|
|
232
|
+
|
|
233
|
+
#### `ragQuery(modelId, knowledgeBaseId, query, options?)`
|
|
234
|
+
Performs a RAG query against a cloud-indexed knowledge base. Requires Hybrid RAG plan.
|
|
235
|
+
|
|
236
|
+
#### `ragQueryLocal(modelId, knowledgeBaseId, query, options?)`
|
|
237
|
+
Performs a RAG query using locally-cached embeddings for offline-capable retrieval.
|
|
238
|
+
|
|
239
|
+
#### `ragQueryOffline(modelId, knowledgeBaseId, query, options?)`
|
|
240
|
+
Fully offline RAG query using pre-synced knowledge base data.
|
|
241
|
+
|
|
242
|
+
#### `syncKnowledgeBase(knowledgeBaseId)`
|
|
243
|
+
Downloads and caches a knowledge base locally for offline RAG queries.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 🌐 Platform Support
|
|
248
|
+
|
|
249
|
+
| Platform | Status | Notes |
|
|
250
|
+
|----------|--------|-------|
|
|
251
|
+
| **Chrome** | ✅ Supported | Recommended |
|
|
252
|
+
| **Safari** | ✅ Supported | iOS 16+ |
|
|
253
|
+
| **Edge** | ✅ Supported | Chromium-based |
|
|
254
|
+
| **Firefox** | ⚠️ Limited | Some models work |
|
|
255
|
+
| **Node.js** | ✅ Supported | v18+ |
|
|
256
|
+
| **React Native** | 🚧 Coming Soon | Q3 2026 |
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## 💡 Usage Examples
|
|
261
|
+
|
|
262
|
+
### Basic Chatbot
|
|
263
|
+
```javascript
|
|
264
|
+
import SlyOS from '@beltoinc/slyos-sdk';
|
|
265
|
+
|
|
266
|
+
const sdk = new SlyOS({ apiKey: 'sk_live_...' });
|
|
267
|
+
await sdk.initialize();
|
|
268
|
+
await sdk.loadModel('quantum-1.7b');
|
|
269
|
+
|
|
270
|
+
async function chat(userMessage) {
|
|
271
|
+
return await sdk.generate('quantum-1.7b', userMessage);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const response = await chat('What are your hours?');
|
|
275
|
+
console.log(response);
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
### With System Prompt
|
|
281
|
+
```javascript
|
|
282
|
+
const systemPrompt = `You are a helpful assistant for McDonald's.
|
|
283
|
+
Help with menu, hours, and nutrition. Be friendly and concise.`;
|
|
284
|
+
|
|
285
|
+
const userMessage = 'What breakfast items do you have?';
|
|
286
|
+
const fullPrompt = `${systemPrompt}\n\nCustomer: ${userMessage}\nAssistant:`;
|
|
287
|
+
|
|
288
|
+
const response = await sdk.generate('quantum-1.7b', fullPrompt, {
|
|
289
|
+
temperature: 0.7,
|
|
290
|
+
maxTokens: 150
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
### React Integration
|
|
297
|
+
```jsx
|
|
298
|
+
import { useState, useEffect } from 'react';
|
|
299
|
+
import SlyOS from '@beltoinc/slyos-sdk';
|
|
300
|
+
|
|
301
|
+
function Chatbot() {
|
|
302
|
+
const [sdk, setSdk] = useState(null);
|
|
303
|
+
const [loading, setLoading] = useState(true);
|
|
304
|
+
const [response, setResponse] = useState('');
|
|
305
|
+
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
async function init() {
|
|
308
|
+
const client = new SlyOS({ apiKey: 'sk_live_...' });
|
|
309
|
+
await client.initialize();
|
|
310
|
+
await client.loadModel('quantum-1.7b');
|
|
311
|
+
setSdk(client);
|
|
312
|
+
setLoading(false);
|
|
313
|
+
}
|
|
314
|
+
init();
|
|
315
|
+
}, []);
|
|
316
|
+
|
|
317
|
+
async function handleChat(message) {
|
|
318
|
+
const reply = await sdk.generate('quantum-1.7b', message);
|
|
319
|
+
setResponse(reply);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (loading) return <div>Loading AI...</div>;
|
|
323
|
+
|
|
324
|
+
return (
|
|
325
|
+
<div>
|
|
326
|
+
<button onClick={() => handleChat('Hello!')}>
|
|
327
|
+
Chat
|
|
328
|
+
</button>
|
|
329
|
+
<p>{response}</p>
|
|
330
|
+
</div>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## 🔧 Advanced Configuration
|
|
338
|
+
|
|
339
|
+
### Custom Backend URL
|
|
340
|
+
```javascript
|
|
341
|
+
const sdk = new SlyOS({
|
|
342
|
+
apiKey: 'sk_live_...',
|
|
343
|
+
apiUrl: 'https://api.slyos.world'
|
|
344
|
+
});
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
### Multiple Models
|
|
350
|
+
```javascript
|
|
351
|
+
await sdk.loadModel('quantum-1.7b');
|
|
352
|
+
await sdk.loadModel('quantum-3b');
|
|
353
|
+
|
|
354
|
+
// Use different models
|
|
355
|
+
const fast = await sdk.generate('quantum-1.7b', 'Quick question?');
|
|
356
|
+
const detailed = await sdk.generate('quantum-3b', 'Complex question?');
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## 📊 Performance
|
|
362
|
+
|
|
363
|
+
### Benchmarks (Quantum 1.7B)
|
|
364
|
+
|
|
365
|
+
| Metric | Browser | Node.js |
|
|
366
|
+
|--------|---------|---------|
|
|
367
|
+
| First load | 60-120s | 30-60s |
|
|
368
|
+
| Cached load | <1s | <0.5s |
|
|
369
|
+
| Inference | 10-15 tok/s | 15-25 tok/s |
|
|
370
|
+
| Memory | 1.2GB | 900MB |
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
## 🐛 Troubleshooting
|
|
375
|
+
|
|
376
|
+
### Model won't load
|
|
377
|
+
```javascript
|
|
378
|
+
// Check browser console for errors
|
|
379
|
+
// Ensure 2GB+ RAM available
|
|
380
|
+
// Try smaller model (quantum-1.7b)
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### CORS errors
|
|
384
|
+
```javascript
|
|
385
|
+
// Backend must allow your domain
|
|
386
|
+
// Check CORS_ORIGIN environment variable
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Slow inference
|
|
390
|
+
```javascript
|
|
391
|
+
// Use smaller model
|
|
392
|
+
// Reduce maxTokens
|
|
393
|
+
// Check CPU/RAM availability
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## 🔒 Security
|
|
399
|
+
|
|
400
|
+
- API keys stored client-side (localStorage)
|
|
401
|
+
- All inference happens locally (private)
|
|
402
|
+
- Inference telemetry batched locally (flushed every 10 inferences or 60s)
|
|
403
|
+
- No user data sent to cloud
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## 📦 Package Info
|
|
408
|
+
|
|
409
|
+
- **Package:** `@beltoinc/slyos-sdk`
|
|
410
|
+
- **Version:** 1.4.0
|
|
411
|
+
- **License:** Proprietary
|
|
412
|
+
- **Size:** 168 KB (unpacked)
|
|
413
|
+
- **Dependencies:** axios, @huggingface/transformers
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## 📄 License
|
|
418
|
+
|
|
419
|
+
Proprietary — See LICENSE file for details
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## 🙏 Credits
|
|
424
|
+
|
|
425
|
+
Built with Hugging Face Transformers.js
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## 📞 Support
|
|
430
|
+
|
|
431
|
+
- **npm:** https://www.npmjs.com/package/@beltoinc/slyos-sdk
|
|
432
|
+
- **GitHub:** https://github.com/BeltoAI/sly.os
|
|
433
|
+
- **Docs:** See main README.md
|
|
434
|
+
- **Email:** support@slyos.world
|