Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
fix: auto reset conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
MrlolDev committed Dec 15, 2023
1 parent 8175453 commit 2f43d05
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/bot/commands/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ async function buildInfo(
content: "An error occurred",
});
}
const loadingIndicator = LOADING_INDICATORS[Math.floor(Math.random() * 5)];
let loadingIndicatorId: string | boolean | number | object = await getSettingsValue(user, "general:loadingIndicator");
if (!loadingIndicatorId) {
loadingIndicatorId = (await getDefaultValues("general:loadingIndicator")) as string;
}
const loadingIndicator = LOADING_INDICATORS[loadingIndicatorId as number];

let lastUpdate = Date.now();
let done = false;
event.on("data", async (data) => {
Expand Down
32 changes: 32 additions & 0 deletions src/bot/commands/describe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ButtonStyles, CreateMessageOptions, MessageComponentTypes } from "@discordeno/bot";
import config from "../../config.js";
import { createCommand } from "../config/setup.js";
import { IMAGE_MODELS } from "../models/index.js";
import EventEmitter from "events";
import { LOADING_INDICATORS } from "../../types/models/users.js";
import { mergeImages } from "../utils/image-merge.js";
import { getDefaultValues, getSettingsValue } from "../utils/settings.js";
import { chargePlan, requiredPremium } from "../utils/premium.js";

export default createCommand({
body: {
name: "describe",
description: "Describe an image using AI",
type: "ChatInput",
options: [
{
type: "Attachment",
name: "image",
description: "The image to use",
required: true,
}
],
},
cooldown: {
user: 1.5 * 60 * 1000,
voter: 1.25 * 60 * 1000,
subscription: 1 * 60 * 1000,
},
interaction: async ({ interaction, options, env, premium }) => {
}
})
14 changes: 14 additions & 0 deletions src/bot/utils/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ export async function getConversation(userId: string, modelName: string) {
id: `${userId}-${modelName}`,
})) as Conversation;
if (!conversation) return null;
const numberOfUserMessages = conversation.history.messages.filter((x) => x.role === "user").length;
const numberOfBotMessages = conversation.history.messages.filter((x) => x.role !== "user").length;
// for each 2 messages, there would be 1 bot message
if (numberOfUserMessages > numberOfBotMessages * 2) {
const updatedConversation = {
history: {
datasetId: conversation.history.datasetId,
messages: [],
},
last_update: Date.now(),
};
await update("conversations", conversation.id, updatedConversation);
conversation.history.messages = [];
}
return conversation;
}

Expand Down
4 changes: 3 additions & 1 deletion src/bot/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function key2data(key: string) {
}

export type EnabledSectionsTypes = "chat" | "image" | "premium" | string;
export const EnabledSections: Array<EnabledSectionsTypes> = ["chat", "image"];
export const EnabledSections: Array<EnabledSectionsTypes> = ["chat", "image", "general"];
export async function generateSections(pageName: EnabledSectionsTypes, env: Environment): Promise<CreateMessageOptions | null> {
let message: null | CreateMessageOptions = null;
const user = env.user;
Expand Down Expand Up @@ -185,6 +185,7 @@ export function getMetadata(
value: l.id,
})),
emoji: "🌐",
enabled: true,
};
case "general:loadingIndicator":
return {
Expand All @@ -196,6 +197,7 @@ export function getMetadata(
value: l.emoji?.id || "default",
})),
emoji: "🔄",
enabled: true,
};
case "chat:model":
return {
Expand Down

0 comments on commit 2f43d05

Please sign in to comment.