1
0

websocket server: API change(!), better response format

This commit is contained in:
ben_mkiv 2023-08-22 21:37:19 +02:00
parent 1ec3344999
commit 9abcb0f193

View File

@ -7,18 +7,6 @@ from websockets.server import serve
from utils import generate, get_autoregressive_models, get_voice_list
async def _handle_generate(websocket, message):
await websocket.send(json.dumps(generate(**message)))
async def _handle_get_autoregressive_models(websocket, message):
await websocket.send(json.dumps(get_autoregressive_models()))
async def _handle_get_voice_list(websocket, message):
await websocket.send(json.dumps(get_voice_list()))
# this is a not so nice workaround to set values to None if their string value is "None"
def replaceNoneStringWithNone(message):
for member in message:
@ -28,6 +16,21 @@ def replaceNoneStringWithNone(message):
return message
async def _handle_generate(websocket, message):
message['result'] = generate(**message)
await websocket.send(json.dumps(replaceNoneStringWithNone(message)))
async def _handle_get_autoregressive_models(websocket, message):
message['result'] = get_autoregressive_models()
await websocket.send(json.dumps(replaceNoneStringWithNone(message)))
async def _handle_get_voice_list(websocket, message):
message['result'] = get_voice_list()
await websocket.send(json.dumps(replaceNoneStringWithNone(message)))
async def _handle_message(websocket, message):
message = replaceNoneStringWithNone(message)