@emilshirokikh/slyos-sdk 1.3.0 → 1.3.2
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/create-chatbot.sh +506 -0
- package/dist/index.js +6 -1
- package/package.json +1 -1
- package/src/index.ts +6 -1
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
#################################################################################
|
|
4
|
+
# Slyos Chatbot Setup Script
|
|
5
|
+
#
|
|
6
|
+
# This script creates a fully functional interactive chatbot using the Slyos SDK.
|
|
7
|
+
# Supports both Mac and Windows (via bash/powershell).
|
|
8
|
+
#
|
|
9
|
+
# Usage:
|
|
10
|
+
# ./create-chatbot.sh [--api-key YOUR_KEY] [--model MODEL_NAME]
|
|
11
|
+
#
|
|
12
|
+
# Examples:
|
|
13
|
+
# ./create-chatbot.sh
|
|
14
|
+
# ./create-chatbot.sh --api-key sk_123456789 --model quantum-1.7b
|
|
15
|
+
#################################################################################
|
|
16
|
+
|
|
17
|
+
set -e
|
|
18
|
+
|
|
19
|
+
# Color codes for terminal output
|
|
20
|
+
RED='\033[0;31m'
|
|
21
|
+
GREEN='\033[0;32m'
|
|
22
|
+
YELLOW='\033[1;33m'
|
|
23
|
+
BLUE='\033[0;34m'
|
|
24
|
+
CYAN='\033[0;36m'
|
|
25
|
+
NC='\033[0m' # No Color
|
|
26
|
+
|
|
27
|
+
# Default values
|
|
28
|
+
API_KEY=""
|
|
29
|
+
MODEL="quantum-1.7b"
|
|
30
|
+
SLYOS_SERVER="https://slyos-prod.eba-qjz3cmgq.us-east-2.elasticbeanstalk.com"
|
|
31
|
+
PROJECT_NAME="slyos-chatbot"
|
|
32
|
+
|
|
33
|
+
#################################################################################
|
|
34
|
+
# Helper Functions
|
|
35
|
+
#################################################################################
|
|
36
|
+
|
|
37
|
+
print_header() {
|
|
38
|
+
echo -e "\n${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
|
|
39
|
+
echo -e "${BLUE}║${NC} ${CYAN}Slyos Interactive Chatbot Setup${NC} ${BLUE}║${NC}"
|
|
40
|
+
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}\n"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
print_step() {
|
|
44
|
+
echo -e "${CYAN}▶${NC} $1"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
print_success() {
|
|
48
|
+
echo -e "${GREEN}✓${NC} $1"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
print_error() {
|
|
52
|
+
echo -e "${RED}✗${NC} $1" >&2
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
print_info() {
|
|
56
|
+
echo -e "${YELLOW}ℹ${NC} $1"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#################################################################################
|
|
60
|
+
# Argument Parsing
|
|
61
|
+
#################################################################################
|
|
62
|
+
|
|
63
|
+
while [[ $# -gt 0 ]]; do
|
|
64
|
+
case $1 in
|
|
65
|
+
--api-key)
|
|
66
|
+
API_KEY="$2"
|
|
67
|
+
shift 2
|
|
68
|
+
;;
|
|
69
|
+
--model)
|
|
70
|
+
MODEL="$2"
|
|
71
|
+
shift 2
|
|
72
|
+
;;
|
|
73
|
+
-h|--help)
|
|
74
|
+
echo "Usage: $0 [OPTIONS]"
|
|
75
|
+
echo ""
|
|
76
|
+
echo "Options:"
|
|
77
|
+
echo " --api-key KEY Slyos API key (prompted if not provided)"
|
|
78
|
+
echo " --model MODEL AI model to use (default: quantum-1.7b)"
|
|
79
|
+
echo " -h, --help Show this help message"
|
|
80
|
+
exit 0
|
|
81
|
+
;;
|
|
82
|
+
*)
|
|
83
|
+
print_error "Unknown option: $1"
|
|
84
|
+
exit 1
|
|
85
|
+
;;
|
|
86
|
+
esac
|
|
87
|
+
done
|
|
88
|
+
|
|
89
|
+
#################################################################################
|
|
90
|
+
# Main Setup
|
|
91
|
+
#################################################################################
|
|
92
|
+
|
|
93
|
+
print_header
|
|
94
|
+
|
|
95
|
+
# Prompt for API key if not provided
|
|
96
|
+
if [ -z "$API_KEY" ]; then
|
|
97
|
+
if [ -t 0 ]; then
|
|
98
|
+
print_step "Enter your Slyos API key (or press Enter for placeholder)"
|
|
99
|
+
read -r -p " API Key: " API_KEY
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
if [ -z "$API_KEY" ]; then
|
|
103
|
+
API_KEY="YOUR_API_KEY"
|
|
104
|
+
print_info "Using placeholder API key — set SLYOS_API_KEY in .env later"
|
|
105
|
+
else
|
|
106
|
+
print_success "API key configured"
|
|
107
|
+
fi
|
|
108
|
+
else
|
|
109
|
+
print_success "API key provided via arguments"
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
# Confirm model selection
|
|
113
|
+
print_step "AI Model Configuration"
|
|
114
|
+
echo -e " Current model: ${YELLOW}${MODEL}${NC}"
|
|
115
|
+
|
|
116
|
+
# Only prompt interactively if stdin is a terminal (not piped)
|
|
117
|
+
if [ -t 0 ]; then
|
|
118
|
+
read -p " Use this model? (y/n, default: y): " -r -n 1
|
|
119
|
+
echo
|
|
120
|
+
if [[ ! $REPLY =~ ^[Yy]?$ ]]; then
|
|
121
|
+
read -p " Enter model name: " -r MODEL
|
|
122
|
+
fi
|
|
123
|
+
fi
|
|
124
|
+
print_success "Model configured: ${YELLOW}${MODEL}${NC}"
|
|
125
|
+
|
|
126
|
+
# Check if project already exists
|
|
127
|
+
if [ -d "$PROJECT_NAME" ]; then
|
|
128
|
+
if [ -t 0 ]; then
|
|
129
|
+
print_error "Project folder '$PROJECT_NAME' already exists!"
|
|
130
|
+
read -p " Remove existing folder and continue? (y/n): " -r -n 1
|
|
131
|
+
echo
|
|
132
|
+
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
133
|
+
rm -rf "$PROJECT_NAME"
|
|
134
|
+
print_success "Existing folder removed"
|
|
135
|
+
else
|
|
136
|
+
print_error "Setup cancelled"
|
|
137
|
+
exit 1
|
|
138
|
+
fi
|
|
139
|
+
else
|
|
140
|
+
# Non-interactive: auto-remove
|
|
141
|
+
rm -rf "$PROJECT_NAME"
|
|
142
|
+
print_success "Existing folder removed"
|
|
143
|
+
fi
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
# Create project directory
|
|
147
|
+
print_step "Creating project directory: ${CYAN}$PROJECT_NAME${NC}"
|
|
148
|
+
mkdir -p "$PROJECT_NAME"
|
|
149
|
+
cd "$PROJECT_NAME"
|
|
150
|
+
print_success "Project directory created"
|
|
151
|
+
|
|
152
|
+
# Initialize npm
|
|
153
|
+
print_step "Initializing npm package"
|
|
154
|
+
npm init -y > /dev/null 2>&1
|
|
155
|
+
print_success "npm initialized"
|
|
156
|
+
|
|
157
|
+
# Update package.json to use ES modules
|
|
158
|
+
print_step "Configuring ES module support"
|
|
159
|
+
cat > package.json << 'EOF'
|
|
160
|
+
{
|
|
161
|
+
"name": "slyos-chatbot",
|
|
162
|
+
"version": "1.0.0",
|
|
163
|
+
"description": "Interactive chatbot powered by Slyos SDK",
|
|
164
|
+
"main": "app.mjs",
|
|
165
|
+
"type": "module",
|
|
166
|
+
"scripts": {
|
|
167
|
+
"start": "node app.mjs",
|
|
168
|
+
"chat": "node app.mjs"
|
|
169
|
+
},
|
|
170
|
+
"keywords": ["chatbot", "slyos", "ai"],
|
|
171
|
+
"author": "",
|
|
172
|
+
"license": "MIT"
|
|
173
|
+
}
|
|
174
|
+
EOF
|
|
175
|
+
print_success "Package configuration updated"
|
|
176
|
+
|
|
177
|
+
# Install Slyos SDK + dotenv
|
|
178
|
+
print_step "Installing dependencies"
|
|
179
|
+
print_info "This may take a moment..."
|
|
180
|
+
npm install @emilshirokikh/slyos-sdk dotenv > /dev/null 2>&1
|
|
181
|
+
print_success "Dependencies installed"
|
|
182
|
+
|
|
183
|
+
# Create the chatbot application
|
|
184
|
+
print_step "Creating interactive chatbot application: ${CYAN}app.mjs${NC}"
|
|
185
|
+
|
|
186
|
+
cat > app.mjs << 'CHATBOT_EOF'
|
|
187
|
+
#!/usr/bin/env node
|
|
188
|
+
|
|
189
|
+
import 'dotenv/config';
|
|
190
|
+
import readline from 'readline';
|
|
191
|
+
import SlyOS from '@emilshirokikh/slyos-sdk';
|
|
192
|
+
|
|
193
|
+
// Color codes for terminal output
|
|
194
|
+
const colors = {
|
|
195
|
+
reset: '\x1b[0m',
|
|
196
|
+
bright: '\x1b[1m',
|
|
197
|
+
dim: '\x1b[2m',
|
|
198
|
+
cyan: '\x1b[36m',
|
|
199
|
+
green: '\x1b[32m',
|
|
200
|
+
yellow: '\x1b[33m',
|
|
201
|
+
blue: '\x1b[34m',
|
|
202
|
+
red: '\x1b[31m',
|
|
203
|
+
magenta: '\x1b[35m'
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// Configuration
|
|
207
|
+
const config = {
|
|
208
|
+
apiKey: process.env.SLYOS_API_KEY || 'YOUR_API_KEY',
|
|
209
|
+
model: process.env.SLYOS_MODEL || 'quantum-1.7b',
|
|
210
|
+
server: process.env.SLYOS_SERVER || 'https://slyos-prod.eba-qjz3cmgq.us-east-2.elasticbeanstalk.com'
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// Initialize SlyOS SDK
|
|
214
|
+
let sdk;
|
|
215
|
+
try {
|
|
216
|
+
sdk = new SlyOS({
|
|
217
|
+
apiKey: config.apiKey,
|
|
218
|
+
onProgress: (e) => console.log(`${colors.dim}[${e.progress}%] ${e.message}${colors.reset}`)
|
|
219
|
+
});
|
|
220
|
+
} catch (error) {
|
|
221
|
+
console.error(`${colors.red}Error initializing SDK:${colors.reset}`, error.message);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Create readline interface
|
|
226
|
+
const rl = readline.createInterface({
|
|
227
|
+
input: process.stdin,
|
|
228
|
+
output: process.stdout,
|
|
229
|
+
terminal: true
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Note: conversation history is not used for generation with small models
|
|
233
|
+
// They work better with single prompts
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Print welcome banner
|
|
237
|
+
*/
|
|
238
|
+
function printWelcome() {
|
|
239
|
+
console.clear();
|
|
240
|
+
console.log(`${colors.bright}${colors.cyan}╔════════════════════════════════════════════════════════════╗${colors.reset}`);
|
|
241
|
+
console.log(`${colors.bright}${colors.cyan}║${colors.reset} ${colors.bright}${colors.cyan}║${colors.reset}`);
|
|
242
|
+
console.log(`${colors.bright}${colors.cyan}║${colors.reset} ${colors.bright}Welcome to the Slyos Interactive Chatbot${colors.reset} ${colors.bright}${colors.cyan}║${colors.reset}`);
|
|
243
|
+
console.log(`${colors.bright}${colors.cyan}║${colors.reset} ${colors.bright}${colors.cyan}║${colors.reset}`);
|
|
244
|
+
console.log(`${colors.bright}${colors.cyan}╚════════════════════════════════════════════════════════════╝${colors.reset}\n`);
|
|
245
|
+
|
|
246
|
+
console.log(`${colors.blue}Model:${colors.reset} ${colors.yellow}${config.model}${colors.reset}`);
|
|
247
|
+
console.log(`${colors.blue}Server:${colors.reset} ${colors.yellow}${config.server}${colors.reset}`);
|
|
248
|
+
if (config.apiKey === 'YOUR_API_KEY') {
|
|
249
|
+
console.log(`${colors.red}⚠ Using placeholder API key - set SLYOS_API_KEY environment variable${colors.reset}`);
|
|
250
|
+
}
|
|
251
|
+
console.log(`\n${colors.bright}Commands:${colors.reset}`);
|
|
252
|
+
console.log(` ${colors.green}Type your message and press Enter to chat${colors.reset}`);
|
|
253
|
+
console.log(` ${colors.green}Type 'clear' to clear conversation history${colors.reset}`);
|
|
254
|
+
console.log(` ${colors.green}Type 'exit' or 'quit' to end the session${colors.reset}`);
|
|
255
|
+
console.log(`\n${colors.bright}${colors.cyan}─────────────────────────────────────────────────────────────${colors.reset}\n`);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Send message to AI and get response
|
|
260
|
+
*/
|
|
261
|
+
async function sendMessage(userMessage) {
|
|
262
|
+
try {
|
|
263
|
+
console.log(`${colors.dim}Thinking...${colors.reset}`);
|
|
264
|
+
|
|
265
|
+
// Use chatCompletion (OpenAI-compatible) — handles prompt formatting for any model
|
|
266
|
+
const response = await sdk.chatCompletion(config.model, {
|
|
267
|
+
messages: [
|
|
268
|
+
{ role: 'system', content: 'You are a helpful AI assistant. Give short, direct answers.' },
|
|
269
|
+
{ role: 'user', content: userMessage }
|
|
270
|
+
],
|
|
271
|
+
max_tokens: 200,
|
|
272
|
+
temperature: 0.7
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
let assistantMessage = response?.choices?.[0]?.message?.content || '';
|
|
276
|
+
|
|
277
|
+
// Light cleanup — stop at any hallucinated role prefixes
|
|
278
|
+
assistantMessage = assistantMessage
|
|
279
|
+
.split(/\n\s*(User|Human|System):/i)[0]
|
|
280
|
+
.trim();
|
|
281
|
+
|
|
282
|
+
if (!assistantMessage) {
|
|
283
|
+
assistantMessage = '(No response generated — try rephrasing your question)';
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
console.log(`\n${colors.bright}${colors.magenta}AI:${colors.reset} ${assistantMessage}\n`);
|
|
287
|
+
} catch (error) {
|
|
288
|
+
console.error(`\n${colors.red}Error:${colors.reset} ${error.message}\n`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Prompt user for input
|
|
294
|
+
*/
|
|
295
|
+
function promptUser() {
|
|
296
|
+
rl.question(`${colors.bright}${colors.green}You:${colors.reset} `, async (input) => {
|
|
297
|
+
const message = input.trim();
|
|
298
|
+
|
|
299
|
+
if (!message) {
|
|
300
|
+
promptUser();
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Handle commands
|
|
305
|
+
if (message.toLowerCase() === 'exit' || message.toLowerCase() === 'quit') {
|
|
306
|
+
console.log(`\n${colors.bright}${colors.cyan}Thank you for chatting! Goodbye.${colors.reset}\n`);
|
|
307
|
+
rl.close();
|
|
308
|
+
process.exit(0);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (message.toLowerCase() === 'clear') {
|
|
312
|
+
console.clear();
|
|
313
|
+
printWelcome();
|
|
314
|
+
console.log(`${colors.green}✓ Screen cleared${colors.reset}\n`);
|
|
315
|
+
promptUser();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Send message to AI
|
|
320
|
+
await sendMessage(message);
|
|
321
|
+
promptUser();
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Main entry point
|
|
327
|
+
*/
|
|
328
|
+
async function main() {
|
|
329
|
+
printWelcome();
|
|
330
|
+
|
|
331
|
+
try {
|
|
332
|
+
console.log(`${colors.cyan}Initializing SlyOS...${colors.reset}`);
|
|
333
|
+
await sdk.initialize();
|
|
334
|
+
|
|
335
|
+
console.log(`${colors.cyan}Loading model: ${config.model}...${colors.reset}`);
|
|
336
|
+
await sdk.loadModel(config.model);
|
|
337
|
+
|
|
338
|
+
console.log(`${colors.green}Ready! Start chatting below.${colors.reset}\n`);
|
|
339
|
+
console.log(`${colors.bright}${colors.cyan}─────────────────────────────────────────────────────────────${colors.reset}\n`);
|
|
340
|
+
} catch (error) {
|
|
341
|
+
console.error(`${colors.red}Failed to initialize: ${error.message}${colors.reset}`);
|
|
342
|
+
console.error(`${colors.dim}Make sure your API key is correct and you have internet access.${colors.reset}`);
|
|
343
|
+
process.exit(1);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
promptUser();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Handle process termination gracefully
|
|
350
|
+
process.on('SIGINT', () => {
|
|
351
|
+
console.log(`\n${colors.bright}${colors.cyan}Session ended. Goodbye!${colors.reset}\n`);
|
|
352
|
+
rl.close();
|
|
353
|
+
process.exit(0);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
process.on('SIGTERM', () => {
|
|
357
|
+
rl.close();
|
|
358
|
+
process.exit(0);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// Start the chatbot
|
|
362
|
+
main();
|
|
363
|
+
CHATBOT_EOF
|
|
364
|
+
|
|
365
|
+
chmod +x app.mjs
|
|
366
|
+
print_success "Chatbot application created"
|
|
367
|
+
|
|
368
|
+
# Create .env.example file
|
|
369
|
+
print_step "Creating environment configuration example"
|
|
370
|
+
cat > .env.example << 'ENV_EOF'
|
|
371
|
+
# Slyos SDK Configuration
|
|
372
|
+
SLYOS_API_KEY=your_api_key_here
|
|
373
|
+
SLYOS_MODEL=quantum-1.7b
|
|
374
|
+
SLYOS_SERVER=https://slyos-prod.eba-qjz3cmgq.us-east-2.elasticbeanstalk.com
|
|
375
|
+
ENV_EOF
|
|
376
|
+
print_success "Environment configuration template created"
|
|
377
|
+
|
|
378
|
+
# Create README
|
|
379
|
+
print_step "Creating README documentation"
|
|
380
|
+
cat > README.md << 'README_EOF'
|
|
381
|
+
# Slyos Interactive Chatbot
|
|
382
|
+
|
|
383
|
+
A simple yet powerful interactive chatbot powered by the Slyos SDK.
|
|
384
|
+
|
|
385
|
+
## Features
|
|
386
|
+
|
|
387
|
+
- Interactive command-line interface with colored output
|
|
388
|
+
- Conversation history management
|
|
389
|
+
- Easy API configuration
|
|
390
|
+
- Cross-platform support (Mac, Windows, Linux)
|
|
391
|
+
|
|
392
|
+
## Installation
|
|
393
|
+
|
|
394
|
+
1. Clone or download this project
|
|
395
|
+
2. Install dependencies: `npm install`
|
|
396
|
+
3. Configure your API key (see Configuration)
|
|
397
|
+
|
|
398
|
+
## Configuration
|
|
399
|
+
|
|
400
|
+
### Environment Variables
|
|
401
|
+
|
|
402
|
+
Set these environment variables before running:
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
export SLYOS_API_KEY=your_api_key_here
|
|
406
|
+
export SLYOS_MODEL=quantum-1.7b
|
|
407
|
+
export SLYOS_SERVER=https://slyos-prod.eba-qjz3cmgq.us-east-2.elasticbeanstalk.com
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Or create a `.env` file based on `.env.example`.
|
|
411
|
+
|
|
412
|
+
## Running the Chatbot
|
|
413
|
+
|
|
414
|
+
### Direct Method
|
|
415
|
+
```bash
|
|
416
|
+
npm start
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### With Environment Variables
|
|
420
|
+
```bash
|
|
421
|
+
SLYOS_API_KEY=your_key npm start
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
### Manual
|
|
425
|
+
```bash
|
|
426
|
+
node app.mjs
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## Usage
|
|
430
|
+
|
|
431
|
+
Once the chatbot starts:
|
|
432
|
+
|
|
433
|
+
- **Chat**: Type your message and press Enter
|
|
434
|
+
- **Clear History**: Type `clear` to reset conversation
|
|
435
|
+
- **Exit**: Type `exit` or `quit` to end session
|
|
436
|
+
- **Interrupt**: Press Ctrl+C to exit anytime
|
|
437
|
+
|
|
438
|
+
## API Response Format
|
|
439
|
+
|
|
440
|
+
The chatbot supports multiple response formats from the SDK:
|
|
441
|
+
|
|
442
|
+
- `response.content` - Primary response text
|
|
443
|
+
- `response.text` - Alternative response field
|
|
444
|
+
- Direct string response - Fallback format
|
|
445
|
+
|
|
446
|
+
## Troubleshooting
|
|
447
|
+
|
|
448
|
+
### "Error initializing SDK"
|
|
449
|
+
- Check that your API key is valid
|
|
450
|
+
- Verify the Slyos server is accessible
|
|
451
|
+
- Ensure internet connection is active
|
|
452
|
+
|
|
453
|
+
### "Cannot find module '@emilshirokikh/slyos-sdk'"
|
|
454
|
+
- Run `npm install` to install dependencies
|
|
455
|
+
- Check npm log: `npm list`
|
|
456
|
+
|
|
457
|
+
### Placeholder API Key Warning
|
|
458
|
+
- Set the `SLYOS_API_KEY` environment variable with your actual key
|
|
459
|
+
- Or update `config.apiKey` in `app.mjs`
|
|
460
|
+
|
|
461
|
+
## System Requirements
|
|
462
|
+
|
|
463
|
+
- Node.js 14+ (14.17.0 or higher recommended)
|
|
464
|
+
- npm 6+
|
|
465
|
+
- Internet connection for API access
|
|
466
|
+
|
|
467
|
+
## License
|
|
468
|
+
|
|
469
|
+
MIT
|
|
470
|
+
README_EOF
|
|
471
|
+
print_success "README created"
|
|
472
|
+
|
|
473
|
+
# Set up environment with provided values
|
|
474
|
+
print_step "Configuring environment variables"
|
|
475
|
+
cat > .env << ENV_SETUP_EOF
|
|
476
|
+
SLYOS_API_KEY=${API_KEY}
|
|
477
|
+
SLYOS_MODEL=${MODEL}
|
|
478
|
+
SLYOS_SERVER=${SLYOS_SERVER}
|
|
479
|
+
ENV_SETUP_EOF
|
|
480
|
+
print_success "Environment configured"
|
|
481
|
+
|
|
482
|
+
# Final summary
|
|
483
|
+
echo ""
|
|
484
|
+
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
|
|
485
|
+
echo -e "${BLUE}║${NC} ${GREEN}✓ Setup Complete!${NC} ${BLUE}║${NC}"
|
|
486
|
+
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
|
|
487
|
+
echo ""
|
|
488
|
+
echo -e "${CYAN}Project Details:${NC}"
|
|
489
|
+
echo " Location: ${YELLOW}$(pwd)${NC}"
|
|
490
|
+
echo " API Key: ${YELLOW}${API_KEY}${NC}"
|
|
491
|
+
echo " Model: ${YELLOW}${MODEL}${NC}"
|
|
492
|
+
echo ""
|
|
493
|
+
echo -e "${CYAN}Next Steps:${NC}"
|
|
494
|
+
echo " 1. Review the .env file and update your API key if needed"
|
|
495
|
+
echo " 2. Run the chatbot: ${YELLOW}npm start${NC}"
|
|
496
|
+
echo " 3. Type messages to chat with the AI"
|
|
497
|
+
echo " 4. Type 'exit' to quit"
|
|
498
|
+
echo ""
|
|
499
|
+
echo -e "${GREEN}Ready to chat! 🚀${NC}"
|
|
500
|
+
echo ""
|
|
501
|
+
|
|
502
|
+
# Tell user how to start (can't auto-run when piped because stdin is closed)
|
|
503
|
+
echo -e "${CYAN}To start chatting, run:${NC}"
|
|
504
|
+
echo ""
|
|
505
|
+
echo -e " ${YELLOW}cd ${PROJECT_NAME} && npm start${NC}"
|
|
506
|
+
echo ""
|
package/dist/index.js
CHANGED
|
@@ -413,7 +413,12 @@ class SlyOS {
|
|
|
413
413
|
top_p: options.topP || 0.9,
|
|
414
414
|
do_sample: true,
|
|
415
415
|
});
|
|
416
|
-
const
|
|
416
|
+
const rawOutput = result[0].generated_text;
|
|
417
|
+
// HuggingFace transformers returns the prompt + generated text concatenated.
|
|
418
|
+
// Strip the original prompt so we only return the NEW tokens.
|
|
419
|
+
const response = rawOutput.startsWith(prompt)
|
|
420
|
+
? rawOutput.slice(prompt.length).trim()
|
|
421
|
+
: rawOutput.trim();
|
|
417
422
|
const latency = Date.now() - startTime;
|
|
418
423
|
const tokensGenerated = response.split(/\s+/).length;
|
|
419
424
|
const tokensPerSec = (tokensGenerated / (latency / 1000)).toFixed(1);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -615,7 +615,12 @@ class SlyOS {
|
|
|
615
615
|
do_sample: true,
|
|
616
616
|
});
|
|
617
617
|
|
|
618
|
-
const
|
|
618
|
+
const rawOutput = result[0].generated_text;
|
|
619
|
+
// HuggingFace transformers returns the prompt + generated text concatenated.
|
|
620
|
+
// Strip the original prompt so we only return the NEW tokens.
|
|
621
|
+
const response = rawOutput.startsWith(prompt)
|
|
622
|
+
? rawOutput.slice(prompt.length).trim()
|
|
623
|
+
: rawOutput.trim();
|
|
619
624
|
const latency = Date.now() - startTime;
|
|
620
625
|
const tokensGenerated = response.split(/\s+/).length;
|
|
621
626
|
const tokensPerSec = (tokensGenerated / (latency / 1000)).toFixed(1);
|