-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo-in-cmd-nostream.ts
49 lines (46 loc) · 1.19 KB
/
demo-in-cmd-nostream.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
import { getReadLine } from '../src/utils'
import {
ChatGPT,
IChatCompletionStreamOnEndData,
IChatGPTResponse,
} from '../src'
import apiKey from './.key'
const api = new ChatGPT({
apiKey,
debug: true,
requestConfig: {
proxy: {
protocol: 'http',
host: '127.0.0.1',
port: 7890,
},
},
})
void (async function () {
let prevRes = (await basicRunner('你好')) as IChatCompletionStreamOnEndData
console.log('---------------------ChatGPT says------------------------')
console.log(prevRes.data)
let line = ''
const readline = getReadLine()
console.log('---------------------your question------------------')
while ((line = await readline())) {
prevRes = (await basicRunner(
line,
prevRes ? (prevRes.data as IChatGPTResponse).id : undefined,
)) as IChatCompletionStreamOnEndData
console.log('---------------------ChatGPT says------------------------')
console.log(prevRes.data)
console.log('---------------------your question------------------')
}
})()
async function basicRunner(
text: string,
parentMessageId?: string,
sys?: string,
) {
return await api.sendMessage({
text,
parentMessageId,
systemPrompt: sys,
})
}