mirror of
https://github.com/cunnymessiah/keychecker.git
synced 2026-05-10 18:39:04 -07:00
added async support for various services
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user