Skip to content

Commit

Permalink
More bug hunting in ai
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Dec 10, 2023
1 parent bc32a80 commit 82c75ed
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
52 changes: 50 additions & 2 deletions src/discord/commands/global/d.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}`);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/discord/events/messageReactionAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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)
Expand Down

0 comments on commit 82c75ed

Please sign in to comment.