Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added private_view input to hide response (only works on slash comman… #261

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading