51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
import httpx
|
|
|
|
|
|
class EverOSClient:
|
|
def __init__(self, base_url: str, timeout: float = 120.0) -> None:
|
|
self.base_url = base_url.rstrip("/")
|
|
self.timeout = timeout
|
|
|
|
async def add_memory(self, payload: dict[str, Any]) -> dict[str, Any]:
|
|
return await self._post("/api/v1/memory/add", payload)
|
|
|
|
async def flush_memory(
|
|
self,
|
|
session_id: str,
|
|
app_id: str,
|
|
project_id: str,
|
|
) -> dict[str, Any]:
|
|
return await self._post(
|
|
"/api/v1/memory/flush",
|
|
{
|
|
"session_id": session_id,
|
|
"app_id": app_id,
|
|
"project_id": project_id,
|
|
},
|
|
)
|
|
|
|
async def search_memory(self, payload: dict[str, Any]) -> dict[str, Any]:
|
|
return await self._post("/api/v1/memory/search", payload)
|
|
|
|
async def health_check(self) -> dict[str, Any]:
|
|
async with httpx.AsyncClient(
|
|
base_url=self.base_url,
|
|
timeout=self.timeout,
|
|
) as client:
|
|
response = await client.get("/health")
|
|
response.raise_for_status()
|
|
return response.json()
|
|
|
|
async def _post(self, path: str, payload: dict[str, Any]) -> dict[str, Any]:
|
|
async with httpx.AsyncClient(
|
|
base_url=self.base_url,
|
|
timeout=self.timeout,
|
|
) as client:
|
|
response = await client.post(path, json=payload)
|
|
response.raise_for_status()
|
|
return response.json()
|