Skip to content

Commit

Permalink
adjust systemprompt and add 50/50 chance
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Dec 5, 2023
1 parent 841926a commit 3c93218
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
7 changes: 4 additions & 3 deletions app/services/Huggingface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export class Huggingface extends Service {
async textGeneration(input: string, limit: number, temperature?: number) {
return await hf.textGeneration({
model: Model,
inputs: `<s>[INST] ${config.systemPrompt} Hi [/INST] ${
config.systemAnswer
}</s>[INST] ${input.replaceAll(/\[\/?INST\]|<\/?s>/g, "")} [/INST]`,
inputs: `[INST] ${config.systemPrompt} ${input.replaceAll(
/\[\/?INST\]|<\/?s>/g,
""
)} [/INST]`,
parameters: {
max_new_tokens: limit,
temperature: temperature,
Expand Down
31 changes: 17 additions & 14 deletions app/services/discord/modules/shitposting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,28 +63,35 @@ export const Shat = async (options?: {
forceImage?: boolean;
forceReply?: boolean;
forceMessage?: string | Discord.MessageCreateOptions;
forceHuggingface?: boolean;
}): Promise<Discord.MessageCreateOptions | undefined> => {
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;
Expand Down Expand Up @@ -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()
Expand All @@ -223,6 +225,7 @@ export default async (bot: DiscordBot) => {
: shouldSendEmoji
? getRandomEmoji().toString()
: undefined,
forceHuggingface: shouldUseHuggingface,
});
if (shat) {
if (options.msg) {
Expand Down

0 comments on commit 3c93218

Please sign in to comment.