diff --git a/app/services/Huggingface.ts b/app/services/Huggingface.ts index f3221094..f09381f6 100644 --- a/app/services/Huggingface.ts +++ b/app/services/Huggingface.ts @@ -13,9 +13,10 @@ export class Huggingface extends Service { async textGeneration(input: string, limit: number, temperature?: number) { return await hf.textGeneration({ model: Model, - inputs: `[INST] ${config.systemPrompt} Hi [/INST] ${ - config.systemAnswer - }[INST] ${input.replaceAll(/\[\/?INST\]|<\/?s>/g, "")} [/INST]`, + inputs: `[INST] ${config.systemPrompt} ${input.replaceAll( + /\[\/?INST\]|<\/?s>/g, + "" + )} [/INST]`, parameters: { max_new_tokens: limit, temperature: temperature, diff --git a/app/services/discord/modules/shitposting.ts b/app/services/discord/modules/shitposting.ts index 7e93f4a0..68ca1c69 100644 --- a/app/services/discord/modules/shitposting.ts +++ b/app/services/discord/modules/shitposting.ts @@ -13,6 +13,7 @@ const MSG_TRIGGER_COUNT = 10; // how many msgs in above interval until a msg is const MSG_CHAT_INTERVAL = 1000 * 60 * 60 * 2; // total time until a message is forced if below interval wasn't met (active chatters) const MSG_DEAD_CHAT_REVIVAL_INTERVAL = 1000 * 60 * 60 * 0.75; // idle (no active chatters) time until post, can be delayed by chatting const MSG_USE_AUTHOR_FREQ = 0.3; // use the author name instead of message +const MSG_USE_HUGGINGFACE_FREQ = 0.5; // use hugging face to reply instead of markov const MSG_REPLY_REACTION_FREQ = 0.3; const MSG_REPLY_REACTION_CLEAR_INTERVAL = 1000 * 60 * 60; const REACTION_FREQ = 0.005; // how often to react on messages; @@ -62,28 +63,35 @@ export const Shat = async (options?: { forceImage?: boolean; forceReply?: boolean; forceMessage?: string | Discord.MessageCreateOptions; + forceHuggingface?: boolean; }): Promise => { if (options?.forceMessage) return typeof options.forceMessage === "string" ? { content: options.forceMessage } : options.forceMessage; + const rng = Math.random(); + if (rng > TENOR_IMAGE_FREQ && !options?.forceImage) { const message = options?.msg?.replaceAll(`<@${DiscordConfig.bot.userId}> `, ""); let search: string | undefined; let shat: string | undefined; + if (message && !message.startsWith("http")) { - if (rng <= REPLY_FREQ || options?.forceReply) search = getWord(options?.msg); - const response = await globalThis.MetaConcord.container - .getService("Huggingface") - ?.textGeneration(message, 100); - shat = response.generated_text; + if (rng <= REPLY_FREQ || options?.forceReply) search = getWord(message); + if (options?.forceHuggingface) { + const response = await globalThis.MetaConcord.container + .getService("Huggingface") + ?.textGeneration(message, 100); + shat = response.generated_text; + } } if (!shat || shat === options?.msg) shat = await globalThis.MetaConcord.container .getService("Markov") ?.generate(getWord(search ?? options?.fallback), DefaultMarkovConfig); + return shat ? { content: shat } : undefined; } else { const images = globalThis.MetaConcord.container.getService("Motd")?.images; @@ -191,20 +199,14 @@ export default async (bot: DiscordBot) => { posting = true; if (options.msg) (options.msg.channel as Discord.TextChannel).sendTyping(); const rng = Math.random(); + const shouldUseHuggingface = rng <= MSG_USE_HUGGINGFACE_FREQ; const shouldUseAuthor = rng <= MSG_USE_AUTHOR_FREQ; const shouldSendImg = rng <= DISCORD_IMAGE_FREQ; const shouldSendSticker = rng <= STICKER_FREQ; const shouldSendEmoji = rng <= EMOJI_REPLY_FREQ; - const foundMatch = options.msg?.content - .split(" ") - .find(word => - options.originalMsg?.content - .split(" ") - .filter(orig => orig.match(new RegExp(`\\b${word}\\b`))) - ); // this feels like super slow but whatever const shat = await Shat({ - msg: foundMatch - ? foundMatch + msg: shouldUseHuggingface + ? `${options.msg?.author.globalName}: ${options.msg?.content}` : shouldUseAuthor ? options.msg?.author.globalName?.toLowerCase() ?? options.msg?.author.username?.toLowerCase() @@ -223,6 +225,7 @@ export default async (bot: DiscordBot) => { : shouldSendEmoji ? getRandomEmoji().toString() : undefined, + forceHuggingface: shouldUseHuggingface, }); if (shat) { if (options.msg) {