-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_query.py
More file actions
68 lines (55 loc) · 2.53 KB
/
test_query.py
File metadata and controls
68 lines (55 loc) · 2.53 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
#!/usr/bin/env python3
"""
Test script — queries all 3 agents in one shot using GPS coordinates.
The agent identifies the location, then returns nearby restaurants and HMDA data.
Usage:
python test_query.py # uses default coordinates (Atlantic Ave, Brooklyn)
python test_query.py 40.7580 -73.9855 # custom lat/lon
python test_query.py 40.7580 -73.9855 http://localhost:8080 # custom endpoint
"""
import json
import sys
import requests
# ── Config ────────────────────────────────────────────────────────────────────
DEFAULT_LAT = 40.6782 # Atlantic Ave, Brooklyn
DEFAULT_LON = -73.9442
DEFAULT_ENDPOINT = "http://localhost:8080"
lat = float(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT_LAT
lon = float(sys.argv[2]) if len(sys.argv) > 2 else DEFAULT_LON
base = sys.argv[3] if len(sys.argv) > 3 else DEFAULT_ENDPOINT
# ── Query ─────────────────────────────────────────────────────────────────────
query = (
f"My GPS coordinates are latitude {lat}, longitude {lon}. "
"What street am I on? "
"Find A-grade restaurants nearby. "
"Also give me the mortgage denial rates by race for this area."
)
print(f"Endpoint : {base}/run")
print(f"Location : {lat}, {lon}")
print(f"Query : {query}\n")
print("─" * 60)
# ── Request ───────────────────────────────────────────────────────────────────
try:
response = requests.post(
f"{base}/run",
json={"message": query},
timeout=60,
)
response.raise_for_status()
data = response.json()
# ADK responses vary slightly by version — handle both shapes
answer = (
data.get("response")
or data.get("output")
or data.get("answer")
or json.dumps(data, indent=2)
)
print(answer)
except requests.exceptions.ConnectionError:
print(f"ERROR: Could not connect to {base}")
print("Make sure the agent server is running: adk api_server --port 8080 agents")
except requests.exceptions.Timeout:
print("ERROR: Request timed out (>60s). The agent may still be processing.")
except requests.exceptions.HTTPError as e:
print(f"ERROR: {e}")
print(response.text)