From 82c75edfe576e44302782785d23eaa4ff3f2cd66 Mon Sep 17 00:00:00 2001 From: LunaUrsa <1836049+LunaUrsa@users.noreply.github.com> Date: Sun, 10 Dec 2023 09:19:52 -0600 Subject: [PATCH] More bug hunting in ai --- src/discord/commands/global/d.ai.ts | 52 +++++++++++++++++++++++- src/discord/events/messageReactionAdd.ts | 10 ++--- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/discord/commands/global/d.ai.ts b/src/discord/commands/global/d.ai.ts index 64db95bfc..bb5befbda 100644 --- a/src/discord/commands/global/d.ai.ts +++ b/src/discord/commands/global/d.ai.ts @@ -1018,6 +1018,43 @@ async function aiAudit( ); } catch (error) { log.error(F, `${error}`); + log.error(F, `${JSON.stringify({ + name: 'Persona', + value: stripIndents`**${aiPersona.name} (${aiPersona.ai_model})** - ${aiPersona.prompt}`, + inline: false, + }, null, 2)}`); + log.error(F, `${JSON.stringify({ + name: 'Context', + value: stripIndents`${contextMessageOutput || 'No context'}`, + inline: false, + }, null, 2)}`); + log.error(F, `${JSON.stringify({ + name: 'Prompt', + value: stripIndents`${promptMessage.url} ${promptMessage.member?.displayName}: ${promptMessage.cleanContent}`, + inline: false, + }, null, 2)}`); + log.error(F, `${JSON.stringify({ + name: 'Result', + value: stripIndents`${chatResponse.slice(0, 1023)}`, + inline: false, + }, null, 2)}`); + log.error(F, `${JSON.stringify({ + name: 'Chat Tokens', + value: stripIndents`${promptTokens + completionTokens} Tokens \n($${(promptCost + completionCost).toFixed(6)})`, + inline: true, + }, null, 2)}`); + log.error(F, `${JSON.stringify({ + name: 'User Tokens', + value: `${aiUsageData.tokens} Tokens\n($${((aiUsageData.tokens / 1000) + * aiCosts[aiPersona.ai_model].output).toFixed(6)})`, + inline: true, + }, null, 2)}`); + log.error(F, `${JSON.stringify({ + name: 'Persona Tokens', + value: `${aiPersona.total_tokens} Tokens\n($${((aiPersona.total_tokens / 1000) + * aiCosts[aiPersona.ai_model].output).toFixed(6)})`, + inline: true, + }, null, 2)}`); } // Get the channel to send the message to @@ -1447,6 +1484,8 @@ export async function discordAiChat( if (messages[0].cleanContent.length < 1) return; if (messages[0].channel.type === ChannelType.DM) return; + log.debug(F, ` ${messages[0].author.displayName} asked me ${messages[0].cleanContent}`); + // Check if the channel is linked to a persona const aiLinkData = await getLinkedChannel(messages[0].channel); // log.debug(F, `aiLinkData: ${JSON.stringify(aiLinkData, null, 2)}`); @@ -1483,6 +1522,10 @@ export async function discordAiChat( const { response, promptTokens, completionTokens } = await aiChat(aiPersona, messageList, messageData.author.id); + log.debug(F, `response: ${response}`); + // log.debug(F, `promptTokens: ${promptTokens}`); + // log.debug(F, `completionTokens: ${completionTokens}`); + // Increment the tokens used await db.ai_personas.update({ where: { @@ -1541,8 +1584,13 @@ export async function discordAiChat( const replyMessage = await messages[0].reply(response.slice(0, 2000)); // React to that message with thumbs up and thumbs down emojis - await replyMessage.react(env.EMOJI_THUMB_UP); - await replyMessage.react(env.EMOJI_THUMB_DOWN); + try { + await replyMessage.react(env.EMOJI_THUMB_UP); + await replyMessage.react(env.EMOJI_THUMB_DOWN); + } catch (error) { + log.error(F, `Error reacting to message: ${messages[0].url}`); + log.error(F, `${error}`); + } } export async function discordAiConversate( diff --git a/src/discord/events/messageReactionAdd.ts b/src/discord/events/messageReactionAdd.ts index 8474bb25f..e6b8e13c1 100644 --- a/src/discord/events/messageReactionAdd.ts +++ b/src/discord/events/messageReactionAdd.ts @@ -32,8 +32,8 @@ export const messageReactionAdd: MessageReactionAddEvent = { } if (!messageReaction.message.guild) return; // Ignore DMs - log.info(F, stripIndents`${user} added ${messageReaction.emoji.name} on to \ - ${messageReaction.message.author?.displayName}'s message`); + // log.info(F, stripIndents`${user} added ${messageReaction.emoji.name} on to \ + // ${messageReaction.message.author?.displayName}'s message`); // AI audit stuff comes first cuz this can happen on other guilds // We want to collect every message tripbot sends that gets three thumbs downs const thumbsUpEmojis = ['👍', '👍🏻', '👍🏼', '👍🏽', '👍🏾', '👍🏿', 'ts_thumbup']; @@ -43,12 +43,12 @@ export const messageReactionAdd: MessageReactionAddEvent = { || thumbsDownEmojis.includes(messageReaction.emoji.name as string) ) ) { - log.debug(F, `Someone reacted to tripbot's message with an audit emoji (${messageReaction.emoji.name})`); + // log.debug(F, `Someone reacted to tripbot's message with an audit emoji (${messageReaction.emoji.name})`); const auditLimit = env.NODE_ENV === 'production' ? 4 : 2; - log.debug(F, `Audit limit is ${auditLimit}, emoji count is ${messageReaction.count}`); + // log.debug(F, `Audit limit is ${auditLimit}, emoji count is ${messageReaction.count}`); if (messageReaction.count === auditLimit) { - log.debug(F, `Audit limit reached (${auditLimit})`); + // log.debug(F, `Audit limit reached (${auditLimit})`); const action = thumbsUpEmojis.includes(messageReaction.emoji.name as string) ? 'approve' : 'reject'; const message = thumbsUpEmojis.includes(messageReaction.emoji.name as string)