增加一个chat接口

This commit is contained in:
yanyuxiyangzk@126.com 2024-04-15 09:58:15 +08:00
parent ec7f7b5041
commit c2e043bade
1 changed files with 19 additions and 0 deletions

19
app2.py
View File

@ -188,6 +188,25 @@ def chat_socket(ws):
res=llm_response(message) res=llm_response(message)
txt_to_audio(res) 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(): def render():
nerfreal.render() nerfreal.render()