From 9abcb0f1936cee7aeb5b30364dcf2d23859c219b Mon Sep 17 00:00:00 2001 From: ben_mkiv Date: Tue, 22 Aug 2023 21:37:19 +0200 Subject: [PATCH 1/2] 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) From 5d73d9e71ce4874bc070e790feb94bbe77b94fa7 Mon Sep 17 00:00:00 2001 From: ben_mkiv Date: Tue, 22 Aug 2023 21:49:49 +0200 Subject: [PATCH 2/2] small QoL change to the StringNone helper, to allow generated text to be "None", maybe someone wants to generate that, we never know... --- src/api/websocket_server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/websocket_server.py b/src/api/websocket_server.py index 2d77785..7695fbc 100644 --- a/src/api/websocket_server.py +++ b/src/api/websocket_server.py @@ -9,8 +9,10 @@ from utils import generate, get_autoregressive_models, get_voice_list # this is a not so nice workaround to set values to None if their string value is "None" def replaceNoneStringWithNone(message): + ignore_fields = ['text'] # list of fields which CAN have "None" as literal String value + for member in message: - if message[member] == 'None': + if message[member] == 'None' and member not in ignore_fields: message[member] = None return message