Skip to content

Commit

Permalink
Merge pull request #261 from UWCS/tldr-hide
Browse files Browse the repository at this point in the history
Added private_view input to hide response (only works on slash comman…
  • Loading branch information
aaj2005 authored Aug 22, 2024
2 parents 99fc34e + 6750f18 commit fbc89c3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 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,14 +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 ):
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 @@ -57,12 +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.message
prev = ctx
for content in split_into_messages(response):
prev = await prev.reply(content, allowed_mentions=mentions)
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 fbc89c3

Please sign in to comment.