-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.js
More file actions
65 lines (55 loc) · 1.72 KB
/
Copy pathquickstart.js
File metadata and controls
65 lines (55 loc) · 1.72 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
/**
* YingSuan AI - Quick Start Example (Node.js)
*
* This example shows how to use YingSuan's OpenAI-compatible API
* with the OpenAI Node.js SDK.
*
* Step 1: Get your API key by emailing yingsuan_service@163.com
* Step 2: Install: npm install openai
* Step 3: Run: node quickstart.js
*/
import OpenAI from 'openai';
// Replace with your YingSuan API key
const API_KEY = 'sk-your-yingsuan-key-here';
const client = new OpenAI({
apiKey: API_KEY,
baseURL: 'https://yingsuan.top/v1',
});
async function chatCompletion(message, model = 'deepseek-chat') {
const response = await client.chat.completions.create({
model,
messages: [
{ role: 'system', content: 'You are a helpful AI assistant.' },
{ role: 'user', content: message },
],
temperature: 0.7,
max_tokens: 1024,
});
return response.choices[0].message.content;
}
async function listModels() {
const models = await client.models.list();
for (const model of models.data) {
console.log(` ${model.id}`);
}
}
async function main() {
console.log('='.repeat(50));
console.log('YingSuan AI - Quick Start Demo (Node.js)');
console.log('='.repeat(50));
console.log('\nAvailable models:');
await listModels();
console.log('\nSending chat request...');
const reply = await chatCompletion(
'Tell me about GPU computing in Southeast Asia in 3 sentences.'
);
console.log(`\nResponse:\n${reply}`);
console.log('\n' + '='.repeat(50));
console.log('Using DeepSeek Reasoner:');
const reasoningReply = await chatCompletion(
'What is the optimal batch size for a GPU with 24GB VRAM running a 7B parameter model?',
'deepseek-reasoner'
);
console.log(`\nResponse:\n${reasoningReply}`);
}
main().catch(console.error);