Skip to content

Commit

Permalink
reverted back to .reply making fix to prev = ctx. Created optional co…
Browse files Browse the repository at this point in the history
…ntext manager as being in ctx/typing() makes ephemral not possible
  • Loading branch information
jfitz02 committed Aug 22, 2024
1 parent 55ab68f commit 6750f18
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cogs/commands/summarise.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import logging
from typing import Optional

Expand Down Expand Up @@ -38,13 +39,19 @@ def build_prompt(self, bullet_points, channel_name):
prompt = f"""People yap too much, I don't want to read all of it. The topic is something related to {channel_name}. In 2 sentences or less give me the gist of what is being said. {bullet_points} Note that the messages are in reverse chronological order:
"""
return prompt

def optional_context_manager(self, use: bool, cm: callable):
if use:
return cm()

return contextlib.nullcontext()

@commands.cooldown(CONFIG.SUMMARISE_LIMIT, CONFIG.SUMMARISE_COOLDOWN * 60, commands.BucketType.channel)
@commands.hybrid_command(help=LONG_HELP_TEXT, brief=SHORT_HELP_TEXT)
async def tldr(
self, ctx: Context, number_of_messages: int = 100, bullet_point_output: bool = False, private_view: bool = False):
number_of_messages = 400 if number_of_messages > 400 else number_of_messages

# avoid banned users
if not await is_author_banned_openai(ctx):
await ctx.send("You are banned from OpenAI!")
Expand All @@ -56,11 +63,13 @@ async def tldr(
messages = await self.create_message(messages, prompt)

# send the prompt to the ai overlords to process
async with ctx.typing():
async with self.optional_context_manager(not private_view, ctx.typing):
response = await self.dispatch_api(messages)
if response:
prev = ctx
for content in split_into_messages(response):
await ctx.send(content, allowed_mentions=mentions, ephemeral=private_view)
prev = await prev.reply(content, allowed_mentions=mentions, ephemeral=private_view)


async def dispatch_api(self, messages) -> Optional[str]:
logging.info(f"Making OpenAI request: {messages}")
Expand Down

0 comments on commit 6750f18

Please sign in to comment.