@beltoinc/slyos-sdk 1.5.2 → 1.5.4

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.
@@ -1,195 +1,3 @@
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
- KB_ID=""
31
- SLYOS_SERVER="https://api.slyos.world"
32
- PROJECT_NAME="slyos-chatbot"
33
-
34
- #################################################################################
35
- # Helper Functions
36
- #################################################################################
37
-
38
- print_header() {
39
- echo -e "\n${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
40
- echo -e "${BLUE}║${NC} ${CYAN}Slyos Interactive Chatbot Setup${NC} ${BLUE}║${NC}"
41
- echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}\n"
42
- }
43
-
44
- print_step() {
45
- echo -e "${CYAN}▶${NC} $1"
46
- }
47
-
48
- print_success() {
49
- echo -e "${GREEN}✓${NC} $1"
50
- }
51
-
52
- print_error() {
53
- echo -e "${RED}✗${NC} $1" >&2
54
- }
55
-
56
- print_info() {
57
- echo -e "${YELLOW}ℹ${NC} $1"
58
- }
59
-
60
- #################################################################################
61
- # Argument Parsing
62
- #################################################################################
63
-
64
- while [[ $# -gt 0 ]]; do
65
- case $1 in
66
- --api-key)
67
- API_KEY="$2"
68
- shift 2
69
- ;;
70
- --model)
71
- MODEL="$2"
72
- shift 2
73
- ;;
74
- --kb-id)
75
- KB_ID="$2"
76
- shift 2
77
- ;;
78
- -h|--help)
79
- echo "Usage: $0 [OPTIONS]"
80
- echo ""
81
- echo "Options:"
82
- echo " --api-key KEY Slyos API key (prompted if not provided)"
83
- echo " --model MODEL AI model to use (default: quantum-1.7b)"
84
- echo " --kb-id ID Knowledge base ID for RAG (optional)"
85
- echo " -h, --help Show this help message"
86
- exit 0
87
- ;;
88
- *)
89
- print_error "Unknown option: $1"
90
- exit 1
91
- ;;
92
- esac
93
- done
94
-
95
- #################################################################################
96
- # Main Setup
97
- #################################################################################
98
-
99
- print_header
100
-
101
- # Prompt for API key if not provided
102
- if [ -z "$API_KEY" ]; then
103
- if [ -t 0 ]; then
104
- print_step "Enter your Slyos API key (or press Enter for placeholder)"
105
- read -r -p " API Key: " API_KEY
106
- fi
107
-
108
- if [ -z "$API_KEY" ]; then
109
- API_KEY="YOUR_API_KEY"
110
- print_info "Using placeholder API key — set SLYOS_API_KEY in .env later"
111
- else
112
- print_success "API key configured"
113
- fi
114
- else
115
- print_success "API key provided via arguments"
116
- fi
117
-
118
- # Confirm model selection
119
- print_step "AI Model Configuration"
120
- echo -e " Current model: ${YELLOW}${MODEL}${NC}"
121
-
122
- # Only prompt interactively if stdin is a terminal (not piped)
123
- if [ -t 0 ]; then
124
- read -p " Use this model? (y/n, default: y): " -r -n 1
125
- echo
126
- if [[ ! $REPLY =~ ^[Yy]?$ ]]; then
127
- read -p " Enter model name: " -r MODEL
128
- fi
129
- fi
130
- print_success "Model configured: ${YELLOW}${MODEL}${NC}"
131
-
132
- # Check if project already exists
133
- if [ -d "$PROJECT_NAME" ]; then
134
- if [ -t 0 ]; then
135
- print_error "Project folder '$PROJECT_NAME' already exists!"
136
- read -p " Remove existing folder and continue? (y/n): " -r -n 1
137
- echo
138
- if [[ $REPLY =~ ^[Yy]$ ]]; then
139
- rm -rf "$PROJECT_NAME"
140
- print_success "Existing folder removed"
141
- else
142
- print_error "Setup cancelled"
143
- exit 1
144
- fi
145
- else
146
- # Non-interactive: auto-remove
147
- rm -rf "$PROJECT_NAME"
148
- print_success "Existing folder removed"
149
- fi
150
- fi
151
-
152
- # Create project directory
153
- print_step "Creating project directory: ${CYAN}$PROJECT_NAME${NC}"
154
- mkdir -p "$PROJECT_NAME"
155
- cd "$PROJECT_NAME"
156
- print_success "Project directory created"
157
-
158
- # Initialize npm
159
- print_step "Initializing npm package"
160
- npm init -y > /dev/null 2>&1
161
- print_success "npm initialized"
162
-
163
- # Update package.json to use ES modules
164
- print_step "Configuring ES module support"
165
- cat > package.json << 'EOF'
166
- {
167
- "name": "slyos-chatbot",
168
- "version": "1.0.0",
169
- "description": "Interactive chatbot powered by Slyos SDK",
170
- "main": "app.mjs",
171
- "type": "module",
172
- "scripts": {
173
- "start": "node app.mjs",
174
- "chat": "node app.mjs"
175
- },
176
- "keywords": ["chatbot", "slyos", "ai"],
177
- "author": "",
178
- "license": "MIT"
179
- }
180
- EOF
181
- print_success "Package configuration updated"
182
-
183
- # Install Slyos SDK + dotenv
184
- print_step "Installing dependencies"
185
- print_info "This may take a moment..."
186
- npm install @beltoinc/slyos-sdk dotenv node-fetch > /dev/null 2>&1
187
- print_success "Dependencies installed"
188
-
189
- # Create the chatbot application
190
- print_step "Creating interactive chatbot application: ${CYAN}app.mjs${NC}"
191
-
192
- cat > app.mjs << 'CHATBOT_EOF'
193
1
  #!/usr/bin/env node
