Fix: use pydantic pattern; handle httpx RequestError in gateway and qdrant
This commit is contained in:
@@ -109,20 +109,32 @@ def _col(name: Optional[str]) -> str:
|
||||
async def _embed_url(url: str) -> List[float]:
|
||||
"""Call the CLIP service to get an image embedding."""
|
||||
async with httpx.AsyncClient(timeout=30) as http:
|
||||
r = await http.post(f"{CLIP_URL}/embed", json={"url": url})
|
||||
try:
|
||||
r = await http.post(f"{CLIP_URL}/embed", json={"url": url})
|
||||
except httpx.RequestError as e:
|
||||
raise HTTPException(502, f"CLIP request failed: {str(e)}")
|
||||
if r.status_code >= 400:
|
||||
raise HTTPException(502, f"CLIP /embed error: {r.status_code} {r.text[:200]}")
|
||||
return r.json()["vector"]
|
||||
try:
|
||||
return r.json()["vector"]
|
||||
except Exception:
|
||||
raise HTTPException(502, f"CLIP /embed returned non-JSON: {r.status_code} {r.text[:200]}")
|
||||
|
||||
|
||||
async def _embed_bytes(data: bytes) -> List[float]:
|
||||
"""Call the CLIP service to embed uploaded file bytes."""
|
||||
async with httpx.AsyncClient(timeout=30) as http:
|
||||
files = {"file": ("image", data, "application/octet-stream")}
|
||||
r = await http.post(f"{CLIP_URL}/embed/file", files=files)
|
||||
try:
|
||||
r = await http.post(f"{CLIP_URL}/embed/file", files=files)
|
||||
except httpx.RequestError as e:
|
||||
raise HTTPException(502, f"CLIP request failed: {str(e)}")
|
||||
if r.status_code >= 400:
|
||||
raise HTTPException(502, f"CLIP /embed/file error: {r.status_code} {r.text[:200]}")
|
||||
return r.json()["vector"]
|
||||
try:
|
||||
return r.json()["vector"]
|
||||
except Exception:
|
||||
raise HTTPException(502, f"CLIP /embed/file returned non-JSON: {r.status_code} {r.text[:200]}")
|
||||
|
||||
|
||||
def _build_filter(metadata: Dict[str, Any]) -> Optional[Filter]:
|
||||
|
||||
Reference in New Issue
Block a user