-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_models.py
More file actions
28 lines (25 loc) · 971 Bytes
/
list_models.py
File metadata and controls
28 lines (25 loc) · 971 Bytes
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
import subprocess
import requests
token = subprocess.run([r'C:\Program Files\GitHub CLI\gh.exe', 'auth', 'token'], capture_output=True, text=True).stdout.strip()
response = requests.get(
'https://models.inference.ai.azure.com/models',
headers={'Authorization': f'Bearer {token}'}
)
if response.status_code == 200:
data = response.json()
print('Available models:')
if isinstance(data, list):
for m in data:
if isinstance(m, dict):
model_id = m.get('id') or m.get('name') or str(m)
print(f" - {model_id}")
else:
print(f" - {m}")
elif isinstance(data, dict):
models = data.get('data') or data.get('models') or [data]
for m in models:
if isinstance(m, dict):
model_id = m.get('id') or m.get('name') or str(m)
print(f" - {model_id}")
else:
print(f'Error {response.status_code}: {response.text[:500]}')