-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (37 loc) · 1.01 KB
/
index.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
import { Configuration, OpenAIApi } from "openai";
import { stdout } from "process";
import readline from "readline";
const configuration = new Configuration({
organization: "org-VsVNHgGPjwKKkTmLlJJFcXoq",
apiKey: "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",
});
const openai = new OpenAIApi(configuration);
/*openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: "Hello"}],
})
.then((res) => {
console.log(res.data.choices[0].message.content);
})
.catch((e) =>{
console.log(e);
});
*/
const userInterface = readline.createInterface({
input: process.stdin,
output: stdout,
});
userInterface.prompt();
userInterface.on("line", async (input) =>{
await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: input}],
})
.then((res) =>{
console.log(res.data.choices[0].message.content);
userInterface.prompt();
})
.catch((e) => {
console.log(e);
});
});