From b3416a6e496a8d4f15a34807ccdd29b0f5e0ceed Mon Sep 17 00:00:00 2001 From: based Date: Wed, 24 Jan 2024 07:07:55 +1000 Subject: [PATCH] bug fixes --- OpenAI.py | 20 +++++++++++--------- main.py | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/OpenAI.py b/OpenAI.py index 344d9e2..cb0614e 100644 --- a/OpenAI.py +++ b/OpenAI.py @@ -55,16 +55,18 @@ async def get_oai_key_tier(key: APIKey, session): if key.trial: return 'Free' tts_object = {"model": "tts-1-hd", "input": "", "voice": "alloy"} - async with session.post(f'{oai_api_url}/audio/speech', - headers={'Authorization': f'Bearer {key.api_key}', 'accept': 'application/json'}, - json=tts_object) as response: - if response.status in [400, 429]: - try: - return oai_tiers[int(response.headers.get("x-ratelimit-limit-requests"))] - except KeyError: + for _ in range(3): # we'll give it 3 shots if oai decides to shid itself. + async with session.post(f'{oai_api_url}/audio/speech', + headers={'Authorization': f'Bearer {key.api_key}', 'accept': 'application/json'}, + json=tts_object) as response: + if response.status in [400, 429]: + try: + return oai_tiers[int(response.headers.get("x-ratelimit-limit-requests"))] + except (KeyError, TypeError, ValueError): + continue + else: return - else: - return + return async def get_oai_org(key: APIKey, session): diff --git a/main.py b/main.py index 5733830..8a67b50 100644 --- a/main.py +++ b/main.py @@ -93,7 +93,7 @@ async def validate_makersuite(key: APIKey, sem): api_keys.add(key) -async def validate_aws(key: APIKey): +def validate_aws(key: APIKey): if check_aws(key) is None: return api_keys.add(key) @@ -106,7 +106,7 @@ async def validate_azure(key: APIKey, sem): api_keys.add(key) -async def validate_vertexai(key: APIKey): +def validate_vertexai(key: APIKey): if check_vertexai(key) is None: return api_keys.add(key)