From 9abcb0f1936cee7aeb5b30364dcf2d23859c219b Mon Sep 17 00:00:00 2001 From: ben_mkiv Date: Tue, 22 Aug 2023 21:37:19 +0200 Subject: [PATCH] websocket server: API change(!), better response format --- src/api/websocket_server.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/api/websocket_server.py b/src/api/websocket_server.py index 3af0685..2d77785 100644 --- a/src/api/websocket_server.py +++ b/src/api/websocket_server.py @@ -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)