-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (89 loc) · 3.56 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const nodemailer = require("nodemailer");
const {
GoogleGenerativeAI,
HarmCategory,
HarmBlockThreshold,
} = require("@google/generative-ai");
const transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false, // Use `true` for port 465, `false` for all other ports
auth: {
user: "[email protected]",
pass: "MqrGrvMssBtVBUB3kS",
},
});
let text;
async function AI() {
const MODEL_NAME = "gemini-1.0-pro";
const genAI = new GoogleGenerativeAI('AIzaSyCy_B8Uv9oJ47qpqbi1WtSQcYufbUrzbf4'); // Replace 'your_api_key_here' with your actual API key
const model = genAI.getGenerativeModel({ model: MODEL_NAME });
const generationConfig = {
temperature: 0.9,
topK: 1,
topP: 1,
maxOutputTokens: 500,
};
const safetySettings = [
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH,
},
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH,
},
{
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH,
},
{
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH,
},
];
const conversationHistory = [
{
role: "user",
parts: [{ text: "Pretend you're email and you have to write emails "}],
},
{
role: "model",
parts: [{ text: "```html\n\n\n\n \n \n\n\n Subject: Your Order Confirmation\n\n Hi [Customer Name],\n\n Thank you for your recent order from [Company Name]. We're excited to get your order shipped to you as soon as possible.\n\n Order Details\n\n \n Order Number: [Order Number]\n Order Date: [Order Date]\n Shipping Address: [Shipping Address]\n Billing Address: [Billing Address]\n Items Ordered:\n \n [Item Name] x [Quantity]\n [Item Name] x [Quantity]\n [Item Name] x [Quantity]\n \n \n\n The total amount of your order is [Total Amount].\n\n We expect your order to arrive within [Shipping Time Frame]. You can track your order status at [Tracking URL].\n\n If you have any questions about your order, please don't hesitate to contact us.\n\n Thank you for your business!\n\n Sincerely,\n [Company Name]\n\n\n```"}],
},
];
const chat = model.startChat({
generationConfig,
safetySettings,
history: conversationHistory,
});
const msg = "write me a CV letter to apply for a job";
const result = await chat.sendMessage(msg);
const response = await result.response;
const text = response.text()
console.log("iiiiii",text);
console.log("iiiiii",response);
console.log("iiiiii",response.text());
return text;
// messages = JSON.parse(text);
// if (messages.messages) {
// messages = messages.messages; // ChatGPT is not 100% reliable, sometimes it directly returns an array and sometimes a JSON object with a messages property
// }
// console.log("uuuu",messages);
}
// const htmlTemplate = `<h1>Hello world?</h1>`
async function main() {
const text = await AI();
// send mail with defined transport object
const info = await transporter.sendMail({
from: '[email protected]', // sender address
to: "[email protected]", // list of receivers
subject: "Hello ✔", // Subject line
// text: "Hello world?", // plain text body
html: text, // html body
});
console.log("Message sent: %s", info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// Message sent: <[email protected]>
}
main().catch(console.error);