fix: migrate Places and Routes to new GCP APIs
Switch from legacy Places textsearch and Directions APIs (disabled on this project) to Places API (New) and Routes API (New). Both places.py and the assistant's _places_search helper updated. Also fixes uid() recursive self-call in trips page and adds Places API response logging.
This commit is contained in:
@@ -74,30 +74,38 @@ _TOOLS = [
|
||||
]
|
||||
|
||||
|
||||
_PLACES_SEARCH_URL = "https://places.googleapis.com/v1/places:searchText"
|
||||
_PLACES_FIELDS = "places.id,places.displayName,places.formattedAddress,places.rating,places.googleMapsUri"
|
||||
|
||||
|
||||
async def _places_search(query: str, near: str) -> list[dict]:
|
||||
if not settings.google_maps_api_key:
|
||||
return []
|
||||
full_query = f"{query} {near}".strip()
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=8) as client:
|
||||
r = await client.get(
|
||||
"https://maps.googleapis.com/maps/api/place/textsearch/json",
|
||||
params={"query": f"{query} {near}".strip(), "key": settings.google_maps_api_key},
|
||||
r = await client.post(
|
||||
_PLACES_SEARCH_URL,
|
||||
json={"textQuery": full_query},
|
||||
headers={
|
||||
"X-Goog-Api-Key": settings.google_maps_api_key,
|
||||
"X-Goog-FieldMask": _PLACES_FIELDS,
|
||||
},
|
||||
)
|
||||
data = r.json()
|
||||
status = data.get("status")
|
||||
results = data.get("results", [])
|
||||
logger.info(f"Places search '{query} {near}': status={status}, count={len(results)}")
|
||||
if status not in ("OK", "ZERO_RESULTS"):
|
||||
logger.warning(f"Places API error: {status} — {data.get('error_message', '')}")
|
||||
places = data.get("places", [])
|
||||
logger.info(f"Places search '{full_query}': count={len(places)}")
|
||||
if not places and "error" in data:
|
||||
logger.warning(f"Places API error: {data['error'].get('message', '')}")
|
||||
return [
|
||||
{
|
||||
"name": p.get("name"),
|
||||
"address": p.get("formatted_address"),
|
||||
"place_id": p.get("place_id"),
|
||||
"maps_link": f"https://www.google.com/maps/place/?q=place_id:{p.get('place_id')}",
|
||||
"name": p.get("displayName", {}).get("text"),
|
||||
"address": p.get("formattedAddress"),
|
||||
"place_id": p.get("id"),
|
||||
"maps_link": p.get("googleMapsUri"),
|
||||
"rating": p.get("rating"),
|
||||
}
|
||||
for p in results[:5]
|
||||
for p in places[:5]
|
||||
]
|
||||
except Exception as e:
|
||||
logger.error(f"Places search in assistant failed: {e}")
|
||||
|
||||
Reference in New Issue
Block a user