From 6c1e1b83ca3646810b79829eab1545a758e646f6 Mon Sep 17 00:00:00 2001 From: LunaUrsa <1836049+LunaUrsa@users.noreply.github.com> Date: Sun, 18 Feb 2024 15:08:56 -0600 Subject: [PATCH] A few fixes --- package.json | 2 +- src/discord/commands/global/d.ai.ts | 29 +++++++++++++++---- src/global/commands/g.ai.ts | 2 +- .../20240218205351_ai_ui_fix/migration.sql | 18 ++++++++++++ src/prisma/tripbot/schema.prisma | 8 ++--- 5 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 src/prisma/tripbot/migrations/20240218205351_ai_ui_fix/migration.sql diff --git a/package.json b/package.json index 491c43089..b837a90ed 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "db:validateSchema": "docker exec -it tripbot npx prisma validate", "db:generateClient": "npx prisma generate && docker exec -it tripbot npx prisma generate", "db:pushDev": "docker exec -it tripbot npx prisma db push && npm run tripbot:db:generate", - "db:migrateDev": "docker exec -it tripbot npx prisma migrate dev -n ai_ui_update", + "db:migrateDev": "docker exec -it tripbot npx prisma migrate dev -n ai_ui_fix", "db:seed": "docker exec -it tripbot npx prisma db seed", "## PGADMIN ##": "", "pgadmin": "docker compose --project-name tripbot up -d --force-recreate --build tripbot_pgadmin", diff --git a/src/discord/commands/global/d.ai.ts b/src/discord/commands/global/d.ai.ts index f95930bef..846152f6a 100644 --- a/src/discord/commands/global/d.ai.ts +++ b/src/discord/commands/global/d.ai.ts @@ -781,6 +781,15 @@ async function createPersona( const selectedModel = modelSelectMenu.options.find(option => option.default)?.value; log.debug(F, `selectedModel: ${JSON.stringify(selectedModel, null, 2)}`); + let modelName = ''; + if (selectedModel === 'GPT_3_5_TURBO') { + modelName = 'GPT-3.5'; + } else if (selectedModel === 'GPT_4_TURBO') { + modelName = 'GPT-4'; + } else if (selectedModel === 'GEMINI_PRO') { + modelName = 'Gemini'; + } + await interaction.showModal(new ModalBuilder() .setCustomId(`aiPromptModal~${interaction.id}`) .setTitle('Modal') @@ -789,7 +798,7 @@ async function createPersona( .addComponents(new TextInputBuilder() .setCustomId('name') .setPlaceholder(stripIndents`TripBot V3`) - .setValue(stripIndents`TripBot V3`) + .setValue(stripIndents`TripBot (${modelName})`) .setLabel('Unique name for your persona') .setMinLength(3) .setStyle(TextInputStyle.Short)), @@ -1750,11 +1759,14 @@ async function link( const verb = aiLinkData ? 'updated' : 'created'; await db.ai_channels.upsert({ + // where: { + // channel_id_persona_id: { + // channel_id: selectedChannel, + // persona_id: personaData.id, + // }, + // }, where: { - channel_id_persona_id: { - channel_id: selectedChannel, - persona_id: personaData.id, - }, + channel_id: selectedChannel, }, create: { channel_id: selectedChannel, @@ -2152,11 +2164,15 @@ export async function aiMessage( const typingInterval = setInterval(() => { messageData.channel.sendTyping(); - }, 5000); // Start typing indicator every 5 seconds + }, 9000); // Start typing indicator every 9 seconds let response = ''; let promptTokens = 0; let completionTokens = 0; + const typingFailsafe = setInterval(() => { + clearInterval(typingInterval); // Stop sending typing indicator + }, 30000); // Failsafe to stop typing indicator after 30 seconds + try { const chatResponse = await aiChat(aiPersona, messageList, messageData.author.id, attachmentInfo); response = chatResponse.response; @@ -2164,6 +2180,7 @@ export async function aiMessage( completionTokens = chatResponse.completionTokens; } finally { clearInterval(typingInterval); // Stop sending typing indicator + clearTimeout(typingFailsafe); // Clear the failsafe timeout to prevent it from running if we've successfully stopped typing } log.debug(F, `response from API: ${response}`); diff --git a/src/global/commands/g.ai.ts b/src/global/commands/g.ai.ts index 2c0fe31a2..fadd78a16 100644 --- a/src/global/commands/g.ai.ts +++ b/src/global/commands/g.ai.ts @@ -635,7 +635,7 @@ async function openAiConversation( log.debug(F, `messageContent: ${JSON.stringify(messageContent, null, 2)}`); // Send the result to the dev room - await devRoom.send(`AI Conversation succeeded: ${JSON.stringify(messageContent, null, 2)}`); + // await devRoom.send(`AI Conversation succeeded: ${JSON.stringify(messageContent, null, 2)}`); // await messages[0].reply(result.response.slice(0, 2000)); response = (messageContent as MessageContentText).text.value; diff --git a/src/prisma/tripbot/migrations/20240218205351_ai_ui_fix/migration.sql b/src/prisma/tripbot/migrations/20240218205351_ai_ui_fix/migration.sql new file mode 100644 index 000000000..8bb7c2e15 --- /dev/null +++ b/src/prisma/tripbot/migrations/20240218205351_ai_ui_fix/migration.sql @@ -0,0 +1,18 @@ +/* + Warnings: + + - A unique constraint covering the columns `[channel_id]` on the table `ai_channels` will be added. If there are existing duplicate values, this will fail. + +*/ + +-- DropConstraint +ALTER TABLE ai_channels DROP CONSTRAINT aichannels_channelid_personaid_unique; + +-- DropIndex +-- DROP INDEX "aichannels_channelid_personaid_unique"; + +-- CreateIndex +CREATE UNIQUE INDEX "aichannels_channelid_unique" ON "ai_channels"("channel_id"); + +-- AddForeignKey +ALTER TABLE "ai_channels" ADD CONSTRAINT "aichannels_guildid_foreign" FOREIGN KEY ("guild_id") REFERENCES "discord_guilds"("id") ON DELETE NO ACTION ON UPDATE NO ACTION; diff --git a/src/prisma/tripbot/schema.prisma b/src/prisma/tripbot/schema.prisma index 98d2e8acc..9bc810d1a 100644 --- a/src/prisma/tripbot/schema.prisma +++ b/src/prisma/tripbot/schema.prisma @@ -207,7 +207,7 @@ model discord_guilds { reaction_roles reaction_roles[] ai_moderation ai_moderation? user_actions user_actions[] - // ai_channels ai_channels[] + ai_channels ai_channels[] } model drug_articles { @@ -440,11 +440,11 @@ model ai_channels { persona_id String @db.Uuid ai_personas ai_personas @relation(fields: [persona_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "aichannels_personaid_foreign") - // discord_guilds discord_guilds @relation(fields: [guild_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "aichannels_guildid_foreign") + discord_guilds discord_guilds @relation(fields: [guild_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "aichannels_guildid_foreign") - // @@unique([channel_id], map: "aichannels_channelid_unique") + @@unique([channel_id], map: "aichannels_channelid_unique") - @@unique([channel_id, persona_id], map: "aichannels_channelid_personaid_unique") + // @@unique([channel_id, persona_id], map: "aichannels_channelid_personaid_unique") } model ai_moderation {