Skip to content

Commit

Permalink
fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it…
Browse files Browse the repository at this point in the history
… fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it
  • Loading branch information
TheYande committed Sep 4, 2024
1 parent 954a834 commit 0ef75e8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
6 changes: 5 additions & 1 deletion modules/ai/ai-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ export class AIChat {
* @returns An array of messages.
*/
getChatHistory(): { role: string; content: string | any[]; type?: string }[] {
return [...this.stickyMessages, ...this.history];
return [...this.history];
}

getStickies() {
return this.stickyMessages
}

/**
Expand Down
37 changes: 35 additions & 2 deletions modules/ai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,49 @@ defineEvent("messageCreate", async (m) => {
const userAi = dmAis[m.channel.id];
if (userAi) return userAi;
console.log("making new ai for " + m.author.displayName);
const newAi = new AIChat("https://reverse.mubi.tech/v1/chat/completions", [], 100);
const newAi = new AIChat("https://reverse.mubi.tech/v1/chat/completions", [...normalAi.getChatHistory(), { content: "You are now in DMS.", role: "system" }], 100);
dmPrompts.forEach((p) => newAi.sticky(p ?? ""));
dmAis[m.channel.id] = newAi;
return newAi;
})()
: normalAi;
let replyReason = ''
if (!forcedReply) {
if (!allowFreeWill(m.channel)) return
const reference = m.reference ? await m.fetchReference() : null;
if (!allowFreeWill(m.channel)) {
(
m.attachments
.filter((attachment) =>
attachment.contentType?.match(/^image\/(bmp|jpeg|png|bpm|webp)$/i),
)
.map(() => "").length
) ?
freeWill.inform(
[
{
type: "text",
text: `${m.reference ? `\n(replying to ${reference?.author.displayName} : ${reference?.author.id}\n${reference?.content})\n` : ""}${m.author.displayName} : ${m.author.id} : ${m.channel.isDMBased() ? `${m.author.displayName}'s DMs` : m.channel.name}\n${m.content}`,
},
...[
...m.attachments
.filter((attachment) =>
attachment.contentType?.match(
/^image\/(bmp|jpeg|png|bpm|webp)$/i,
),
)
.map((v) => v.url),
].map((i) => ({ type: "image_url", image_url: { url: i } })),
],
"user",
"complex",
)
: freeWill.inform(
`${m.reference ? `\n(replying to ${reference?.author.displayName} : ${reference?.author.id}\n${reference?.content})\n` : ""}${m.author.displayName} : ${m.author.id} : ${m.channel.isDMBased() ? `${m.author.displayName}'s DMs` : m.channel.name}\n${m.content}`,
"user",
"text",
);
}

let response =
(
m.attachments
Expand Down
6 changes: 3 additions & 3 deletions modules/ai/misc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TextChannel, ForumChannel, Channel } from "discord.js";
import config from "../../common/config.js";

const disallowFreeWillChannels: (TextChannel | ForumChannel)[] = [
const disallowFreeWillChannels: (TextChannel | ForumChannel | undefined)[] = [
config.channels.general,
config.channels.memes,
config.channels.queer,
Expand All @@ -11,7 +11,7 @@ const disallowFreeWillChannels: (TextChannel | ForumChannel)[] = [
config.channels.intros,
config.channels.verify,
config.channels.help
].filter(c => !!c)
].filter(c => !!c && c !== undefined)


export const allowFreeWill = (channel: Channel): boolean => {
Expand All @@ -25,4 +25,4 @@ export const allowFreeWill = (channel: Channel): boolean => {



const id = (c: { id: string }) => c.id
const id = (c?: { id?: string }) => c?.id

0 comments on commit 0ef75e8

Please sign in to comment.