aboutsummaryrefslogtreecommitdiff
path: root/bot/src/plugins/chatbot.js
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-03-20 16:20:59 -0400
committerAndrew Lee <andrew@alee14.me>2025-03-20 16:20:59 -0400
commit0f55f5f52e84fd5cdedb448d408dfa3c69c5fe5f (patch)
tree8ec510bcfaabd2adb2d3e13407658c13ec3deb64 /bot/src/plugins/chatbot.js
parentc06c0be2e7520ceaf5284472d0d99c7417aceb7a (diff)
downloadAleeBot-0f55f5f52e84fd5cdedb448d408dfa3c69c5fe5f.tar.gz
AleeBot-0f55f5f52e84fd5cdedb448d408dfa3c69c5fe5f.tar.bz2
AleeBot-0f55f5f52e84fd5cdedb448d408dfa3c69c5fe5f.zip
Modularized LLM chatbot; Added back eval
Diffstat (limited to 'bot/src/plugins/chatbot.js')
-rw-r--r--bot/src/plugins/chatbot.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/bot/src/plugins/chatbot.js b/bot/src/plugins/chatbot.js
index f4095a2..3da7421 100644
--- a/bot/src/plugins/chatbot.js
+++ b/bot/src/plugins/chatbot.js
@@ -1 +1,34 @@
-// add llm feature here
+import { ollamaGlobal, ollamaModel } from '../storage/consts.js';
+import { ollama } from '../utils/ollama.js';
+import { AttachmentBuilder } from 'discord.js';
+import { guildSettings } from '../models/guild-settings.js';
+
+export async function ChatBot(msg, args) {
+ const guildSetting = await guildSettings.findOne({ where: { guildID: msg.guild.id } });
+
+ if (!guildSetting.ollamaEnabled) return;
+ if (!ollamaGlobal) return msg.reply('Sorry, the LLM chatbot feature has been turned off.');
+ if (!args) return msg.reply('Sorry? What was that?');
+
+ try {
+ const loadingMessage = await msg.reply('Thinking...');
+
+ const response = await ollama.chat({
+ model: ollamaModel,
+ messages: [{ role: 'user', content: args }],
+ });
+
+ let content = response.message.content;
+
+ if (content.length > 2000) {
+ const attachment = new AttachmentBuilder(Buffer.from(content, 'utf-8'), { name: 'output.txt' });
+ return await loadingMessage.edit({ files: [attachment] });
+ } else {
+ return await loadingMessage.edit({ content });
+ }
+
+ } catch (err) {
+ console.error(err);
+ await msg.reply(`Something went wrong. [Submit an issue at the AleeBot repository.](<https://github.com/Alee14/AleeBot/issues>)\nMessage:\n\`\`\`${err.stack}\`\`\``);
+ }
+}