feat: add worker HTTP client

This commit is contained in:
2026-05-25 18:50:44 +02:00
parent 335ef7cc6c
commit 6e75ba21da
2 changed files with 125 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import httpx
from src.backend.config import settings
class WorkerClient:
def __init__(self):
self.base_url = settings.worker_url
async def process(
self,
prompt: str,
system_prompt: str,
model: str,
session_id: str | None = None,
) -> dict:
async with httpx.AsyncClient(timeout=300.0) as client:
resp = await client.post(
f"{self.base_url}/process",
json={
"prompt": prompt,
"system_prompt": system_prompt,
"model": model,
"session_id": session_id,
},
)
return resp.json()
async def summarize(
self,
exchanges: list[dict],
mode: str = "incremental",
) -> dict:
async with httpx.AsyncClient(timeout=300.0) as client:
resp = await client.post(
f"{self.base_url}/summarize",
json={"exchanges": exchanges, "mode": mode},
)
return resp.json()
async def health(self) -> bool:
try:
async with httpx.AsyncClient(timeout=5.0) as client:
resp = await client.get(f"{self.base_url}/health")
return resp.status_code == 200
except Exception:
return False