-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.js
More file actions
278 lines (229 loc) · 7.67 KB
/
setup.js
File metadata and controls
278 lines (229 loc) · 7.67 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env node
/**
* SVECTOR SDK Setup and Quick Start Guide
* This script helps users get started with the SVECTOR SDK
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
console.log('SVECTOR SDK Quick Start Guide\n');
function runCommand(command, description) {
console.log(`📋 ${description}`);
try {
execSync(command, { stdio: 'pipe' });
console.log('Success\n');
} catch (error) {
console.log(`Failed: ${error.message}\n`);
}
}
function checkEnvironment() {
console.log('🔍 Checking environment...');
// Check Node.js version
const nodeVersion = process.version;
console.log(` Node.js version: ${nodeVersion}`);
if (parseInt(nodeVersion.slice(1)) < 18) {
console.log('⚠️ Warning: Node.js 18+ is recommended');
} else {
console.log('Node.js version is compatible');
}
// Check if TypeScript is available
try {
execSync('npx tsc --version', { stdio: 'pipe' });
console.log('TypeScript is available');
} catch {
console.log('ℹ️ TypeScript not found globally (this is OK)');
}
console.log('');
}
function createExampleProject() {
console.log(' Creating example project...');
const projectDir = 'svector-example';
const exampleCode = `
import { SVECTOR } from 'svector';
async function main() {
const client = new SVECTOR({
apiKey: process.env.SVECTOR_API_KEY,
});
try {
// List available models
const models = await client.models.list();
console.log('Available models:', models.models);
// Basic chat completion
const response = await client.chat.create({
model: 'spec-3-turbo',
messages: [
{ role: 'user', content: 'Hello! How can SVECTOR help developers?' }
],
max_tokens: 150,
});
console.log('Response:', response.choices[0].message.content);
} catch (error) {
console.error('Error:', error.message);
}
}
main();
`;
const packageJson = {
name: 'svector-example',
version: '1.0.0',
description: 'Example project using SVECTOR SDK',
main: 'index.js',
type: 'module',
scripts: {
start: 'node index.js',
'start:ts': 'npx tsx index.ts'
},
dependencies: {
svector: '^1.0.0'
},
devDependencies: {
'tsx': '^4.0.0',
'typescript': '^5.0.0'
}
};
try {
if (!fs.existsSync(projectDir)) {
fs.mkdirSync(projectDir);
}
fs.writeFileSync(
path.join(projectDir, 'index.ts'),
exampleCode.trim()
);
fs.writeFileSync(
path.join(projectDir, 'package.json'),
JSON.stringify(packageJson, null, 2)
);
fs.writeFileSync(
path.join(projectDir, '.env.example'),
'SVECTOR_API_KEY=your-api-key-here\n'
);
console.log(`Example project created in ${projectDir}/`);
console.log('');
} catch (error) {
console.log(`Failed to create example project: ${error.message}\n`);
}
}
function showQuickStart() {
console.log('Quick Start Guide');
console.log('─'.repeat(50));
console.log('');
console.log('1️⃣ Install SVECTOR SDK:');
console.log(' npm install svector');
console.log('');
console.log('2️⃣ Get your API key:');
console.log(' Visit: https://platform.svector.co.in');
console.log(' Generate an API key from your dashboard');
console.log('');
console.log('3️⃣ Set environment variable:');
console.log(' export SVECTOR_API_KEY="your-api-key-here"');
console.log('');
console.log('4️⃣ Basic usage:');
console.log(`
import { SVECTOR } from 'svector';
const client = new SVECTOR();
const response = await client.chat.create({
model: 'spec-3-turbo',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);
`);
}
function showAvailableExamples() {
console.log(' Available Examples');
console.log('─'.repeat(50));
console.log('');
const examples = [
'basic-chat.ts - Simple chat completion',
'streaming-chat.ts - Real-time streaming responses',
'file-upload-rag.ts - File upload and RAG usage',
'advanced-rag.ts - Advanced RAG with multiple files',
'nodejs-example.ts - Node.js integration patterns',
'browser-example.ts - Browser usage examples',
'comprehensive-demo.ts - Complete feature showcase'
];
examples.forEach((example, index) => {
console.log(` ${index + 1}. ${example}`);
});
console.log('');
console.log('💡 Find all examples at: https://github.com/SVECTOR-CORPORATION/svector-node/tree/main/examples');
}
function showDocumentation() {
console.log('📖 Documentation');
console.log('─'.repeat(50));
console.log('');
console.log('📋 API Reference: https://platform.svector.co.in');
console.log(' Website: https://www.svector.co.in');
console.log('Support: support@svector.co.in');
console.log(' Issues: https://github.com/SVECTOR-CORPORATION/svector-node/issues');
console.log('');
}
function showTroubleshooting() {
console.log('🛠️ Troubleshooting');
console.log('─'.repeat(50));
console.log('');
console.log('❓ Common Issues:');
console.log('');
console.log('🔑 Authentication Error:');
console.log(' • Check your API key is correct');
console.log(' • Ensure SVECTOR_API_KEY environment variable is set');
console.log(' • Verify your API key has necessary permissions');
console.log('');
console.log(' Vision API Server Configuration Issue:');
console.log(' • Error: "All endpoints route to SVECTOR Server"');
console.log(' • This indicates server-side routing problems');
console.log(' • Try using alternative endpoints or contact support');
console.log(' • Workaround: Use regular chat API with vision messages');
console.log(' • Example: client.chat.create() with image_url content');
console.log('');
console.log('📦 Module Type Warning (Node.js):');
console.log(' • Add "type": "module" to your package.json');
console.log(' • Or rename files from .js to .mjs');
console.log(' • Or use CommonJS syntax with require()');
console.log('');
console.log(' Network Errors:');
console.log(' • Check internet connectivity');
console.log(' • Verify firewall/proxy settings');
console.log(' • Try increasing timeout: { timeout: 60000 }');
console.log('');
console.log('📱 Browser Issues:');
console.log(' • Set dangerouslyAllowBrowser: true');
console.log(' • Use environment variables for API keys in development only');
console.log(' • Consider using a backend proxy for production');
console.log('');
console.log('Rate Limiting:');
console.log(' • Built-in retry logic handles most cases');
console.log(' • Implement exponential backoff for high-volume usage');
console.log(' • Monitor your usage limits in the dashboard');
console.log('');
}
// Main execution
async function main() {
checkEnvironment();
showQuickStart();
showAvailableExamples();
showDocumentation();
showTroubleshooting();
// Optionally create example project
console.log(' Want to create an example project? (y/n)');
// In a real CLI tool, you'd use readline here
// For this example, we'll just show the option
console.log(' Run: node setup.js --create-example');
console.log('');
console.log('✨ You\'re ready to start building with SVECTOR!');
console.log('');
console.log('Happy coding! 🚀');
}
// Handle command line arguments
if (process.argv.includes('--create-example')) {
createExampleProject();
} else {
main();
}
module.exports = {
checkEnvironment,
createExampleProject,
showQuickStart,
showAvailableExamples,
showDocumentation,
showTroubleshooting
};