-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo-with-stream.ts
50 lines (46 loc) · 1.01 KB
/
demo-with-stream.ts
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
import { ChatGPT } from '../src'
const api = new ChatGPT({
apiKey: process.env.OPENAI_API_KEY as string, // get api key
})
async function run() {
const res = await api.sendMessage({
text: 'calc 1 + 2',
model: 'gpt-3.5-turbo',
onProgress(t, raw) {
console.log('[onProgress]', t, raw)
},
onEnd(t) {
console.log('[onEnd]', t)
},
})
console.log('res', res)
}
run()
// [onProgress] 3
// [onProgress]
// [onEnd] {
// success: true,
// data: {
// id: '14cb9244-a1bf-4152-8aba-1ee768fcc210',
// text: '3',
// created: 1681634268,
// role: 'assistant',
// parentMessageId: 'ae4f6881-0c54-4484-862c-2d31d8d394e3',
// tokens: 40,
// len: 127
// },
// status: 200
// }
// res {
// success: true,
// data: {
// id: '14cb9244-a1bf-4152-8aba-1ee768fcc210',
// text: '3',
// created: 1681634268,
// role: 'assistant',
// parentMessageId: 'ae4f6881-0c54-4484-862c-2d31d8d394e3',
// tokens: 40,
// len: 127
// },
// status: 200
// }