giving errors and responses a more human feel.
This commit is contained in:
26
llamabot.js
26
llamabot.js
@ -1,5 +1,9 @@
|
||||
const Discord = require('discord.js');
|
||||
const fetch = require('node-fetch');
|
||||
const emptyResponses = require('./assets/emptyMessages.js');
|
||||
const resetResponses = require('./assets/resetMessages.js');
|
||||
const errorMessages = require('./assets/errorMessages.js');
|
||||
|
||||
require('dotenv').config()
|
||||
// hi
|
||||
const { Client, GatewayIntentBits, ActivityType, Partials } = require('discord.js');
|
||||
@ -33,7 +37,7 @@ client.on('messageCreate', async (message) => {
|
||||
if (message.channel.id !== channelID && message.channel.id !== channelID2) {
|
||||
return;
|
||||
}
|
||||
if (message.author.bot) return; // Ignore messages from bots
|
||||
if (message.author.bot) return; // Ignore messages from bots
|
||||
|
||||
if (conversations.get(message.author.id)?.busy) {
|
||||
message.delete()
|
||||
@ -52,8 +56,8 @@ client.on('messageCreate', async (message) => {
|
||||
conversation.messages.push({ role: 'user', content: message.cleanContent });
|
||||
|
||||
} else {
|
||||
// Append user message to conversation history
|
||||
conversation.messages.push({ role: 'user', content: message.cleanContent });
|
||||
// Append user message to conversation history
|
||||
conversation.messages.push({ role: 'user', content: message.cleanContent });
|
||||
}
|
||||
if (message.content === '!reset' || message.content === '!r') {
|
||||
conversations.delete(userID); // Delete user's conversation map if they request reset
|
||||
@ -75,18 +79,22 @@ client.on('messageCreate', async (message) => {
|
||||
if (response && response.trim()) {
|
||||
// Send response to user if it's not empty
|
||||
await message.channel.send(response);
|
||||
conversation.busy = false;
|
||||
} else {
|
||||
// Handle empty response here
|
||||
await message.channel.send("Sorry, I don't have much to say about that.");
|
||||
// Auto delete the map if the user creates an empty respose from the AI
|
||||
const randomResponse = emptyResponses[Math.floor(Math.random() * emptyResponses.length)];
|
||||
// We had an empty response, create a new memory map for sanity.
|
||||
await message.channel.send(randomResponse); // give the user a human like reponse about the error
|
||||
conversations.delete(userID); // Delete user's conversation map if they request reset
|
||||
await message.channel.send('To avoid bugs, I reset our conversation, what can I help you with?');
|
||||
const resetMessage = resetResponses[Math.floor(Math.random() * resetResponses.length)];
|
||||
await message.channel.send(resetMessage); // give a notification of reset using a human like response.
|
||||
conversation.busy = false;
|
||||
}
|
||||
conversations.set(userID, conversation); // Update user's conversation map in memory
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await message.channel.send('Oops, something went wrong!\nYou can try !reset which will start a new session.');
|
||||
} finally {
|
||||
const errorMessage = errorMessages[Math.floor(Math.random() * errorMessages.length)];
|
||||
await message.channel.send(errorMessage); // give a notification of reset using a human like response. } finally {
|
||||
conversation.busy = false;
|
||||
}
|
||||
});
|
||||
@ -104,7 +112,7 @@ async function generateResponse(conversation) {
|
||||
'accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ messages: conversation.messages}),
|
||||
body: JSON.stringify({ messages: conversation.messages }),
|
||||
signal: controller.signal
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user