-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (38 loc) · 1.09 KB
/
test.js
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
import fetch from 'node-fetch'
import 'dotenv/config'
import readline from 'readline'
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });
const api = process.env.API_CHATGPT
const temperature = 1
const openai = async (prompt) => {
const body = {
model: "text-davinci-003",
prompt: prompt,
temperature: temperature,
max_tokens: 256,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
}
const getapi = await fetch(api, {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
}).then(response => response.json())
.then(response => {
const gettext = response.choices[0].text
const textsplit = gettext.split(/\d+\.\s+/).filter(Boolean);
return textsplit
})
return getapi
}
export default openai
// rl.question('Masukan prompt chatgpt :', (prompt) => {
// openai(prompt)
// rl.close()
// })