feat: add worker HTTP client
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user