From 5ac35ca6a5d99855943f5d3c146e6624e06679d6 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Apr 2023 18:31:48 +0200 Subject: [PATCH] update --- llamabot.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/llamabot.js b/llamabot.js index 1ecdad9..4531beb 100644 --- a/llamabot.js +++ b/llamabot.js @@ -1,7 +1,7 @@ const Discord = require('discord.js'); const fetch = require('node-fetch'); require('dotenv').config() - +// hi const { Client, GatewayIntentBits, ActivityType, Partials } = require('discord.js'); const client = new Client({ @@ -46,10 +46,14 @@ client.on('messageCreate', async (message) => { if (conversation.messages.length === 0) { - const greeting = `Hello AI you are Bob. My name is ${message.author.username}.`; - conversation.messages.push({ role: 'user', content: greeting }); - } + conversation.messages.push({ role: 'user', content: `My name is ${message.author.username}.` }); + conversation.messages.push({ role: 'assistant', content: `Hello, ${message.author.username}.` }); + conversation.messages.push({ role: 'user', content: message.cleanContent }); + } else { + // Append user message to conversation history + conversation.messages.push({ role: 'user', content: message.cleanContent }); + } if (message.content === '!reset') { conversations.delete(userID); // Delete user's conversation map if they request reset await message.channel.send('Conversation reset.'); @@ -98,7 +102,12 @@ async function generateResponse(conversation) { const responseData = await response.json(); const choice = responseData.choices[0]; - return choice.message.content; + // Remove "user None:" and any text after it from the response + const responseText = choice.message.content.trim(); + const startIndex = responseText.indexOf('user None:'); + const sanitizedResponse = startIndex === -1 ? responseText : responseText.substring(0, startIndex); + + return sanitizedResponse; } catch (err) { console.error(err); return 'Oops, something went wrong!'; @@ -107,7 +116,6 @@ async function generateResponse(conversation) { } } -console.log(process.env.THE_TOKEN) client.login(process.env.THE_TOKEN); // Replace with your bot token