-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
32 lines (23 loc) · 1018 Bytes
/
main.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
const Groq = require("groq-sdk");
const TelegramBot = require('node-telegram-bot-api');
// Replace with your Telegram bot token and Groq API key
const TELEGRAM_TOKEN = 'YOUR_TELEGRAM_TOKEN';
const GROQ_API_KEY = 'YOUR_GROP_API_KEY';
const bot = new TelegramBot(TELEGRAM_TOKEN, { polling: true });
const groq = new Groq({ apiKey: GROQ_API_KEY });
console.log("Bot running..")
console.log("------------------------------------")
async function handleRequest(msg) {
const completion = await groq.chat.completions.create({
messages: [{ role: "user", content: msg.text }],
model: "mixtral-8x7b-32768"
}).then((chatCompletion) => {
return chatCompletion.choices[0]?.message?.content || "I'm still learning how to answer that!";
});
console.log("------------------------------------")
console.log(" # User: " + msg.text)
console.log(" # AI: " + completion)
console.log("------------------------------------")
bot.sendMessage(msg.chat.id, completion);
}
bot.on('message', handleRequest);