From 5dcd493c67ff863c69c1214f0892a80e4951087e Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 13 Jan 2023 06:40:31 +0000 Subject: [PATCH] Format Python code with psf/black push --- cogs/draw_image_generation.py | 8 +++-- cogs/gpt_3_commands_and_converser.py | 6 ++-- models/openai_model.py | 51 ++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/cogs/draw_image_generation.py b/cogs/draw_image_generation.py index bb39aa5..d073cbf 100644 --- a/cogs/draw_image_generation.py +++ b/cogs/draw_image_generation.py @@ -64,7 +64,9 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"): # Error catching for API errors except aiohttp.ClientResponseError as e: - message = f"The API returned an invalid response: **{e.status}: {e.message}**" + message = ( + f"The API returned an invalid response: **{e.status}: {e.message}**" + ) await ctx.channel.send(message) if not from_context else await ctx.respond( message ) @@ -72,7 +74,9 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"): except ValueError as e: message = f"Error: {e}. Please try again with a different prompt." - await ctx.channel.send( message )if not from_context else await ctx.respond( message ) + await ctx.channel.send(message) if not from_context else await ctx.respond( + message + ) return diff --git a/cogs/gpt_3_commands_and_converser.py b/cogs/gpt_3_commands_and_converser.py index 238c474..7a81d40 100644 --- a/cogs/gpt_3_commands_and_converser.py +++ b/cogs/gpt_3_commands_and_converser.py @@ -1159,14 +1159,15 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"): # Error catching for AIOHTTP Errors except aiohttp.ClientResponseError as e: - message = f"The API returned an invalid response: **{e.status}: {e.message}**" + message = ( + f"The API returned an invalid response: **{e.status}: {e.message}**" + ) if from_context: await ctx.send_followup(message) else: await ctx.reply(message) self.remove_awaiting(ctx.author.id, ctx.channel.id, from_g_command) - # Error catching for OpenAI model value errors except ValueError as e: if from_context: @@ -1175,7 +1176,6 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"): await ctx.reply(e) self.remove_awaiting(ctx.author.id, ctx.channel.id, from_g_command) - # General catch case for everything except Exception: diff --git a/models/openai_model.py b/models/openai_model.py index 46f6f90..dd11546 100644 --- a/models/openai_model.py +++ b/models/openai_model.py @@ -344,8 +344,10 @@ class Model: self._prompt_min_length = value def backoff_handler(details): - print (f"Backing off {details['wait']:0.1f} seconds after {details['tries']} tries calling function {details['target']} | " - f"{details['exception'].status}: {details['exception'].message}") + print( + f"Backing off {details['wait']:0.1f} seconds after {details['tries']} tries calling function {details['target']} | " + f"{details['exception'].status}: {details['exception'].message}" + ) async def valid_text_request(self, response): try: @@ -357,7 +359,14 @@ class Model: + str(response["error"]["message"]) ) - @backoff.on_exception(backoff.expo, aiohttp.ClientResponseError, factor=3, base=5, max_tries=4, on_backoff=backoff_handler) + @backoff.on_exception( + backoff.expo, + aiohttp.ClientResponseError, + factor=3, + base=5, + max_tries=4, + on_backoff=backoff_handler, + ) async def send_embedding_request(self, text, custom_api_key=None): async with aiohttp.ClientSession(raise_for_status=True) as session: payload = { @@ -380,7 +389,14 @@ class Model: traceback.print_exc() return - @backoff.on_exception(backoff.expo, aiohttp.ClientResponseError, factor=3, base=5, max_tries=6, on_backoff=backoff_handler) + @backoff.on_exception( + backoff.expo, + aiohttp.ClientResponseError, + factor=3, + base=5, + max_tries=6, + on_backoff=backoff_handler, + ) async def send_moderations_request(self, text): # Use aiohttp to send the above request: async with aiohttp.ClientSession(raise_for_status=True) as session: @@ -396,7 +412,14 @@ class Model: ) as response: return await response.json() - @backoff.on_exception(backoff.expo, aiohttp.ClientResponseError, factor=3, base=5, max_tries=4, on_backoff=backoff_handler) + @backoff.on_exception( + backoff.expo, + aiohttp.ClientResponseError, + factor=3, + base=5, + max_tries=4, + on_backoff=backoff_handler, + ) async def send_summary_request(self, prompt, custom_api_key=None): """ Sends a summary request to the OpenAI API @@ -438,7 +461,14 @@ class Model: return response - @backoff.on_exception(backoff.expo, aiohttp.ClientResponseError, factor=3, base=5, max_tries=4, on_backoff=backoff_handler) + @backoff.on_exception( + backoff.expo, + aiohttp.ClientResponseError, + factor=3, + base=5, + max_tries=4, + on_backoff=backoff_handler, + ) async def send_request( self, prompt, @@ -521,7 +551,14 @@ class Model: return response - @backoff.on_exception(backoff.expo, aiohttp.ClientResponseError, factor=3, base=5, max_tries=4, on_backoff=backoff_handler) + @backoff.on_exception( + backoff.expo, + aiohttp.ClientResponseError, + factor=3, + base=5, + max_tries=4, + on_backoff=backoff_handler, + ) async def send_image_request( self, ctx, prompt, vary=None, custom_api_key=None ) -> tuple[File, list[Any]]: