Format Python code with psf/black push

github-actions 2 years ago
parent b90d50ab07
commit fee6062df2

@ -40,7 +40,9 @@ class SearchService(discord.Cog, name="SearchService"):
self.redo_users = {} self.redo_users = {}
# Make a mapping of all the country codes and their full country names: # Make a mapping of all the country codes and their full country names:
async def paginate_embed(self, response_text, user: discord.Member, original_link=None): async def paginate_embed(
self, response_text, user: discord.Member, original_link=None
):
"""Given a response text make embed pages and return a list of the pages. Codex makes it a codeblock in the embed""" """Given a response text make embed pages and return a list of the pages. Codex makes it a codeblock in the embed"""
response_text = [ response_text = [
@ -53,7 +55,9 @@ class SearchService(discord.Cog, name="SearchService"):
for count, chunk in enumerate(response_text, start=1): for count, chunk in enumerate(response_text, start=1):
if not first: if not first:
page = discord.Embed( page = discord.Embed(
title=f"Search Results" if not original_link else f"Follow-up results", title=f"Search Results"
if not original_link
else f"Follow-up results",
description=chunk, description=chunk,
url=original_link, url=original_link,
) )
@ -130,7 +134,10 @@ class SearchService(discord.Cog, name="SearchService"):
urls = "\n".join(f"<{url}>" for url in urls) urls = "\n".join(f"<{url}>" for url in urls)
if from_followup: if from_followup:
original_link, followup_question = from_followup.original_link, from_followup.followup_question original_link, followup_question = (
from_followup.original_link,
from_followup.followup_question,
)
query_response_message = f"**Question:**\n\n`{followup_question}`\n\n**Google Search Query**\n\n`{refined_text.strip()}`\n\n**Final Answer:**\n\n{response.response.strip()}\n\n**Sources:**\n{urls}" query_response_message = f"**Question:**\n\n`{followup_question}`\n\n**Google Search Query**\n\n`{refined_text.strip()}`\n\n**Final Answer:**\n\n{response.response.strip()}\n\n**Sources:**\n{urls}"
else: else:
query_response_message = f"**Question:**\n\n`{query.strip()}`\n\n**Google Search Query**\n\n`{refined_text.strip()}`\n\n**Final Answer:**\n\n{response.response.strip()}\n\n**Sources:**\n{urls}" query_response_message = f"**Question:**\n\n`{query.strip()}`\n\n**Google Search Query**\n\n`{refined_text.strip()}`\n\n**Final Answer:**\n\n{response.response.strip()}\n\n**Sources:**\n{urls}"
@ -146,7 +153,9 @@ class SearchService(discord.Cog, name="SearchService"):
# If the response is too long, lets paginate using the discord pagination # If the response is too long, lets paginate using the discord pagination
# helper # helper
embed_pages = await self.paginate_embed(query_response_message, ctx.user, original_link if from_followup else None) embed_pages = await self.paginate_embed(
query_response_message, ctx.user, original_link if from_followup else None
)
paginator = pages.Paginator( paginator = pages.Paginator(
pages=embed_pages, pages=embed_pages,
timeout=None, timeout=None,
@ -173,6 +182,7 @@ class SearchView(discord.ui.View):
self.add_item(RedoButton(self.ctx, self.search_cog)) self.add_item(RedoButton(self.ctx, self.search_cog))
self.add_item(FollowupButton(self.ctx, self.search_cog, self.response_text)) self.add_item(FollowupButton(self.ctx, self.search_cog, self.response_text))
# A view for a follow-up button # A view for a follow-up button
class FollowupButton(discord.ui.Button["SearchView"]): class FollowupButton(discord.ui.Button["SearchView"]):
def __init__(self, ctx, search_cog, response_text): def __init__(self, ctx, search_cog, response_text):
@ -183,8 +193,9 @@ class FollowupButton(discord.ui.Button["SearchView"]):
async def callback(self, interaction: discord.Interaction): async def callback(self, interaction: discord.Interaction):
"""Send the followup modal""" """Send the followup modal"""
await interaction.response.send_modal(modal=FollowupModal(self.ctx, self.search_cog, self.response_text)) await interaction.response.send_modal(
modal=FollowupModal(self.ctx, self.search_cog, self.response_text)
)
# A view for a redo button # A view for a redo button
@ -212,10 +223,13 @@ class RedoButton(discord.ui.Button["SearchView"]):
redo=True, redo=True,
) )
class FollowupData: class FollowupData:
def __init__(self, original_link, followup_question): def __init__(self, original_link, followup_question):
self.original_link = original_link self.original_link = original_link
self.followup_question = followup_question self.followup_question = followup_question
# The modal for following up # The modal for following up
class FollowupModal(discord.ui.Modal): class FollowupModal(discord.ui.Modal):
def __init__(self, ctx, search_cog, response_text) -> None: def __init__(self, ctx, search_cog, response_text) -> None:
@ -237,10 +251,21 @@ class FollowupModal(discord.ui.Modal):
query = self.search_cog.redo_users[self.ctx.user.id].query query = self.search_cog.redo_users[self.ctx.user.id].query
# In the response text, get only the text between "**Final Answer:**" and "**Sources:**" # In the response text, get only the text between "**Final Answer:**" and "**Sources:**"
self.response_text = self.response_text.split("**Final Answer:**")[1].split("**Sources:**")[0] self.response_text = self.response_text.split("**Final Answer:**")[1].split(
"**Sources:**"
)[0]
# Build the context # Build the context
context_text = "Original question: "+query+"\n"+"Answer to original: "+self.response_text+"\n"+"Follow-up question: "+self.children[0].value context_text = (
"Original question: "
+ query
+ "\n"
+ "Answer to original: "
+ self.response_text
+ "\n"
+ "Follow-up question: "
+ self.children[0].value
)
# Get the link of the message that the user interacted on # Get the link of the message that the user interacted on
message_link = f"https://discord.com/channels/{interaction.guild_id}/{interaction.channel_id}/{interaction.message.id}" message_link = f"https://discord.com/channels/{interaction.guild_id}/{interaction.channel_id}/{interaction.message.id}"

@ -566,9 +566,16 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
) )
return return
await self.ask_command(message, prompt, False, None, None, None, None, from_message_context=True ) await self.ask_command(
message,
prompt,
False,
None,
None,
None,
None,
from_message_context=True,
)
def cleanse_response(self, response_text): def cleanse_response(self, response_text):
"""Cleans history tokens from response""" """Cleans history tokens from response"""

Loading…
Cancel
Save