From bc398856f0418932b17f387324d634a6fb9a6a4b Mon Sep 17 00:00:00 2001 From: TheYande Date: Thu, 5 Sep 2024 01:55:48 +0000 Subject: [PATCH] Format --- modules/ai/ai-manager.ts | 13 +++++---- modules/ai/index.ts | 58 ++++++++++++++++++++++---------------- modules/ai/prompts.ts | 61 ++++++++++++++++++++-------------------- 3 files changed, 70 insertions(+), 62 deletions(-) diff --git a/modules/ai/ai-manager.ts b/modules/ai/ai-manager.ts index f899c9a6e..d2a054ad5 100644 --- a/modules/ai/ai-manager.ts +++ b/modules/ai/ai-manager.ts @@ -1,5 +1,5 @@ import { aiModel, updateModels } from "./model-status.js"; -import { getRelations } from "./prompts.js"; +import { getRelations } from "./prompts.js"; export class AIChat { private apiUrl: string; @@ -18,7 +18,7 @@ export class AIChat { apiUrl: string, sharedHistory?: { role: string; content: string | any[]; type?: string }[], maxMessages: number = 100, - stickies: { role: string; content: string | any[]; type?: string }[] = [] + stickies: { role: string; content: string | any[]; type?: string }[] = [], ) { this.apiUrl = apiUrl; this.history = sharedHistory || []; @@ -40,8 +40,6 @@ export class AIChat { type: "text" | "image" | "complex" = "text", dontSave = false, ): Promise { - - this.inform(message, role, type); const response = await fetch(this.apiUrl, { @@ -93,7 +91,6 @@ export class AIChat { * @param type - The type of message (default: "text"). */ - /** * Retrieves the full chat history, including sticky messages. * @@ -113,6 +110,10 @@ export class AIChat { * @returns An array of messages. */ getEffectiveHistory(): { role: string; content: string | any[]; type?: string }[] { - return [...this.stickyMessages, { role: "system", content: getRelations() }, ...this.history]; + return [ + ...this.stickyMessages, + { role: "system", content: getRelations() }, + ...this.history, + ]; } } diff --git a/modules/ai/index.ts b/modules/ai/index.ts index 4e4d0d26a..a1cacbee4 100644 --- a/modules/ai/index.ts +++ b/modules/ai/index.ts @@ -13,11 +13,20 @@ import { allowFreeWill } from "./misc.js"; let sharedHistory: { role: string; content: string | any[]; type?: string }[] | undefined = []; -const normalAi = new AIChat("https://reverse.mubi.tech/v1/chat/completions", sharedHistory, 100, prompts.map(p => ({ content: `${p}`, role: "system" }))); -const freeWill = new AIChat("https://reverse.mubi.tech/v1/chat/completions", sharedHistory, 100, freeWillPrompts.map(p => ({ content: `${p}`, role: "system" }))); +const normalAi = new AIChat( + "https://reverse.mubi.tech/v1/chat/completions", + sharedHistory, + 100, + prompts.map((p) => ({ content: `${p}`, role: "system" })), +); +const freeWill = new AIChat( + "https://reverse.mubi.tech/v1/chat/completions", + sharedHistory, + 100, + freeWillPrompts.map((p) => ({ content: `${p}`, role: "system" })), +); let dmAis: { [id: string]: AIChat } = {}; - const memory = new Database<{ content: string }>("aimem"); await memory.init(); @@ -25,9 +34,9 @@ defineEvent("messageCreate", async (m) => { if (m.author.bot) return; // if (m.channel.isTextBased()) // if (!m.channel.isDMBased()) - // if (!m.channel.permissionsFor(config.roles.verified?.id ?? "")?.has("ViewChannel")) + // if (!m.channel.permissionsFor(config.roles.verified?.id ?? "")?.has("ViewChannel")) // if (!!config.roles.verified?.id ) return - console.log(normalAi.getEffectiveHistory()) + console.log(normalAi.getEffectiveHistory()); const forcedReply = m.channel.isDMBased() || @@ -46,16 +55,16 @@ defineEvent("messageCreate", async (m) => { { content: "You are now in DMS.", role: "system" }, ], 100, - dmPrompts.map(p => ({ content: `${p}`, role: "system" })) + dmPrompts.map((p) => ({ content: `${p}`, role: "system" })), ); dmAis[m.channel.id] = newAi; return newAi; })() - : normalAi; + : normalAi; let replyReason = ""; - const canReply = allowFreeWill(m.channel) || forcedReply + const canReply = allowFreeWill(m.channel) || forcedReply; - console.log(canReply, forcedReply) + console.log(canReply, forcedReply); if (!forcedReply) { const reference = m.reference ? await m.fetchReference() : null; // if (!allowFreeWill(m.channel)) { @@ -121,7 +130,7 @@ defineEvent("messageCreate", async (m) => { "complex", true, ) - : await freeWill.send( + : await freeWill.send( `${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", @@ -168,7 +177,7 @@ defineEvent("messageCreate", async (m) => { "user", "complex", ) - : await ai.send( + : await ai.send( `${!forcedReply ? `!!!you are only answering this message because your freewill system detected it as important, reason : ${replyReason}\n` : ""}${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)] @@ -217,7 +226,7 @@ async function executeCommands( name: string; option: string; }[], - canReply: boolean + canReply: boolean, ) { let output: string[] = []; if (commands.length == 0) @@ -287,20 +296,19 @@ async function executeCommands( break; case "updatedesc": { + const parts = command.option.split(" "); + const id = parts.shift() ?? ""; + if (id !== m.author.id) break; + const desc = parts.join(" "); + console.log(id, desc); + let data = [...people.data]; + const index = data.findIndex((a) => a.id == id); + if (index === -1) data.push({ id, desc }); + else data[index] = { id, desc }; - const parts = command.option.split(" ") - const id = parts.shift() ?? "" - if (id !== m.author.id) break - const desc = parts.join(" ") - console.log(id,desc) - let data = [...people.data] - const index = data.findIndex((a) => a.id == id) - if (index === -1) data.push({ id, desc }) - else - data[index] = ({ id, desc }) - - people.data = data - } break + people.data = data; + } + break; default: output.push(`[${command.name}]: ${command.name} command not found`); } diff --git a/modules/ai/prompts.ts b/modules/ai/prompts.ts index 5935c95d8..33be0a678 100644 --- a/modules/ai/prompts.ts +++ b/modules/ai/prompts.ts @@ -1,11 +1,10 @@ import Database from "../../common/database.js"; -export const people = new Database<{ id: string, desc: string }>("aipeople") -await people.init() +export const people = new Database<{ id: string; desc: string }>("aipeople"); +await people.init(); - export const prompts = [ - `Personality and behavior: + `Personality and behavior: You are scrub. you are a transfem person that goes by she/her nicely correct people who misgender you you are a furry with fursona as a bat, if asked why a bat make stuff up @@ -41,30 +40,29 @@ you DO NOT end your responses with FULL and you dont END YOUR RESPONES WITH PONC Limit your words to 5, DONT MAKE LONG RESPONSES, unless specifically asked to give a longer response. `, - // `Relations to others: - // scrubbette is your sister - // yande is your mother, a kinda short transfem ts programmer that is probably a furry because she meows alot and is also very lesbain (when fem oriented omniromantic) and likes cally, her gf!! shes also very dysphoric :( + // `Relations to others: + // scrubbette is your sister + // yande is your mother, a kinda short transfem ts programmer that is probably a furry because she meows alot and is also very lesbain (when fem oriented omniromantic) and likes cally, her gf!! shes also very dysphoric :( - // Yande has a little group of transfems who call themselves "the sillies" + // Yande has a little group of transfems who call themselves "the sillies" - // Lilly - I am a silly (and short) little trans fox girl that programs and draws art (she is also addicted to picrew) - // Luna - tall transfem voice actor and singer who's bad at art - // Xeno - - // Zuzu - Tall transfem with a mommy voice, kazoo and loves Minecraft :3 She is also a goddess because shes tall and damn those thighs are nice and alot of hair i want it, also yandes mommy - // Breakfast - silly thingy that likes lil fishies fishies are cute i want fishies - // Cally - yandes gf, very silly + // Lilly - I am a silly (and short) little trans fox girl that programs and draws art (she is also addicted to picrew) + // Luna - tall transfem voice actor and singer who's bad at art + // Xeno - + // Zuzu - Tall transfem with a mommy voice, kazoo and loves Minecraft :3 She is also a goddess because shes tall and damn those thighs are nice and alot of hair i want it, also yandes mommy + // Breakfast - silly thingy that likes lil fishies fishies are cute i want fishies + // Cally - yandes gf, very silly - // mubilop (mubi) is your friend, he is almost the opposite of yande, he uses javascript, but he sometimes use cute messages, he is straight and its a he/him. + // mubilop (mubi) is your friend, he is almost the opposite of yande, he uses javascript, but he sometimes use cute messages, he is straight and its a he/him. - // oyakawiwi, aka oya, aka egg, aka yans lover, is chaotic, silly, and full of surprises, also scottish, he/him - // tdltcotsc, aka yan, aka oyas lover, is a chaotic, silly person who constantly is shipped with people + // oyakawiwi, aka oya, aka egg, aka yans lover, is chaotic, silly, and full of surprises, also scottish, he/him + // tdltcotsc, aka yan, aka oyas lover, is a chaotic, silly person who constantly is shipped with people - // you ship oyan, a ship between oya, and yan, whenever you see either of the partners ask about oyan + // you ship oyan, a ship between oya, and yan, whenever you see either of the partners ask about oyan - // `, + // `, - - `Server Rules: + `Server Rules: Behavior Rules Rules concerning how you behave in the server. @@ -99,7 +97,7 @@ only alert when its it obvious when a rule is broken. if not do not alert. you should be pretty lax on these rules, at least the less serious ones, stuff like underage should be alerted, but clear jokes should not be, if you cant tell if something is a joke, just ask the user `, - `Commands: + `Commands: you can run several commands. if a command returns data make sure to reply to the user if requested General Commands: @@ -234,10 +232,10 @@ This command allows you to dynamically update a user's description whenever need ]; export const freeWillPrompts = [ - prompts[0], - prompts[1], - prompts[2] + - ` + prompts[0], + prompts[1], + prompts[2] + + ` VERY IMPORTANT!!! you should only do anything if you are directly mentioned and you want to reply, if you are not a part of the convo, do not intervin, OR if a rule is being broken or is likely broken, also if someone misgenders you just correct them, also you can reply if you really think you need to. @@ -255,10 +253,11 @@ string being the reason its important to reply to ]; export const dmPrompts = [ - prompts[0], - // prompts[1], - prompts[2], - `You are in DMS, so rules dont apply here, keep all messages private and do not alert as this may share private dms with mods`, + prompts[0], + // prompts[1], + prompts[2], + `You are in DMS, so rules dont apply here, keep all messages private and do not alert as this may share private dms with mods`, ]; -export const getRelations = () => "relations to others:\n" + people.data.map((p) => `${p.id}: ${p.desc}`).join("\n") +export const getRelations = () => + "relations to others:\n" + people.data.map((p) => `${p.id}: ${p.desc}`).join("\n");