-
Notifications
You must be signed in to change notification settings - Fork 0
/
openaiEmail.js
46 lines (38 loc) · 1.28 KB
/
openaiEmail.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
43
44
45
var nodemailer = require('nodemailer');
require('dotenv').config();
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
organization: process.env.OPEN_AI_ORG,
apiKey: process.env.OPEN_AI_KEY,
});
const openai = new OpenAIApi(configuration);
let response;
async function makeRequest() {
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: "Tell he needs to get cycle counts done and outdates are due at the end of the month"}],
});
response = completion.data.choices[0].message.content
// console.log("response", completion.data.choices[0].message.content)
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS
}
});
var mailOptions = {
from: process.env.EMAIL_USER,
to: process.env.RECIPIENT,
subject: 'Sending Email using ChatGPT',
text: response
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
makeRequest();