mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 09:16:19 +00:00
🔧 chore(openaicaller.py): remove unnecessary sleep statements to improve code readability and performance
🔊 refactor(openaicaller.py): add print statements to indicate when OpenAI API is being called and when retries are being made for better debugging and monitoring
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user