194
2
 
195
3
  import 'dotenv/config';
@@ -560,151 +368,3 @@ process.on('SIGTERM', () => {
560
368
 
561
369
  // Start the chatbot
562
370
  main();
563
- CHATBOT_EOF
564
-
565
- chmod +x app.mjs
566
- print_success "Chatbot application created"
567
-
568
- # Create .env.example file
569
- print_step "Creating environment configuration example"
570
- cat > .env.example << 'ENV_EOF'
571
- # Slyos SDK Configuration
572
- SLYOS_API_KEY=your_api_key_here
573
- SLYOS_MODEL=quantum-1.7b
574
- SLYOS_SERVER=https://api.slyos.world
575
- ENV_EOF
576
- print_success "Environment configuration template created"
577
-
578
- # Create README
579
- print_step "Creating README documentation"
580
- cat > README.md << 'README_EOF'
581
- # Slyos Interactive Chatbot
582
-
583
- A simple yet powerful interactive chatbot powered by the Slyos SDK.
584
-
585
- ## Features
586
-
587
- - Interactive command-line interface with colored output
588
- - Conversation history management
589
- - Easy API configuration
590
- - Cross-platform support (Mac, Windows, Linux)
591
-
592
- ## Installation
593
-
594
- 1. Clone or download this project
595
- 2. Install dependencies: `npm install`
596
- 3. Configure your API key (see Configuration)
597
-
598
- ## Configuration
599
-
600
- ### Environment Variables
601
-
602
- Set these environment variables before running:
603
-
604
- ```bash
605
- export SLYOS_API_KEY=your_api_key_here
606
- export SLYOS_MODEL=quantum-1.7b
607
- export SLYOS_SERVER=https://api.slyos.world
608
- ```
609
-
610
- Or create a `.env` file based on `.env.example`.
611
-
612
- ## Running the Chatbot
613
-
614
- ### Direct Method
615
- ```bash
616
- npm start
617
- ```
618
-
619
- ### With Environment Variables
620
- ```bash
621
- SLYOS_API_KEY=your_key npm start
622
- ```
623
-
624
- ### Manual
625
- ```bash
626
- node app.mjs
627
- ```
628
-
629
- ## Usage
630
-
631
- Once the chatbot starts:
632
-
633
- - **Chat**: Type your message and press Enter
634
- - **Clear History**: Type `clear` to reset conversation
635
- - **Exit**: Type `exit` or `quit` to end session
636
- - **Interrupt**: Press Ctrl+C to exit anytime
637
-
638
- ## API Response Format
639
-
640
- The chatbot supports multiple response formats from the SDK:
641
-
642
- - `response.content` - Primary response text
643
- - `response.text` - Alternative response field
644
- - Direct string response - Fallback format
645
-
646
- ## Troubleshooting
647
-
648
- ### "Error initializing SDK"
649
- - Check that your API key is valid
650
- - Verify the Slyos server is accessible
651
- - Ensure internet connection is active
652
-
653
- ### "Cannot find module '@beltoinc/slyos-sdk'"
654
- - Run `npm install` to install dependencies
655
- - Check npm log: `npm list`
656
-
657
- ### Placeholder API Key Warning
658
- - Set the `SLYOS_API_KEY` environment variable with your actual key
659
- - Or update `config.apiKey` in `app.mjs`
660
-
661
- ## System Requirements
662
-
663
- - Node.js 14+ (14.17.0 or higher recommended)
664
- - npm 6+
665
- - Internet connection for API access
666
-
667
- ## License
668
-
669
- MIT
670
- README_EOF
671
- print_success "README created"
672
-
673
- # Set up environment with provided values
674
- print_step "Configuring environment variables"
675
- cat > .env << ENV_SETUP_EOF
676
- SLYOS_API_KEY=${API_KEY}
677
- SLYOS_MODEL=${MODEL}
678
- SLYOS_SERVER=${SLYOS_SERVER}
679
- SLYOS_KB_ID=${KB_ID}
680
- ENV_SETUP_EOF
681
- print_success "Environment configured"
682
-
683
- # Final summary
684
- echo ""
685
- echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
686
- echo -e "${BLUE}║${NC} ${GREEN}✓ Setup Complete!${NC} ${BLUE}║${NC}"
687
- echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
688
- echo ""
689
- echo -e "${CYAN}Project Details:${NC}"
690
- echo " Location: ${YELLOW}$(pwd)${NC}"
691
- echo " API Key: ${YELLOW}${API_KEY}${NC}"
692
- echo " Model: ${YELLOW}${MODEL}${NC}"
693
- if [ -n "$KB_ID" ]; then
694
- echo " Knowledge Base: ${GREEN}${KB_ID} (RAG enabled)${NC}"
695
- fi
696
- echo ""
697
- echo -e "${CYAN}Next Steps:${NC}"
698
- echo " 1. Review the .env file and update your API key if needed"
699
- echo " 2. Run the chatbot: ${YELLOW}npm start${NC}"
700
- echo " 3. Type messages to chat with the AI"
701
- echo " 4. Type 'exit' to quit"
702
- echo ""
703
- echo -e "${GREEN}Ready to chat! 🚀${NC}"
704
- echo ""
705
-
706
- # Tell user how to start (can't auto-run when piped because stdin is closed)
707
- echo -e "${CYAN}To start chatting, run:${NC}"
708
- echo ""
709
- echo -e " ${YELLOW}cd ${PROJECT_NAME} && npm start${NC}"
710
- echo ""