answerer-api / accelerator.py
DaniilAlpha's picture
.
7ace067
raw
history blame
528 Bytes
from typing import Union
from fastapi.websockets import WebSocket, WebSocketState
class Accelerator:
ws: Union[WebSocket, None] = None
def connected(self):
if self.ws == None: return False
if self.ws.client_state == WebSocketState.CONNECTED:
return True
else:
self.ws = None
return False
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()