-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
35 lines (28 loc) · 855 Bytes
/
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
const {Client} = require("whatsapp-web.js");
const qrcode = require("qrcode-terminal");
const {Configuration, OpenAIApi} = require("openai");
require("dotenv").config();
const client = new Client();
client.on('qr',(qr) =>{
qrcode.generate(qr,{small:true});
});
client.on('ready',() =>{
console.log("Client is ready");
});
client.initialize();
const configuration = new Configuration({
apiKey : process.env.SECRET_KEY,
});
const openai = new OpenAIApi(configuration);
async function runCompletion(message){
const completion = await openai.createCompletion({
model:"text-davinci-003",
prompt: message,
max_tokens: 200,
});
return completion.data.choices[0].text;
}
client.on('message',message => {
console.log(message.body);
runCompletion(message.body).then(result => message.reply(result));
})