-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (26 loc) · 763 Bytes
/
index.js
File metadata and controls
30 lines (26 loc) · 763 Bytes
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
import { Configuration, OpenAIApi } from "openai";
import readline from "readline";
const configuration = new Configuration({
organization: "org-0nmrFWw6wSm6xIJXSbx4FpTw",
apiKey: "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",
});
const openai = new OpenAIApi(configuration);
const userInterface = readline.createInterface({
input: process.stdin,
output: process.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);
});
});