Bhavika67's picture
Upload 64 files
6fa37e3 verified
Raw
History Blame Contribute Delete
1.26 kB
"""
api_client/chat.py β€” Chat and stats API calls
"""
from .http import api_post, api_get
def send_message(message: str, namespace: str) -> dict:
"""POST /chat β€” returns the raw response dict."""
return api_post("/chat", {"message": message, "namespace": namespace})
def reset_memory(namespace: str) -> str:
"""POST /chat/reset β€” clears server-side conversation history."""
res = api_post(f"/chat/reset?namespace={namespace}")
return res.get("result", res.get("error", "Done."))
def get_stats() -> tuple:
"""GET /stats β€” returns an 8-tuple for the Stats tab outputs."""
res = api_get("/stats")
if "error" in res:
err = res["error"]
return (err,) + ("",) * 7
tags = res.get("top_tags", [])
tags_str = ", ".join(f"{t}({c})" for t, c in tags) if isinstance(tags, list) else str(tags)
return (
str(res.get("total_entries", "β€”")),
str(res.get("namespaces", "β€”")),
str(res.get("expired_pending_cleanup", "β€”")),
"Yes" if res.get("auth_enabled") else "No",
str(res.get("model", "β€”")),
str(res.get("rate_limit_per_min", "β€”")),
str(res.get("db_path", "β€”")),
tags_str or "none",
)