Skip to content

Commit

Permalink
A few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Feb 18, 2024
1 parent db2748a commit 6c1e1b8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 23 additions & 6 deletions src/discord/commands/global/d.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2152,18 +2164,23 @@ 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;
promptTokens = chatResponse.promptTokens;
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}`);
Expand Down
2 changes: 1 addition & 1 deletion src/global/commands/g.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 4 additions & 4 deletions src/prisma/tripbot/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6c1e1b8

Please sign in to comment.