-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (34 loc) · 875 Bytes
/
script.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
import { config } from "dotenv";
config();
import { Configuration, OpenAIApi } from "openai";
import readline from "readline";
const openai = new OpenAIApi(
new Configuration({
apiKey: process.env.API_KEY,
})
);
const userInterface = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
userInterface.prompt()
userInterface.on("line", async input => {
const res = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{
role: "user",
content: input
}]
})
console.log(res.data.choices[0].message.content)
})
userInterface.prompt()
// openai.createChatCompletion({
// model: "gpt-3.5-turbo",
// messages: [{
// role: "user",
// content: "Hiii"
// }]
// }).then(res=> {
// console.log(res.data.choices[0].message.content)
// })