Yeah just gonna like, change everything
This commit is contained in:
parent
3b4168aa98
commit
344c1cb7e4
5
basePrompt.txt
Normal file
5
basePrompt.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
You are Bob, a large language model trained by OpenAI.
|
||||||
|
Answer as concisely as possible.
|
||||||
|
Knowledge cutoff: 2021
|
||||||
|
You do not have access to the current date or time.
|
||||||
|
The maximum number of characters in your response is exactly 2000 characters, which is a limitation of Discord.
|
|
@ -3,5 +3,10 @@
|
||||||
"name": "reset",
|
"name": "reset",
|
||||||
"description": "Reset the GPT-3 chat",
|
"description": "Reset the GPT-3 chat",
|
||||||
"type": 1
|
"type": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "info",
|
||||||
|
"description": "Info about the current session",
|
||||||
|
"type": 1
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"discord": {
|
"discord": {
|
||||||
"token": "",
|
"token": "",
|
||||||
"channel": ""
|
"authorized_channels": [""]
|
||||||
},
|
},
|
||||||
"openai": {
|
"openai": {
|
||||||
"key": "",
|
"key": "",
|
||||||
"resetTime":
|
"resetTime": 600000,
|
||||||
|
"basePrompt": {"role": "system", "name": "Bot", "content": "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible. Knowledge cutoff: 2021, You do not have access to the current date or time. The maximum number of characters in your response is exactly 2000 characters, no more."}
|
||||||
}
|
}
|
||||||
}
|
}
|
78
index.js
78
index.js
|
@ -24,6 +24,9 @@ const client = new Discord.Client({
|
||||||
intents: ["MessageContent", "GuildMessages", "Guilds"]
|
intents: ["MessageContent", "GuildMessages", "Guilds"]
|
||||||
});
|
});
|
||||||
var sessions = {}; // Keep track of sessions, not really used right now, but if I wanted to allow multiple sessions, I could
|
var sessions = {}; // Keep track of sessions, not really used right now, but if I wanted to allow multiple sessions, I could
|
||||||
|
var basePrompt = config.openai.basePrompt
|
||||||
|
basePrompt.content = fs.readFileSync("./basePrompt.txt", "utf8").toString();
|
||||||
|
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
console.log(`${colors.cyan("[INFO]")} Logged in as ${colors.green(client.user.tag)}`)
|
console.log(`${colors.cyan("[INFO]")} Logged in as ${colors.green(client.user.tag)}`)
|
||||||
// Log startup time in seconds
|
// Log startup time in seconds
|
||||||
|
@ -53,43 +56,74 @@ client.on("ready", () => {
|
||||||
|
|
||||||
client.on('interactionCreate', async (interaction) => {
|
client.on('interactionCreate', async (interaction) => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isCommand()) return;
|
||||||
switch(interaction.commandName) {
|
if (!config.discord.authorized_channels.includes(interaction.channelId)) return; // Only allow messages in the authorized channels
|
||||||
case "reset":
|
switch (interaction.commandName) {
|
||||||
// Reset the session
|
case "reset":
|
||||||
sessions[interaction.channelId] = {messages: []};
|
// Remove the session
|
||||||
|
await delete sessions[interaction.channelId];
|
||||||
interaction.reply(lang.reset);
|
interaction.reply(lang.reset);
|
||||||
break;
|
break;
|
||||||
|
case "info": // Info about the current session
|
||||||
|
// If the session is empty other than the base prompt, say so
|
||||||
|
if (!sessions[interaction.channelId]) return interaction.reply({
|
||||||
|
ephemeral: true,
|
||||||
|
content: lang.empty
|
||||||
|
});
|
||||||
|
if (sessions[interaction.channelId].messages.length == 1) {
|
||||||
|
return interaction.reply({
|
||||||
|
ephemeral: true,
|
||||||
|
content: lang.empty
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Otherwise, give some info like message count for both the user and the bot, and total message count
|
||||||
|
var userCount = 0;
|
||||||
|
var botCount = 0;
|
||||||
|
// Await counting the messages
|
||||||
|
await sessions[interaction.channelId].messages.forEach((message) => {
|
||||||
|
// Ignore the base prompt
|
||||||
|
if (message.content == basePrompt) return;
|
||||||
|
if (message.role == "user") {
|
||||||
|
userCount++;
|
||||||
|
} else if (message.role == "assistant") {
|
||||||
|
botCount++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
title: lang.info,
|
||||||
|
description: lang.infoDesc.replace("{userCount}", userCount).replace("{botCount}", botCount).replace("{total}", userCount + botCount),
|
||||||
|
color: 0x00FFFF,
|
||||||
|
|
||||||
|
// This is broken, I don't know why,
|
||||||
|
footer: {
|
||||||
|
text: lang.infoFooter
|
||||||
|
},
|
||||||
|
timestamp: sessions[interaction.channelId].started
|
||||||
|
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageCreate', async (message) => {
|
client.on('messageCreate', async (message) => {
|
||||||
if(!message.channelId == config.discord.channel) return;
|
if (!config.discord.authorized_channels.includes(message.channelId)) return; // Only allow messages in the authorized channels
|
||||||
if(message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
if(message.content.startsWith("!!")) return; // So you can chat without the bot replying
|
if (message.content.startsWith("!!")) return; // So you can chat without the bot replying
|
||||||
// If the session doesn't exist, create it
|
// If the session doesn't exist, create it
|
||||||
if (!sessions[message.channelId]) {
|
if (!sessions[message.channelId]) {
|
||||||
sessions[message.channelId] = {
|
sessions[message.channelId] = {
|
||||||
messages: [],
|
messages: [basePrompt],
|
||||||
// 10 minute auto reset
|
started: new Date(),
|
||||||
autoReset: setTimeout(() => {
|
|
||||||
sessions[message.channelId] = {messages: []};
|
|
||||||
message.channel.send(lang.timeout)
|
|
||||||
}, config.openai.resetTime)
|
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
// Reset the auto reset timer
|
|
||||||
clearTimeout(sessions[message.channelId].autoReset);
|
|
||||||
sessions[message.channelId].autoReset = setTimeout(() => {
|
|
||||||
sessions[message.channelId] = {messages: []};
|
|
||||||
message.channel.send(lang.timeout)
|
|
||||||
}, config.openai.resetTime);
|
|
||||||
}
|
}
|
||||||
var typing = setInterval(() => {
|
var typing = setInterval(() => {
|
||||||
message.channel.sendTyping();
|
message.channel.sendTyping();
|
||||||
}, 1000)
|
}, 1000)
|
||||||
// Add the message to the session
|
// Add the message to the session
|
||||||
sessions[message.channelId].messages.push({
|
sessions[message.channelId].messages.push({
|
||||||
"name": "User",
|
"name": `${message.author.id}`,
|
||||||
"content": message.content,
|
"content": message.content,
|
||||||
"role": "user"
|
"role": "user"
|
||||||
});
|
});
|
||||||
|
@ -104,7 +138,7 @@ client.on('messageCreate', async (message) => {
|
||||||
sessions[message.channelId].messages.push(output);
|
sessions[message.channelId].messages.push(output);
|
||||||
// Send the bot's response
|
// Send the bot's response
|
||||||
clearInterval(typing);
|
clearInterval(typing);
|
||||||
message.channel.send(output.content);
|
message.reply(output.content);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,9 @@
|
||||||
"description": "Your session has timed out. Say anything to start a new one!",
|
"description": "Your session has timed out. Say anything to start a new one!",
|
||||||
"color": 16711680
|
"color": 16711680
|
||||||
}]
|
}]
|
||||||
}
|
},
|
||||||
|
"empty": "There isn't a session here.",
|
||||||
|
"info": "Current Session",
|
||||||
|
"infoDesc": "AI Messages: {botCount}\nUser Messages: {userCount}\nTotal Messages: {total}",
|
||||||
|
"infoFooter": "Session Started"
|
||||||
}
|
}
|
Loading…
Reference in a new issue