forked from Y-AIFE/ChatGPT-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.ts
39 lines (36 loc) · 926 Bytes
/
demo.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
import { ChatGPT } from '../src'
const api = new ChatGPT({
apiKey: process.env.OPENAI_API_KEY as string, // get api key
debug: true,
requestConfig: {
timeout: 600000,
},
})
async function run() {
const res = await api.sendMessage({
text: '你好呀',
})
console.log('res', res)
}
run()
// res {
// success: true,
// data: {
// id: '0291c0ab-37a3-40c9-9c6b-353516909bd4',
// text: '你好!有什么我可以帮助你的吗?',
// created: 1689435751,
// role: 'assistant',
// parentMessageId: '2bdd469f-7119-4f14-b195-5393f595a075',
// tokens: 66,
// len: 134
// },
// raw: {
// id: 'chatcmpl-7cbhf67RofiO7AmYyPD41iisahF26',
// object: 'chat.completion',
// created: 1689435751,
// model: 'gpt-3.5-turbo-0613',
// choices: [ [Object] ],
// usage: { prompt_tokens: 48, completion_tokens: 18, total_tokens: 66 }
// },
// status: 200
// }