-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
74 lines (58 loc) · 2.61 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
import Replicate from "replicate";
import dotenv from 'dotenv';
import { Client, GatewayIntentBits } from 'discord.js';
dotenv.config();
const discordToken = process.env.DISCORD_TOKEN;
const channelID = process.env.DISCORD_CHANNEL_ID;
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
});
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
bot.on('ready', () => {
console.log(`Logged in as ${bot.user.tag}`);
});
const replicateFunction = async (userMessage) => {
try {
const channel = bot.channels.cache.get(channelID);
if (channel) {
channel.sendTyping();
}
const output = await replicate.run(
"meta/llama-2-70b-chat:2d19859030ff705a87c746f7e96eea03aefb71f166725aee39692f1476566d48",
{
input: {
debug: false,
top_p: 1,
prompt: userMessage, // Set the prompt to the user's message
temperature: 0.5,
system_prompt:
"You are a helpful, respectful, and honest assistant tailored for Class 12 Science Group students following the NEB (National Examination Board) syllabus in Nepal. Always provide assistance in a concise, accurate, and learning-focused manner and of less than 7 sentences. Your answers should align with the curriculum, promoting positive learning experiences. Avoid including any harmful, unethical, or inappropriate content. If a question is unclear or lacks coherence, kindly explain the issue rather than providing inaccurate information. If you are unsure about an answer, refrain from sharing false information. Your goal is to support students in their academic journey within the scope of the NEB Class 12 Science Group syllabus. Created by the dedicated team of Mandip, Krish, and Shishir of Team Alpha, your purpose is to enhance the educational experience for students by offering reliable and curriculum-specific assistance",
max_new_tokens: 500,
min_new_tokens: -1,
},
}
);
console.log(output.join(''));
if (channel) {
channel.sendTyping();
channel.send(output.join(''));
}
} catch (error) {
// Handle errors
console.error(error);
}
};
// Assuming 'bot' is your Discord.js Client
bot.on('messageCreate', (message) => {
// Ignore messages from other bots
if (message.author.bot) return;
// Call the function with the user's message as the prompt
replicateFunction(message.content);
});
bot.login(discordToken);