-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_models.py
62 lines (53 loc) · 2.07 KB
/
list_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import requests
import json
from azure.identity import DefaultAzureCredential
# create array of azure regions
regions = [
"australiaeast",
"brazilsouth",
"canadacentral",
"canadaeast",
"eastus",
"eastus2",
"francecentral",
"germanywestcentral",
"italynorth",
"japaneast",
"koreacentral",
"northcentralus",
"norwayeast",
"polandcentral",
"southafricanorth",
"southcentralus",
"southindia",
"swedencentral",
"switzerlandnorth",
"switzerlandwest",
"uksouth",
"westeurope",
"westus",
"westus3" ]
# get the subscription ID from the environment
sub_id = os.environ.get("AZURE_SUBSCRIPTION_ID")
if not sub_id:
raise Exception("AZURE_SUBSCRIPTION_ID is not set")
# get the default credential based on the environment variables
credential = DefaultAzureCredential()
print(f"{'Region':<20} {'Model':<35} {'Quota Used (K)':<15} {'Total Quota (K)':<15}")
for region in regions:
# api URL is based on the subscription ID and region
url = f"https://management.azure.com/subscriptions/{sub_id}/providers/Microsoft.CognitiveServices/locations/{region}/usages?api-version=2023-05-01"
api_call_headers = {'Authorization': 'Bearer ' + credential.get_token('https://management.azure.com/.default').token}
api_call_response = requests.get(url, headers=api_call_headers)
if api_call_response.status_code != 200:
print(f"Error: {api_call_response.text}")
exit()
model_list = json.loads(api_call_response.text)['value']
#print(json.dumps(response_obj, indent=4))
#print(f"Quota usage in {region.upper()}:")
for sku in model_list:
model_name = sku['name']['value']
# ignore the AccountCount, FineTuned, and ProvisionedManaged quota
if "AccountCount" not in model_name and "ProvisionedManaged" not in model_name and "FineTuned" not in model_name and "finetune" not in model_name and "fine-tune" not in model_name:
print(f"{region:<20} {model_name.replace('OpenAI.Standard.', ''):<35} {sku['currentValue']:<15} {sku['limit']:<15}")