Update api_usage.py
Browse files- api_usage.py +51 -1
api_usage.py
CHANGED
|
@@ -7,6 +7,8 @@ from dateutil.relativedelta import relativedelta
|
|
| 7 |
import boto3
|
| 8 |
import botocore.exceptions
|
| 9 |
import concurrent.futures
|
|
|
|
|
|
|
| 10 |
|
| 11 |
BASE_URL = 'https://api.openai.com/v1'
|
| 12 |
GPT_TYPES = ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k", "gpt-4-32k-0314"]
|
|
@@ -206,12 +208,60 @@ def check_key_availability(session, key):
|
|
| 206 |
except Exception as e:
|
| 207 |
return False
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
def check_ant_tier(rpm):
|
| 210 |
if rpm:
|
| 211 |
for k, v in RPM_LIMIT_PER_BUILD_TIER_ANT.items():
|
| 212 |
if int(rpm) == v:
|
| 213 |
return k
|
| 214 |
-
return "
|
| 215 |
|
| 216 |
def check_key_ant_availability(key):
|
| 217 |
try:
|
|
|
|
| 7 |
import boto3
|
| 8 |
import botocore.exceptions
|
| 9 |
import concurrent.futures
|
| 10 |
+
import asyncio
|
| 11 |
+
import aiohttp
|
| 12 |
|
| 13 |
BASE_URL = 'https://api.openai.com/v1'
|
| 14 |
GPT_TYPES = ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k", "gpt-4-32k-0314"]
|
|
|
|
| 208 |
except Exception as e:
|
| 209 |
return False
|
| 210 |
|
| 211 |
+
async def fetch_ant(async_session, json_data):
|
| 212 |
+
url = 'https://api.anthropic.com/v1/messages'
|
| 213 |
+
try:
|
| 214 |
+
async with async_session.post(url=url, json=json_data) as response:
|
| 215 |
+
result = await response.json()
|
| 216 |
+
if response.status == 200:
|
| 217 |
+
return True
|
| 218 |
+
else:
|
| 219 |
+
return False
|
| 220 |
+
except Exception as e:
|
| 221 |
+
return False
|
| 222 |
+
|
| 223 |
+
async def check_ant_rate_limit(key):
|
| 224 |
+
max_requests = 10
|
| 225 |
+
headers = {
|
| 226 |
+
"accept": "application/json",
|
| 227 |
+
"anthropic-version": "2023-06-01",
|
| 228 |
+
"content-type": "application/json",
|
| 229 |
+
"x-api-key": key
|
| 230 |
+
}
|
| 231 |
+
json_data = {
|
| 232 |
+
'model': 'claude-3-haiku-20240307',
|
| 233 |
+
'max_tokens': 1,
|
| 234 |
+
"temperature": 0.1,
|
| 235 |
+
'messages': [
|
| 236 |
+
{
|
| 237 |
+
'role': 'user',
|
| 238 |
+
'content': ',',
|
| 239 |
+
}
|
| 240 |
+
],
|
| 241 |
+
}
|
| 242 |
+
invalid = False
|
| 243 |
+
try:
|
| 244 |
+
async with aiohttp.ClientSession(headers=headers) as async_session:
|
| 245 |
+
tasks = [fetch_ant(async_session, json_data) for _ in range(max_requests)]
|
| 246 |
+
results = await asyncio.gather(*tasks)
|
| 247 |
+
count = 0
|
| 248 |
+
#print(results)
|
| 249 |
+
for result in results:
|
| 250 |
+
if result:
|
| 251 |
+
count+=1
|
| 252 |
+
if count == max_requests:
|
| 253 |
+
return f'{max_requests} or above'
|
| 254 |
+
return count
|
| 255 |
+
except Exception as e:
|
| 256 |
+
#print(e)
|
| 257 |
+
return 0
|
| 258 |
+
|
| 259 |
def check_ant_tier(rpm):
|
| 260 |
if rpm:
|
| 261 |
for k, v in RPM_LIMIT_PER_BUILD_TIER_ANT.items():
|
| 262 |
if int(rpm) == v:
|
| 263 |
return k
|
| 264 |
+
return "Evaluation/Scale"
|
| 265 |
|
| 266 |
def check_key_ant_availability(key):
|
| 267 |
try:
|