Format Python code with psf/black push

github-actions 1 year ago
parent b28795c69d
commit 5eedc459fa

@ -14,6 +14,7 @@ ALLOWED_GUILDS = EnvService.get_allowed_guilds()
USER_INPUT_API_KEYS = EnvService.get_user_input_api_keys()
USER_KEY_DB = EnvService.get_api_db()
class RedoSearchUser:
def __init__(self, ctx, query, search_scope, nodes):
self.ctx = ctx
@ -21,6 +22,7 @@ class RedoSearchUser:
self.search_scope = search_scope
self.nodes = nodes
class SearchService(discord.Cog, name="SearchService"):
"""Cog containing translation commands and retrieval of translation services"""
@ -141,5 +143,13 @@ class RedoButton(discord.ui.View):
@discord.ui.button(label="Redo", style=discord.ButtonStyle.danger)
async def redo(self, button: discord.ui.Button, interaction: discord.Interaction):
"""Redo the translation"""
await interaction.response.send_message("Redoing search...", ephemeral=True, delete_after=15)
await self.search_cog.search_command(self.search_cog.redo_users[self.ctx.user.id].ctx, self.search_cog.redo_users[self.ctx.user.id].query, self.search_cog.redo_users[self.ctx.user.id].search_scope, self.search_cog.redo_users[self.ctx.user.id].nodes, redo=True)
await interaction.response.send_message(
"Redoing search...", ephemeral=True, delete_after=15
)
await self.search_cog.search_command(
self.search_cog.redo_users[self.ctx.user.id].ctx,
self.search_cog.redo_users[self.ctx.user.id].query,
self.search_cog.redo_users[self.ctx.user.id].search_scope,
self.search_cog.redo_users[self.ctx.user.id].nodes,
redo=True,
)

@ -695,7 +695,7 @@ class ComposeModal(discord.ui.View):
# Map everything into the short to long cache
for index in self.indexes:
if len(index) > 94:
index_name = index[:94] + "-" + str(random.randint(0000,9999))
index_name = index[:94] + "-" + str(random.randint(0000, 9999))
SHORT_TO_LONG_CACHE[index_name] = index
else:
SHORT_TO_LONG_CACHE[index[:99]] = index
@ -711,7 +711,9 @@ class ComposeModal(discord.ui.View):
self.index_select = discord.ui.Select(
placeholder="Select index(es) to compose",
options=[
discord.SelectOption(label=LONG_TO_SHORT_CACHE[index], value=LONG_TO_SHORT_CACHE[index])
discord.SelectOption(
label=LONG_TO_SHORT_CACHE[index], value=LONG_TO_SHORT_CACHE[index]
)
for index in self.indexes
][0:25],
max_values=len(self.indexes) if len(self.indexes) < 25 else 25,
@ -728,7 +730,10 @@ class ComposeModal(discord.ui.View):
discord.ui.Select(
placeholder="Select index(es) to compose",
options=[
discord.SelectOption(label=LONG_TO_SHORT_CACHE[index], value=LONG_TO_SHORT_CACHE[index])
discord.SelectOption(
label=LONG_TO_SHORT_CACHE[index],
value=LONG_TO_SHORT_CACHE[index],
)
for index in self.indexes
][i : i + 25],
max_values=len(self.indexes[i : i + 25]),

@ -160,7 +160,13 @@ class Search:
pass
async def search(
self, ctx: discord.ApplicationContext, query, user_api_key, search_scope, nodes, redo=None
self,
ctx: discord.ApplicationContext,
query,
user_api_key,
search_scope,
nodes,
redo=None,
):
DEFAULT_SEARCH_NODES = 1
if not user_api_key:
@ -169,9 +175,11 @@ class Search:
os.environ["OPENAI_API_KEY"] = user_api_key
if ctx:
in_progress_message = await ctx.respond(
embed=self.build_search_started_embed()
) if not redo else await ctx.channel.send(embed=self.build_search_started_embed())
in_progress_message = (
await ctx.respond(embed=self.build_search_started_embed())
if not redo
else await ctx.channel.send(embed=self.build_search_started_embed())
)
llm_predictor = LLMPredictor(llm=OpenAI(model_name="text-davinci-003"))
try:
@ -181,7 +189,8 @@ class Search:
# Refine a query to send to google custom search API
query_refined = llm_predictor_presearch.generate(
prompts=[f"You are to be given a search query for google. Change the query such that putting it into the Google Custom Search API will return the most relevant websites to assist in answering the original query. If the original query is asking about something that is relevant to the current day, insert the current_date into the refined query. If the user is asking about something that may be relevant to the current month, insert the current year and month into the refined query, if the query is asking for something relevant to the current year, insert the current year into the refined query. There is no need to insert a day, month, or year for queries that purely ask about facts and about things that don't have much time-relevance. The current_date is {str(datetime.now().date())}. Do not insert the current_date if not neccessary. Respond with only the refined query for the original query. Dont use punctuation or quotation marks.\n\nExamples:\n---\nOriginal Query: Who is Harald Baldr?\nRefined Query: Harald Baldr biography\n---\nOriginal Query: What happened today with the Ohio train derailment?\nRefined Query: Ohio train derailment details {str(datetime.now().date())}\n---\nOriginal Query: Is copper in drinking water bad for you?\nRefined Query: copper in drinking water adverse effects\n---\nOriginal Query: What's the current time in Mississauga?\nRefined Query: current time Mississauga\nNow, refine the user input query.\nOriginal Query: {query}\nRefined Query:"
prompts=[
f"You are to be given a search query for google. Change the query such that putting it into the Google Custom Search API will return the most relevant websites to assist in answering the original query. If the original query is asking about something that is relevant to the current day, insert the current_date into the refined query. If the user is asking about something that may be relevant to the current month, insert the current year and month into the refined query, if the query is asking for something relevant to the current year, insert the current year into the refined query. There is no need to insert a day, month, or year for queries that purely ask about facts and about things that don't have much time-relevance. The current_date is {str(datetime.now().date())}. Do not insert the current_date if not neccessary. Respond with only the refined query for the original query. Dont use punctuation or quotation marks.\n\nExamples:\n---\nOriginal Query: Who is Harald Baldr?\nRefined Query: Harald Baldr biography\n---\nOriginal Query: What happened today with the Ohio train derailment?\nRefined Query: Ohio train derailment details {str(datetime.now().date())}\n---\nOriginal Query: Is copper in drinking water bad for you?\nRefined Query: copper in drinking water adverse effects\n---\nOriginal Query: What's the current time in Mississauga?\nRefined Query: current time Mississauga\nNow, refine the user input query.\nOriginal Query: {query}\nRefined Query:"
]
)
query_refined_text = query_refined.generations[0][0].text

Loading…
Cancel
Save