Spaces:
Sleeping
Sleeping
File size: 782 Bytes
4e7e4c0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import httpx
from typing import List
import logging
logger = logging.getLogger("embedding-client")
class EmbeddingClient:
def __init__(self, base_url: str):
self.base_url = base_url.rstrip("/")
async def encode(self, texts: List[str]) -> List[List[float]]:
try:
async with httpx.AsyncClient(timeout=30) as client:
response = await client.post(
f"{self.base_url}/embed",
json={"texts": texts}
)
response.raise_for_status()
return response.json()["embeddings"]
except Exception as e:
logger.exception("Embedding service call failed")
raise RuntimeError("EmbeddingServiceError") from e
|