-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_gemini.py
More file actions
63 lines (52 loc) · 2.2 KB
/
verify_gemini.py
File metadata and controls
63 lines (52 loc) · 2.2 KB
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
63
import os
import ecologits
from ecologits import EcoLogits
try:
from google import genai
GOOGLE_GENAI_AVAILABLE = True
except ImportError:
GOOGLE_GENAI_AVAILABLE = False
def verify():
print(f"EcoLogits version: {ecologits.__version__}")
if not GOOGLE_GENAI_AVAILABLE:
print("ERROR: google-genai is not installed.")
return
print("google-genai is installed.")
# Initialize EcoLogits
EcoLogits.init(providers=["google_genai"])
print("EcoLogits initialized with google_genai provider.")
api_key = os.environ.get("GEMINI_API_KEY")
if not api_key or api_key == "<GEMINI_API_KEY>":
print("WARNING: GEMINI_API_KEY not found in environment. Skipping live test.")
return
print("GEMINI_API_KEY found. Running live test...")
client = genai.Client(api_key=api_key)
models_to_try = ["gemini-3-flash-preview", "gemini-2.0-flash"]
for model_name in models_to_try:
print(f"Testing model: {model_name}...")
try:
response = client.models.generate_content(
model=model_name,
contents="Say 'EcoLogits is ready!'"
)
print(f"Response received successfully from {model_name}.")
if hasattr(response, 'impacts'):
print(f"Impacts: {response.impacts}")
try:
print(f"Energy: {response.impacts.energy.value.mean} kWh")
except AttributeError:
print(f"Impacts summary: {response.impacts}")
print(f"SUCCESS: EcoLogits correctly tracked the impact for {model_name}.")
return # Exit after first successful call
else:
print(f"FAILURE: Response object from {model_name} does not have 'impacts' attribute.")
except Exception as e:
if "429" in str(e) or "RESOURCE_EXHAUSTED" in str(e):
print(f"QUOTA EXHAUSTED for {model_name}. Attempting fallback...")
continue
else:
print(f"ERROR during test with {model_name}: {e}")
break
print("All attempts failed or quota reached for all models.")
if __name__ == "__main__":
verify()