-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathexample.js
More file actions
33 lines (26 loc) 路 914 Bytes
/
Copy pathexample.js
File metadata and controls
33 lines (26 loc) 路 914 Bytes
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
import { config } from "dotenv";
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
config({ path: join(__dirname, '.env') });
import { init } from "@heyputer/puter.js/src/init.cjs";
const puter = init(process.env.PUTER_AUTH_TOKEN);
async function chatExample() {
const response = await puter.ai.chat([{role:'user', content:'Hello, how are you?'}], {
model: "deepseek-chat",
stream: false
});
console.log(JSON.stringify(response, null, 2).substring(0, 500));
}
async function streamExample() {
const stream = await puter.ai.chat([{role:'user', content:'Tell me a story'}], {
model: "deepseek-chat",
stream: true
});
for await (const part of stream) {
process.stdout.write(part?.message?.content || part?.text || "");
}
console.log("\n");
}
chatExample();