-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_models.py
More file actions
24 lines (21 loc) · 752 Bytes
/
Copy pathtest_models.py
File metadata and controls
24 lines (21 loc) · 752 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
import urllib.request
import os
import json
api_key = os.environ.get("GOOGLE_API_KEY")
if not api_key:
# try reading .env
with open(".env", "r") as f:
for line in f:
if line.startswith("GOOGLE_API_KEY="):
api_key = line.strip().split("=", 1)[1].strip('"\'')
break
url = f"https://generativelanguage.googleapis.com/v1beta/models?key={api_key}"
req = urllib.request.Request(url)
try:
with urllib.request.urlopen(req) as response:
data = json.loads(response.read().decode())
for model in data.get('models', []):
if 'embed' in model.get('supportedGenerationMethods', []):
print(model['name'])
except Exception as e:
print(f"Error: {e}")