Spaces:
Sleeping
Sleeping
Download src/agent/callback.py from bxntang/rtm-class-ai: direct link, hf CLI and curl.
- Browser
- Download file 949 Bytes
-
https://huggingface.co/spaces/bxntang/rtm-class-ai/resolve/main/src/agent/callback.py
- Command line
-
hf download hf://spaces/bxntang/rtm-class-ai/src/agent/callback.py
-
curl -L -o callback.py https://huggingface.co/spaces/bxntang/rtm-class-ai/resolve/main/src/agent/callback.py
949 Bytes
| from __future__ import annotations | |
| from src.config import settings | |
| class WebhookCallbackClient: | |
| def __init__(self) -> None: | |
| self._client = None | |
| async def initialize(self) -> None: | |
| if self._client is not None: | |
| return | |
| try: | |
| import httpx | |
| except ImportError as exc: | |
| raise RuntimeError("httpx package is required for webhook callback.") from exc | |
| self._client = httpx.AsyncClient( | |
| timeout=settings.webhook_callback_timeout_seconds, | |
| ) | |
| async def shutdown(self) -> None: | |
| if self._client is None: | |
| return | |
| await self._client.aclose() | |
| self._client = None | |
| async def send_json(self, *, callback_url: str, payload: dict) -> None: | |
| await self.initialize() | |
| assert self._client is not None | |
| response = await self._client.post(callback_url, json=payload) | |
| response.raise_for_status() | |