-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurai_solo.js
36 lines (27 loc) · 837 Bytes
/
urai_solo.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
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
let prompt = process.argv.slice(2).join(" ");
prompt = prompt ? prompt : "hello world";
function typewriter(text, delay = 50) {
text = text + "\n"
for (let i = 0; i < text.length; i++) {
setTimeout(() => {
process.stdout.write(text[i]);
}, delay * i);
}
}
//typewriter("hello")
//console.log(prompt);
const openai = new OpenAIApi(configuration);
async function talkToGpt() {
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: prompt}]
});
return completion.data.choices[0].message.content.replace("\n\n","")
}
talkToGpt().then((data) =>
typewriter(data)
)