added async support for various services

This commit is contained in:
based
2024-01-18 09:14:54 +10:00
parent 5baed1e942
commit 22de3b0754
8 changed files with 159 additions and 150 deletions
+9 -9
View File
@@ -1,9 +1,8 @@
import requests
import aiohttp
import APIKey
def check_ai21(key: APIKey):
async def check_ai21(key: APIKey):
url = "https://api.ai21.com/studio/v1/j2-light/complete"
payload = {
@@ -16,14 +15,15 @@ def check_ai21(key: APIKey):
"Authorization": f"Bearer {key.api_key}"
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code not in [200, 402]:
return
async with aiohttp.ClientSession() as session:
async with session.post(url, json=payload, headers=headers) as response:
if response.status not in [200, 402]:
return
if response.status_code == 402: # unsure if this error code also applies to empty keys
key.trial_elapsed = True
if response.status == 402: # unsure if this error code also applies to empty keys
key.trial_elapsed = True
return True
return True
def pretty_print_ai21_keys(keys):