-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_direct.py
More file actions
executable file
·128 lines (103 loc) · 3.49 KB
/
test_direct.py
File metadata and controls
executable file
·128 lines (103 loc) · 3.49 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python3
"""
Direct test - paste your API key below and run.
"""
# ============================================
# PASTE YOUR FULL API KEY HERE:
# ============================================
API_KEY = "PASTE_YOUR_KEY_HERE"
# ============================================
import asyncio
import json
import os
import sys
from pathlib import Path
sys.path.insert(0, '.')
from google import genai
from google.genai import types
async def test():
"""Direct LLM test."""
if API_KEY == "PASTE_YOUR_KEY_HERE":
print("\n❌ Please edit test_direct.py and paste your API key at the top")
print(" Look for: API_KEY = \"PASTE_YOUR_KEY_HERE\"")
print(" Replace with your full key: AIzaSyAORX...pJwY\n")
return False
print("\n" + "="*70)
print("Direct Gemini LLM Test")
print("="*70)
print(f"\nUsing API key: {API_KEY[:10]}...{API_KEY[-4:]}\n")
# Load events
events = []
with open("imx500_events_remote.jsonl") as f:
for i, line in enumerate(f):
if i >= 48:
break
event = json.loads(line.strip())
events.append(event)
print(f"Loaded {len(events)} events\n")
# Create client
client = genai.Client(api_key=API_KEY)
# Build prompt
prompt = f"""Analyze these {len(events)} car detection events from an object detection camera.
Events: {len(events)} car detections over 60 minutes
Average confidence: 0.52
Please provide:
1. A brief summary (2-3 sentences)
2. Key insights
3. Any recommendations
"""
# Try different model names
models_to_try = [
"gemini-1.5-flash",
"models/gemini-1.5-flash",
"gemini-1.5-pro",
"models/gemini-1.5-pro",
"gemini-pro",
"models/gemini-pro",
]
for model in models_to_try:
print(f"🔄 Trying: {model}")
try:
response = client.models.generate_content(
model=model,
contents=prompt,
config=types.GenerateContentConfig(
temperature=0.3,
max_output_tokens=500
)
)
print(f"✅ SUCCESS with {model}!\n")
print("="*70)
print("LLM SUMMARY")
print("="*70)
print()
print(response.text)
print()
print("="*70)
print(f"✅ Model '{model}' works!")
print("="*70)
return True
except Exception as e:
error_msg = str(e)
if "404" in error_msg:
print(f" ❌ Not found")
elif "429" in error_msg:
print(f" ❌ Quota exceeded")
elif "403" in error_msg:
print(f" ❌ Permission denied")
else:
print(f" ❌ {error_msg[:60]}")
print("\n❌ All models failed. Here's what to do:")
print("\n1. Check your API key is correct")
print("2. Visit https://aistudio.google.com/app/prompts/new_chat")
print("3. Try a test prompt there to verify your key works")
print("4. Check quota: https://console.cloud.google.com/apis/api/generativelanguage.googleapis.com/quotas")
return False
if __name__ == "__main__":
success = asyncio.run(test())
if success:
print("\n🎉 SUCCESS! Your API key works!")
print("\nNow you can run:")
print(f" export GEMINI_API_KEY='{API_KEY}'")
print(" python src/agents/adk_enhanced/coordinator.py")
sys.exit(0 if success else 1)