from typing import Union from fastapi import WebSocket class Accelerator: _connected = False def connected(self): return self._connected ws: Union[WebSocket, None] async def connect(self, ws: WebSocket): await ws.accept() self.ws = ws async def accelerate(self, input): await self.ws.send_text(input) return await self.ws.receive_text()