From c2e043bade416c53bfe039a947fe7d0d52885715 Mon Sep 17 00:00:00 2001 From: "yanyuxiyangzk@126.com" Date: Mon, 15 Apr 2024 09:58:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AAchat?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app2.py b/app2.py index fab2797..19ce030 100644 --- a/app2.py +++ b/app2.py @@ -188,6 +188,25 @@ def chat_socket(ws): res=llm_response(message) txt_to_audio(res) +@sockets.route('/chat') +def chat_socket(ws): + # 获取WebSocket对象 + #ws = request.environ.get('wsgi.websocket') + # 如果没有获取到,返回错误信息 + if not ws: + print('未建立连接!') + return 'Please use WebSocket' + # 否则,循环接收和发送消息 + else: + print('建立连接!') + while True: + message = ws.receive() + + if len(message)==0: + return '输入信息为空' + else: + txt_to_audio(message) + def render(): nerfreal.render()