answerer-api / accelerator.py
DaniilAlpha's picture
Fixed bug in accelerator.
70dbc85
raw
history blame
448 Bytes
from typing import Union
from fastapi.websockets import WebSocket, WebSocketDisconnect
class Accelerator:
ws: Union[WebSocket, None]
def connected(self): return self.ws != None
async def connect(self, ws: WebSocket):
await ws.accept()
self.ws = ws
async def accelerate(self, input):
try:
await self.ws.send_text(input)
return await self.ws.receive_text()
except WebSocketDisconnect:
self.ws = None