From f165610b7005656491d801116232e5bc05134e7b Mon Sep 17 00:00:00 2001 From: Paillat Date: Mon, 4 Sep 2023 12:45:52 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(openaicaller.py):=20remove?= =?UTF-8?q?=20unnecessary=20sleep=20statements=20to=20improve=20code=20rea?= =?UTF-8?q?dability=20and=20performance=20=F0=9F=94=8A=20refactor(openaica?= =?UTF-8?q?ller.py):=20add=20print=20statements=20to=20indicate=20when=20O?= =?UTF-8?q?penAI=20API=20is=20being=20called=20and=20when=20retries=20are?= =?UTF-8?q?=20being=20made=20for=20better=20debugging=20and=20monitoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/openaicaller.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/openaicaller.py b/src/utils/openaicaller.py index f332262..62dc516 100644 --- a/src/utils/openaicaller.py +++ b/src/utils/openaicaller.py @@ -136,8 +136,10 @@ class openai_caller: async def retryal_call(self, recall_func, callable): i = 0 response = None + print(f"{bcolors.BOLD}Calling OpenAI API...{bcolors.ENDC}") while i < 10: try: + print(f"{bcolors.BOLD}Retryal {i+1}...{bcolors.ENDC}") response = await callable() return response except APIError as e: @@ -147,21 +149,18 @@ class openai_caller: await recall_func( "`An APIError occurred. This is not your fault, it is OpenAI's fault. We apologize for the inconvenience. Retrying...`" ) - await asyncio.sleep(5) i += 1 except Timeout as e: print( f"\n\n{bcolors.BOLD}{bcolors.WARNING}The request timed out. Retrying...{bcolors.ENDC}" ) await recall_func("`The request timed out. Retrying...`") - await asyncio.sleep(5) i += 1 except RateLimitError as e: print( f"\n\n{bcolors.BOLD}{bcolors.WARNING}RateLimitError. You are being rate limited. Retrying...{bcolors.ENDC}" ) await recall_func("`You are being rate limited. Retrying...`") - await asyncio.sleep(5) i += 1 except APIConnectionError as e: print( @@ -185,7 +184,6 @@ class openai_caller: f"\n\n{bcolors.BOLD}{bcolors.WARNING}ServiceUnavailableError. The OpenAI API is not responding. Retrying...{bcolors.ENDC}" ) await recall_func("`The OpenAI API is not responding. Retrying...`") - await asyncio.sleep(5) await recall_func() i += 1 finally: