- Add migration 013_city_map_coordinates.sql with map coordinates, zones, and agents table - Add /city/map API endpoint in city-service - Add /city/agents and /city/agents/online endpoints - Extend presence aggregator to include agents[] in snapshot - Add AgentsSource for fetching agent data from DB - Create CityMap component with interactive room tiles - Add useCityMap hook for fetching map data - Update useGlobalPresence to include agents - Add map/list view toggle on /city page - Add agent badges to room cards and map tiles
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import httpx
|
|
from typing import Optional
|
|
|
|
class EmbeddingClient:
|
|
"""Simple embedding client for Phase 3"""
|
|
|
|
def __init__(self, endpoint: str = "http://localhost:8001/embed", provider: str = "local"):
|
|
self.endpoint = endpoint
|
|
self.provider = provider
|
|
self.client = httpx.AsyncClient(timeout=30.0)
|
|
|
|
async def embed(self, text: str) -> list[float]:
|
|
"""
|
|
Generate embedding for text
|
|
|
|
For Phase 3: Returns stub embeddings if service unavailable
|
|
"""
|
|
try:
|
|
response = await self.client.post(
|
|
self.endpoint,
|
|
json={"text": text}
|
|
)
|
|
response.raise_for_status()
|
|
data = response.json()
|
|
return data.get("embedding", [])
|
|
|
|
except (httpx.ConnectError, httpx.HTTPStatusError):
|
|
# Embedding service not available - return stub
|
|
print(f"⚠️ Embedding service not available at {self.endpoint}, using stub")
|
|
# Return zero vector as stub (1024 dimensions for BGE-M3)
|
|
return [0.0] * 1024
|
|
|
|
except Exception as e:
|
|
print(f"❌ Embedding error: {e}")
|
|
return [0.0] * 1024
|
|
|
|
async def embed_batch(self, texts: list[str]) -> list[list[float]]:
|
|
"""Generate embeddings for multiple texts"""
|
|
# For Phase 3: simple sequential processing
|
|
embeddings = []
|
|
for text in texts:
|
|
emb = await self.embed(text)
|
|
embeddings.append(emb)
|
|
return embeddings
|
|
|
|
async def close(self):
|
|
"""Close HTTP client"""
|
|
await self.client.aclose()
|
|
|
|
|
|
|
|
|
|
|