From 4706ac2daa2ff4dee255b077f8c3ae46572ae0b7 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Mon, 3 Jun 2024 00:19:50 +0100 Subject: [PATCH] Add trump command --- src/cogs/ollama.py | 65 +++++++++++++++++++++++++++++++++++++++-- src/cogs/quote_quota.py | 6 ---- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/cogs/ollama.py b/src/cogs/ollama.py index 248a937..28d3244 100644 --- a/src/cogs/ollama.py +++ b/src/cogs/ollama.py @@ -76,6 +76,8 @@ class OllamaDownloadHandler: self.eval_count = 0 self.prompt_eval_count = 0 + self.log = logging.getLogger("jimmy.cogs.ollama.download") + def abort(self): self._abort.set() @@ -111,7 +113,12 @@ class OllamaDownloadHandler: async def flatten(self) -> "OllamaDownloadHandler": """Returns the current instance, but fully consumed.""" async for _ in self: - pass + self.log.info( + "Downloading orca-mini:7b on server %r - %s (%.2f%%)", + self.base_url, + self.status, + self.percent + ) return self @@ -905,7 +912,7 @@ class Ollama(commands.Cog): tried = set() for _ in range(10): - server = self.next_server() + server = self.next_server(tried) if await self.check_server(CONFIG["ollama"][server]["base_url"]): break tried.add(server) @@ -999,6 +1006,60 @@ class Ollama(commands.Cog): break await msg.edit(embed=embed) + @commands.command(hidden=True) + async def trump(self, ctx: commands.Context, max_history: int = 100): + async with ctx.channel.typing(): + thread_id = self.history.create_thread( + ctx.author, + "You are the former united states president, Donald Trump, convicted of 34 felonies." + " You have been posting approximately 50 times a day on your platform 'Truth Social' spreading your" + " words of truth to the american people in order to make america great again. After reading through all" + " of your previous truth posts, you should generate another one, ready to be posted, " + "under 4000 characters." + ) + messages = self.history.get_history(thread_id) + async for message in ctx.channel.history(limit=max_history): + if message.author.id == 1101439218334576742 and len(message.embeds): + embed = message.embeds[0] + if embed.type == "rich" and embed.colour and embed.colour.value == 0x5448EE: + self.history.add_message(thread_id, "assistant", embed.description) + self.history.add_message(thread_id, "user", "Generate a new truth post.") + self.history.save_thread(thread_id) + + tried = set() + for _ in range(10): + server = self.next_server(tried) + if await self.check_server(CONFIG["ollama"][server]["base_url"]): + break + tried.add(server) + else: + return await ctx.reply("All servers are offline. Please try again later.", delete_after=300) + + client = OllamaClient(CONFIG["ollama"][server]["base_url"]) + async with self.servers[server]: + if not await client.has_model_named("llama2-uncensored", "7b-chat"): + with client.download_model("llama2-uncensored", "7b-chat") as handler: + await handler.flatten() + + embed = discord.Embed( + title="New Truth!", + description="", + colour=0x6559FF + ) + msg = await ctx.reply(embed=embed) + last_edit = time.time() + messages = self.history.get_history(thread_id) + async with client.new_chat("llama2-uncensored:7b-chat", messages) as handler: + async for ln in handler: + embed.description += ln["message"]["content"] + if len(embed.description) >= 4000: + break + if (time.time() - last_edit) >= 2.5: + await msg.edit(embed=embed) + last_edit = time.time() + embed.set_footer(text="Finished generating truth based off of {:,} messages.".format(len(messages))) + await msg.edit(embed=embed) + def setup(bot): bot.add_cog(Ollama(bot)) diff --git a/src/cogs/quote_quota.py b/src/cogs/quote_quota.py index 89784ab..ec946d6 100644 --- a/src/cogs/quote_quota.py +++ b/src/cogs/quote_quota.py @@ -223,12 +223,6 @@ class QuoteQuota(commands.Cog): def is_truth(msg: discord.Message) -> bool: if msg.author.id == 1101439218334576742: - # if msg.created_at.timestamp() <= 1713202855.80234: - # # Pre 6:30pm 15th April, embeds were not tagged for detection. - # truth = any((_te.type == "rich" for _te in msg.embeds)) - # if truth: - # self.log.debug("Found untagged rich trump truth embed: %r", msg.id) - # return True for __t_e in msg.embeds: if __t_e.type == "rich" and __t_e.colour is not None and __t_e.colour.value == 0x5448EE: self.log.debug("Found tagged rich trump truth embed: %r", msg.id)