From a5f04700dd5bafd45e0964800514a776a89045a9 Mon Sep 17 00:00:00 2001 From: linghaihui <75124771@qq.com> Date: Thu, 30 Mar 2023 11:58:35 +0800 Subject: [PATCH] Fix some issues --- bingchat/components/chatbox/index.js | 1 + bingchat/components/chatbox/index.wxml | 6 +++--- bingchat/components/chatbox/index.wxss | 2 +- bingchat/pages/index/index.js | 8 ++++++-- bingchat/project.private.config.json | 2 +- new-bing/app.py | 21 +++++++++++---------- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/bingchat/components/chatbox/index.js b/bingchat/components/chatbox/index.js index 11cfe08..d575c61 100644 --- a/bingchat/components/chatbox/index.js +++ b/bingchat/components/chatbox/index.js @@ -31,6 +31,7 @@ Component({ data: { chatList: [], receiveData: false, + autoIncrConversation: 1, }, methods: { initMessageHistory() { diff --git a/bingchat/components/chatbox/index.wxml b/bingchat/components/chatbox/index.wxml index 0506f68..d728c71 100644 --- a/bingchat/components/chatbox/index.wxml +++ b/bingchat/components/chatbox/index.wxml @@ -1,7 +1,7 @@ 输入问题开始和New Bing聊天吧~ - + @@ -21,7 +21,7 @@ - + - + \ No newline at end of file diff --git a/bingchat/components/chatbox/index.wxss b/bingchat/components/chatbox/index.wxss index 3f098f9..4d52e3f 100644 --- a/bingchat/components/chatbox/index.wxss +++ b/bingchat/components/chatbox/index.wxss @@ -21,7 +21,7 @@ width: 80rpx; height: 80rpx; border-radius: 50%; - background-color: #e0e2e8; + background-color: #d0dfe6; } .dt { diff --git a/bingchat/pages/index/index.js b/bingchat/pages/index/index.js index dd2b446..f4e3566 100644 --- a/bingchat/pages/index/index.js +++ b/bingchat/pages/index/index.js @@ -21,6 +21,8 @@ try { function inputPop() { return systemInfo.platform == "ios" || systemInfo.platform == "android" } +// 自增对话 +var autoIncrConversation = 0 Date.prototype.format = function (fmt) { var o = { @@ -226,8 +228,10 @@ Page({ blink: blink, num_in_conversation: num_in_conversation, }) + autoIncrConversation += 1 cht.setData({ chatList: cht.data.chatList, + autoIncrConversation: autoIncrConversation, }) if (role == "rob" && !blink && final) { this.setData({ @@ -240,9 +244,9 @@ Page({ }) setTimeout(() => { cht.setData({ - scrollId: "item" + (cht.data.chatList.length + "9999"), + scrollId: "item" + (autoIncrConversation + "9999"), }) - }, 50) + }, 100) }, submit() { var content = this.data.content diff --git a/bingchat/project.private.config.json b/bingchat/project.private.config.json index b31f0d7..05259dd 100644 --- a/bingchat/project.private.config.json +++ b/bingchat/project.private.config.json @@ -5,5 +5,5 @@ "compileHotReLoad": true, "urlCheck": false }, - "libVersion": "2.16.1" + "libVersion": "2.25.3" } \ No newline at end of file diff --git a/new-bing/app.py b/new-bing/app.py index efe38db..76ef726 100644 --- a/new-bing/app.py +++ b/new-bing/app.py @@ -30,7 +30,6 @@ else: BAK_COOKIE2 = os.environ.get('COOKIE_FILE3', COOKIE) LOCK = threading.Lock() -BOT_LOCK = threading.Lock() bots = {} app = Sanic('new-bing') @@ -85,7 +84,7 @@ async def ws_chat(_, ws): processed_data = await process_data(res, q, sid, auto_reset=1) if processed_data['data']['status'] == 'Throttled': reset_cookie() - await get_bot(sid).reset() + await reset_conversation(sid) processed_data['data']['suggests'].append(q) await ws.send(raw_json.dumps({ 'final': final, @@ -105,9 +104,7 @@ async def ws_chat(_, ws): def get_bot(sid): - BOT_LOCK.acquire(timeout=2) if sid in bots: - BOT_LOCK.release() record = bots[sid] if record['expired'] > datetime.now(): return record['bot'] @@ -116,10 +113,14 @@ def get_bot(sid): 'bot': bot, 'expired': datetime.now() + timedelta(hours=5, minutes=55), # 会话有效期为6小时 } - BOT_LOCK.release() return bot +async def reset_conversation(sid): + await get_bot(sid).reset() + bots[sid]['expired'] = datetime.now() + timedelta(hours=5, minutes=55) + + async def do_chat(request): logger.info('Http request payload: %s', request.json) return await get_bot(request.json.get('sid')).ask( @@ -152,11 +153,11 @@ async def process_data(res, q, sid, auto_reset=None): logger.error('响应异常:%s', res) suggests = [q] if res['type'] == 2: - await get_bot(sid).reset() - text += '\n\n已结束本轮对话。' + await reset_conversation(sid) + text += '\n已结束本轮对话。' msg = res['item']['result']['message'] if 'message' in res['item']['result'] else '' if auto_reset and ('New topic' in text or 'has expired' in msg): - await get_bot(sid).reset() + await reset_conversation(sid) return make_response_data( status, text, suggests, msg, res['item']['throttling']['numUserMessagesInConversation'] if 'throttling' in res['item'] else -1 @@ -171,7 +172,7 @@ async def chat(request): data = await process_data(res, request.json.get('q'), sid, auto_reset) if data['data']['status'] == 'Throttled': reset_cookie() - await get_bot(sid).reset() + await reset_conversation(sid) res = await do_chat(request) data = await process_data(res, request.json.get('q'), sid, auto_reset) return json(data) @@ -179,7 +180,7 @@ async def chat(request): @app.route('/reset') async def reset(request): - await get_bot(request.args.get('sid')).reset() + await reset_conversation(request.args.get('sid')) return json({'data': ''})