Fix some issues

This commit is contained in:
linghaihui 2023-03-30 11:58:35 +08:00
parent 3fc48e1e32
commit a5f04700dd
6 changed files with 23 additions and 17 deletions

View File

@ -31,6 +31,7 @@ Component({
data: {
chatList: [],
receiveData: false,
autoIncrConversation: 1,
},
methods: {
initMessageHistory() {

View File

@ -1,7 +1,7 @@
<wxs src="../../tools.wxs" module="tools" />
<view catchlongpress="longPress">
<view wx:if="{{chatList.length == 0}}" style="text-align:center;color: #b4bbc4;font-size: 30rpx;">输入问题开始和New Bing聊天吧~</view>
<scroll-view class="chat" scroll-y="true" scroll-into-view="{{scrollId}}" style="height:{{systemInfo.windowHeight - 70}}px;" enable-back-to-top="{{true}}" scroll-anchoring="{{true}}" enhanced="{{true}}" enable-flex="{{true}}">
<scroll-view class="chat" scroll-y="{{true}}" scroll-into-view="{{scrollId}}" style="height:{{systemInfo.windowHeight - 70}}px;" enable-back-to-top="{{true}}" scroll-anchoring="{{true}}" enhanced="{{true}}" enable-passive="{{true}}" show-scrollbar="{{false}}">
<view wx:for="{{chatList}}" wx:key="index" wx:for-item="item" id="{{'item'+index}}">
<view class="chat-item left" wx:if="{{item.type != 'man'}}" id="msg-{{index}}">
<image class="avatar" src="{{item.avatarUrl}}" style="display: flex;" catchlongpress="clearChat" data-index="{{index}}" catchtap="showOriginContent" data-index="{{index}}"></image>
@ -21,7 +21,7 @@
<image class="avatar" src="{{item.avatarUrl}}" catchlongpress="clearChat" data-index="{{index}}"></image>
</view>
</view>
<view id="{{'item'+ chatList.length + 9999}}" style="margin-top: 2em;"></view>
<view id="{{'item'+ autoIncrConversation + 9999}}" style="height: 1em;"></view>
</scroll-view>
<icon wx:if="{{receiveData}}" type="cancel" catchtap="cancelReceive" style="position: absolute;bottom: 140rpx;right:1%;z-index: 10000;" size="20"></icon>
<icon wx:if="{{receiveData}}" type="cancel" catchtap="cancelReceive" style="position: absolute;bottom: 142rpx;right:1%;z-index: 10000;" size="20"></icon>
</view>

View File

@ -21,7 +21,7 @@
width: 80rpx;
height: 80rpx;
border-radius: 50%;
background-color: #e0e2e8;
background-color: #d0dfe6;
}
.dt {

View File

@ -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

View File

@ -5,5 +5,5 @@
"compileHotReLoad": true,
"urlCheck": false
},
"libVersion": "2.16.1"
"libVersion": "2.25.3"
}

View File

@ -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': ''})