From 5da836e0e8be354f650824c397abfea66186b986 Mon Sep 17 00:00:00 2001 From: shehuiqiang <39358003@qq.com> Date: Thu, 30 Mar 2023 22:26:42 +0800 Subject: [PATCH] =?UTF-8?q?bug=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/http/http_channel.py | 10 ++++++---- channel/http/templates/index.html | 4 ++++ model/bing/new_bing_model.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/channel/http/http_channel.py b/channel/http/http_channel.py index deb5787..a82fbbb 100644 --- a/channel/http/http_channel.py +++ b/channel/http/http_channel.py @@ -14,7 +14,7 @@ from flask_socketio import SocketIO from common import log http_app = Flask(__name__,) -socketio = SocketIO(http_app) +socketio = SocketIO(http_app, close_timeout=5) # 自动重载模板文件 http_app.jinja_env.auto_reload = True http_app.config['TEMPLATES_AUTO_RELOAD'] = True @@ -29,13 +29,13 @@ async def return_stream(data): if(final): socketio.server.emit( 'disconnect', {'result': response, 'final': final}, request.sid, namespace="/chat") - socketio.server.disconnect(request.sid) + disconnect() else: socketio.server.emit( 'message', {'result': response, 'final': final}, request.sid, namespace="/chat") except Exception as e: - socketio.server.disconnect(request.sid) - log.error("[http]emit:", e) + disconnect() + log.warn("[http]emit:{}", e) break @@ -52,6 +52,7 @@ def stream(data): if img_match_prefix: reply_text = HttpChannel().handle(data=data) socketio.emit('disconnect', {'result': reply_text}, namespace='/chat') + disconnect() return asyncio.run(return_stream(data)) @@ -65,6 +66,7 @@ def connect(): @socketio.on('disconnect', namespace='/chat') def disconnect(): log.info('disconnect') + socketio.server.disconnect(request.sid,namespace="/chat") @http_app.route("/chat", methods=['POST']) diff --git a/channel/http/templates/index.html b/channel/http/templates/index.html index 798965b..1b0f385 100644 --- a/channel/http/templates/index.html +++ b/channel/http/templates/index.html @@ -146,6 +146,10 @@ localConfig.backgroundColor = $(this).val(); }); + $(window).on('unload', function () { + socket.disconnect(); + }); + jQuery(function (a) { var b = a("#chat").convform() }); diff --git a/model/bing/new_bing_model.py b/model/bing/new_bing_model.py index e20b81f..933866e 100644 --- a/model/bing/new_bing_model.py +++ b/model/bing/new_bing_model.py @@ -33,7 +33,7 @@ class BingModel(Model): if final: try: reply = self.build_source_attributions(answer, context) - log.info("[NewBing] reply:{}",reply) + log.info("[NewBing] reply:{}", reply) yield True, reply except Exception as e: log.warn(answer)