superdup95
commited on
Commit
•
a7dd181
1
Parent(s):
45a78d1
Update api_usage.py
Browse files- api_usage.py +12 -5
api_usage.py
CHANGED
@@ -377,7 +377,7 @@ def check_mistral_quota(key):
|
|
377 |
url = 'https://api.mistral.ai/v1/chat/completions'
|
378 |
headers = {'Authorization': f'Bearer {key}'}
|
379 |
data = {
|
380 |
-
'model': 'mistral-
|
381 |
'messages': [{ "role": "user", "content": "" }],
|
382 |
'max_tokens': -1
|
383 |
}
|
@@ -390,23 +390,30 @@ def check_mistral_quota(key):
|
|
390 |
|
391 |
def check_key_replicate_availability(key):
|
392 |
try:
|
|
|
|
|
393 |
url = 'https://api.replicate.com/v1/account'
|
394 |
headers = {'Authorization': f'Token {key}'}
|
395 |
|
396 |
-
rq =
|
397 |
info = rq.json()
|
398 |
if rq.status_code == 401:
|
399 |
return False, "", ""
|
400 |
|
401 |
url = 'https://api.replicate.com/v1/hardware'
|
402 |
-
rq =
|
403 |
result = rq.json()
|
404 |
hardware = []
|
405 |
if result:
|
406 |
hardware = [res['name'] for res in result]
|
407 |
-
|
|
|
|
|
|
|
|
|
|
|
408 |
except:
|
409 |
-
return "Unknown", "", "Error while making request"
|
410 |
|
411 |
def check_key_aws_availability(key):
|
412 |
access_id = key.split(':')[0]
|
|
|
377 |
url = 'https://api.mistral.ai/v1/chat/completions'
|
378 |
headers = {'Authorization': f'Bearer {key}'}
|
379 |
data = {
|
380 |
+
'model': 'mistral-small-latest',
|
381 |
'messages': [{ "role": "user", "content": "" }],
|
382 |
'max_tokens': -1
|
383 |
}
|
|
|
390 |
|
391 |
def check_key_replicate_availability(key):
|
392 |
try:
|
393 |
+
quota = False
|
394 |
+
s = requests.Session()
|
395 |
url = 'https://api.replicate.com/v1/account'
|
396 |
headers = {'Authorization': f'Token {key}'}
|
397 |
|
398 |
+
rq = s.get(url, headers=headers)
|
399 |
info = rq.json()
|
400 |
if rq.status_code == 401:
|
401 |
return False, "", ""
|
402 |
|
403 |
url = 'https://api.replicate.com/v1/hardware'
|
404 |
+
rq = s.get(url, headers=headers)
|
405 |
result = rq.json()
|
406 |
hardware = []
|
407 |
if result:
|
408 |
hardware = [res['name'] for res in result]
|
409 |
+
url = 'https://api.replicate.com/v1/predictions'
|
410 |
+
data = {"version": "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa", "input": {}}
|
411 |
+
rq = s.post(url, headers=headers, json=data)
|
412 |
+
if rq.status_code == 422: # 422 have quota, 402 out of quota
|
413 |
+
quota = True
|
414 |
+
return True, info, quota, hardware
|
415 |
except:
|
416 |
+
return "Unknown", "", "", "Error while making request"
|
417 |
|
418 |
def check_key_aws_availability(key):
|
419 |
access_id = key.split(':')[0]
|