From f6f0410f9d609d0c47c3c696b52f679529859a43 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 8 Feb 2023 21:30:13 +0000 Subject: [PATCH] Format Python code with psf/black push --- cogs/search_service_cog.py | 4 ++- models/index_model.py | 5 ++-- models/search_model.py | 55 ++++++++++++++++++++++++++------------ 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/cogs/search_service_cog.py b/cogs/search_service_cog.py index ca5a244..876d2f7 100644 --- a/cogs/search_service_cog.py +++ b/cogs/search_service_cog.py @@ -79,7 +79,9 @@ class SearchService(discord.Cog, name="SearchService"): await ctx.defer() try: - response = await self.model.search(ctx, query, user_api_key, search_scope, nodes) + response = await self.model.search( + ctx, query, user_api_key, search_scope, nodes + ) except ValueError: await ctx.respond( "The Google Search API returned an error. Check the console for more details.", diff --git a/models/index_model.py b/models/index_model.py index c66200f..47cd5fd 100644 --- a/models/index_model.py +++ b/models/index_model.py @@ -216,14 +216,15 @@ class Index_handler: return documents async def index_webpage(self, url, embed_model) -> GPTSimpleVectorIndex: - # First try to connect to the URL to see if we can even reach it. try: async with aiohttp.ClientSession() as session: async with session.get(url, timeout=5) as response: # Add another entry to links from all_links if the link is not already in it to compensate for the failed request if response.status not in [200, 203, 202, 204]: - raise ValueError("Invalid URL or could not connect to the provided URL.") + raise ValueError( + "Invalid URL or could not connect to the provided URL." + ) else: # Detect if the link is a PDF, if it is, we load it differently if response.headers["Content-Type"] == "application/pdf": diff --git a/models/search_model.py b/models/search_model.py index f7cc404..482e615 100644 --- a/models/search_model.py +++ b/models/search_model.py @@ -56,7 +56,9 @@ class Search: def build_search_refined_embed(self, refined_query): embed = discord.Embed( title="Searching the web...", - description="Refined query: " + refined_query + "\n\nRetrieving links from google...", + description="Refined query: " + + refined_query + + "\n\nRetrieving links from google...", color=0x00FF00, ) return embed @@ -64,8 +66,10 @@ class Search: def build_search_links_retrieved_embed(self, refined_query): embed = discord.Embed( title="Searching the web...", - description="Refined query: " + refined_query + "\n\nRetrieved links from Google\n\n" - "Retrieving webpages...", + description="Refined query: " + + refined_query + + "\n\nRetrieved links from Google\n\n" + "Retrieving webpages...", color=0x00FF00, ) return embed @@ -73,9 +77,11 @@ class Search: def build_search_webpages_retrieved_embed(self, refined_query): embed = discord.Embed( title="Searching the web...", - description="Refined query: " + refined_query + "\n\nRetrieved links from Google\n\n" - "Retrieved webpages\n\n" - "Indexing...", + description="Refined query: " + + refined_query + + "\n\nRetrieved links from Google\n\n" + "Retrieved webpages\n\n" + "Indexing...", color=0x00FF00, ) return embed @@ -83,10 +89,12 @@ class Search: def build_search_indexed_embed(self, refined_query): embed = discord.Embed( title="Searching the web...", - description="Refined query: " + refined_query + "\n\nRetrieved links from Google\n\n" - "Retrieved webpages\n\n" - "Indexed\n\n" - "Thinking about your question...", + description="Refined query: " + + refined_query + + "\n\nRetrieved links from Google\n\n" + "Retrieved webpages\n\n" + "Indexed\n\n" + "Thinking about your question...", color=0x00FF00, ) return embed @@ -150,7 +158,9 @@ class Search: traceback.print_exc() pass - async def search(self,ctx: discord.ApplicationContext, query, user_api_key, search_scope, nodes): + async def search( + self, ctx: discord.ApplicationContext, query, user_api_key, search_scope, nodes + ): DEFAULT_SEARCH_NODES = 1 if not user_api_key: os.environ["OPENAI_API_KEY"] = self.openai_key @@ -158,7 +168,9 @@ class Search: os.environ["OPENAI_API_KEY"] = user_api_key if ctx: - in_progress_message = await ctx.respond(embed=self.build_search_started_embed()) + in_progress_message = await ctx.respond( + embed=self.build_search_started_embed() + ) llm_predictor = LLMPredictor(llm=OpenAI(model_name="text-davinci-003")) try: @@ -180,8 +192,9 @@ class Search: query_refined_text = query if ctx: - await self.try_edit(in_progress_message,self.build_search_refined_embed(query_refined_text)) - + await self.try_edit( + in_progress_message, self.build_search_refined_embed(query_refined_text) + ) # Get the links for the query links, all_links = await self.get_links( @@ -189,7 +202,10 @@ class Search: ) if ctx: - await self.try_edit(in_progress_message,self.build_search_links_retrieved_embed(query_refined_text)) + await self.try_edit( + in_progress_message, + self.build_search_links_retrieved_embed(query_refined_text), + ) if all_links is None: raise ValueError("The Google Search API returned an error.") @@ -252,7 +268,10 @@ class Search: traceback.print_exc() if ctx: - await self.try_edit(in_progress_message,self.build_search_webpages_retrieved_embed(query_refined_text)) + await self.try_edit( + in_progress_message, + self.build_search_webpages_retrieved_embed(query_refined_text), + ) embedding_model = OpenAIEmbedding() @@ -261,7 +280,9 @@ class Search: ) if ctx: - await self.try_edit(in_progress_message,self.build_search_indexed_embed(query_refined_text)) + await self.try_edit( + in_progress_message, self.build_search_indexed_embed(query_refined_text) + ) await self.usage_service.update_usage( embedding_model.last_token_usage, embeddings=True