Spaces:
Sleeping
Sleeping
File size: 1,027 Bytes
29116ed c16e1c9 29116ed c16e1c9 29116ed c16e1c9 29116ed c16e1c9 29116ed c16e1c9 29116ed |
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 |
from fastapi import APIRouter, Header, HTTPException, Query
from api.mcp_clients.web_client import WebClient
router = APIRouter()
web_client = WebClient()
@router.post("/web/search")
async def web_search(
query: str,
max_results: int = Query(5, ge=1, le=10),
region: str = Query("us"),
x_tenant_id: str = Header(None),
):
"""
Perform a live Google Custom Search query for the tenant.
"""
if not x_tenant_id:
raise HTTPException(status_code=400, detail="Missing tenant ID")
try:
results = await web_client.search(query, max_results=max_results, region=region)
return {
"tenant_id": x_tenant_id,
"query": query,
"results": results,
"metadata": {"max_results": max_results, "region": region},
}
except RuntimeError as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc
except Exception as exc:
raise HTTPException(status_code=500, detail="Web search failed") from exc
|