-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathindex.js
46 lines (38 loc) · 1.29 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
// By VishwaGauravIn (https://itsvg.in)
const GenAI = require("@google/generative-ai");
const { TwitterApi } = require("twitter-api-v2");
const SECRETS = require("./SECRETS");
const twitterClient = new TwitterApi({
appKey: SECRETS.APP_KEY,
appSecret: SECRETS.APP_SECRET,
accessToken: SECRETS.ACCESS_TOKEN,
accessSecret: SECRETS.ACCESS_SECRET,
});
const generationConfig = {
maxOutputTokens: 400,
};
const genAI = new GenAI.GoogleGenerativeAI(SECRETS.GEMINI_API_KEY);
async function run() {
// For text-only input, use the gemini-pro model
const model = genAI.getGenerativeModel({
model: "gemini-pro",
generationConfig,
});
// Write your prompt here
const prompt =
"generate a web development content, tips and tricks or something new or some rant or some advice as a tweet, it should not be vague and should be unique; under 280 characters and should be plain text, you can use emojis";
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
console.log(text);
sendTweet(text);
}
run();
async function sendTweet(tweetText) {
try {
await twitterClient.v2.tweet(tweetText);
console.log("Tweet sent successfully!");
} catch (error) {
console.error("Error sending tweet:", error);
}
}