-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcli.mjs
More file actions
executable file
·46 lines (37 loc) · 1.07 KB
/
cli.mjs
File metadata and controls
executable file
·46 lines (37 loc) · 1.07 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
#!/usr/bin/env node
import Anthropic from '@anthropic-ai/sdk';
import readline from 'readline';
const anthropic = new Anthropic({
apiKey: 'local-proxy',
baseURL: 'http://localhost:3333'
});
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function chat() {
console.log('\n🤖 Puter AI Proxy CLI (type "quit" to exit)\n');
const ask = () => {
rl.question('You: ', async (question) => {
if (question.toLowerCase() === 'quit' || question.toLowerCase() === 'exit') {
console.log('\nGoodbye! 👋\n');
rl.close();
return;
}
try {
const msg = await anthropic.messages.create({
model: 'deepseek-chat',
max_tokens: 2048,
messages: [{ role: 'user', content: question }]
});
const response = msg.content[0]?.text || 'No response';
console.log(`\nAssistant: ${response}\n`);
} catch (error) {
console.error(`\nError: ${error.message}\n`);
}
ask();
});
};
ask();
}
chat();