Format Python code with psf/black push

github-actions 2 years ago
parent b9e4eae8d3
commit f6f0410f9d

@ -79,7 +79,9 @@ class SearchService(discord.Cog, name="SearchService"):
await ctx.defer() await ctx.defer()
try: 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: except ValueError:
await ctx.respond( await ctx.respond(
"The Google Search API returned an error. Check the console for more details.", "The Google Search API returned an error. Check the console for more details.",

@ -216,14 +216,15 @@ class Index_handler:
return documents return documents
async def index_webpage(self, url, embed_model) -> GPTSimpleVectorIndex: async def index_webpage(self, url, embed_model) -> GPTSimpleVectorIndex:
# First try to connect to the URL to see if we can even reach it. # First try to connect to the URL to see if we can even reach it.
try: try:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=5) as response: 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 # 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]: 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: else:
# Detect if the link is a PDF, if it is, we load it differently # Detect if the link is a PDF, if it is, we load it differently
if response.headers["Content-Type"] == "application/pdf": if response.headers["Content-Type"] == "application/pdf":

@ -56,7 +56,9 @@ class Search:
def build_search_refined_embed(self, refined_query): def build_search_refined_embed(self, refined_query):
embed = discord.Embed( embed = discord.Embed(
title="Searching the web...", 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, color=0x00FF00,
) )
return embed return embed
@ -64,8 +66,10 @@ class Search:
def build_search_links_retrieved_embed(self, refined_query): def build_search_links_retrieved_embed(self, refined_query):
embed = discord.Embed( embed = discord.Embed(
title="Searching the web...", title="Searching the web...",
description="Refined query: " + refined_query + "\n\nRetrieved links from Google\n\n" description="Refined query: "
"Retrieving webpages...", + refined_query
+ "\n\nRetrieved links from Google\n\n"
"Retrieving webpages...",
color=0x00FF00, color=0x00FF00,
) )
return embed return embed
@ -73,9 +77,11 @@ class Search:
def build_search_webpages_retrieved_embed(self, refined_query): def build_search_webpages_retrieved_embed(self, refined_query):
embed = discord.Embed( embed = discord.Embed(
title="Searching the web...", title="Searching the web...",
description="Refined query: " + refined_query + "\n\nRetrieved links from Google\n\n" description="Refined query: "
"Retrieved webpages\n\n" + refined_query
"Indexing...", + "\n\nRetrieved links from Google\n\n"
"Retrieved webpages\n\n"
"Indexing...",
color=0x00FF00, color=0x00FF00,
) )
return embed return embed
@ -83,10 +89,12 @@ class Search:
def build_search_indexed_embed(self, refined_query): def build_search_indexed_embed(self, refined_query):
embed = discord.Embed( embed = discord.Embed(
title="Searching the web...", title="Searching the web...",
description="Refined query: " + refined_query + "\n\nRetrieved links from Google\n\n" description="Refined query: "
"Retrieved webpages\n\n" + refined_query
"Indexed\n\n" + "\n\nRetrieved links from Google\n\n"
"Thinking about your question...", "Retrieved webpages\n\n"
"Indexed\n\n"
"Thinking about your question...",
color=0x00FF00, color=0x00FF00,
) )
return embed return embed
@ -150,7 +158,9 @@ class Search:
traceback.print_exc() traceback.print_exc()
pass 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 DEFAULT_SEARCH_NODES = 1
if not user_api_key: if not user_api_key:
os.environ["OPENAI_API_KEY"] = self.openai_key os.environ["OPENAI_API_KEY"] = self.openai_key
@ -158,7 +168,9 @@ class Search:
os.environ["OPENAI_API_KEY"] = user_api_key os.environ["OPENAI_API_KEY"] = user_api_key
if ctx: 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")) llm_predictor = LLMPredictor(llm=OpenAI(model_name="text-davinci-003"))
try: try:
@ -180,8 +192,9 @@ class Search:
query_refined_text = query query_refined_text = query
if ctx: 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 # Get the links for the query
links, all_links = await self.get_links( links, all_links = await self.get_links(
@ -189,7 +202,10 @@ class Search:
) )
if ctx: 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: if all_links is None:
raise ValueError("The Google Search API returned an error.") raise ValueError("The Google Search API returned an error.")
@ -252,7 +268,10 @@ class Search:
traceback.print_exc() traceback.print_exc()
if ctx: 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() embedding_model = OpenAIEmbedding()
@ -261,7 +280,9 @@ class Search:
) )
if ctx: 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( await self.usage_service.update_usage(
embedding_model.last_token_usage, embeddings=True embedding_model.last_token_usage, embeddings=True

Loading…
Cancel
Save