This commit is contained in:
linghaihui 2023-03-27 00:50:35 +08:00
parent 88b346ae85
commit ceca424248
2 changed files with 38 additions and 22 deletions

View File

@ -9,6 +9,7 @@ function inputPop() {
return systemInfo.platform == "ios" || systemInfo.platform == "android" return systemInfo.platform == "ios" || systemInfo.platform == "android"
} }
// 各平台对话分离
var sid_prefix = systemInfo.platform == "ios" || systemInfo.platform == "android" ? "" : systemInfo.platform var sid_prefix = systemInfo.platform == "ios" || systemInfo.platform == "android" ? "" : systemInfo.platform
const initHeight = inputPop() ? 20 : 5 const initHeight = inputPop() ? 20 : 5
@ -195,10 +196,15 @@ Page({
} else { } else {
that.pushStorageMessage(cht, "搜索中🔍...", "rob", [], true) that.pushStorageMessage(cht, "搜索中🔍...", "rob", [], true)
} }
if (systemInfo.platform == "ios" || systemInfo.platform == "android" || systemInfo.platform == "devtools") { // 经测试mac 平台下打开debug才能触发websocket的onOpen回调。。。
that.sendWSRequest(content) if (systemInfo.platform == "mac") {
if (systemInfo.enableDebug) {
that.sendWSRequest(content)
} else {
that.sendHttpRequest(content)
}
} else { } else {
that.sendHttpRequest(content) that.sendWSRequest(content)
} }
}, },
pushStorageMessage: function (cht, content, role, suggests, blink, pop, num_in_conversation = -1, final = true) { pushStorageMessage: function (cht, content, role, suggests, blink, pop, num_in_conversation = -1, final = true) {
@ -268,17 +274,20 @@ Page({
} }
}) })
socket.onOpen(() => { socket.onOpen(() => {
that.setData({ console.log("Socket onOpen", socket)
socket: { if (socket.readyState == 1) {
socket: socket, that.setData({
isOpen: true socket: {
} socket: socket,
}) isOpen: true
setTimeout(() => { }
if (callback) { })
callback() setTimeout(() => {
} if (callback) {
}, 50) callback()
}
}, 50)
}
}) })
socket.onClose((code, reason) => { socket.onClose((code, reason) => {
console.log('Socket onClose', code, reason) console.log('Socket onClose', code, reason)
@ -299,6 +308,9 @@ Page({
}, },
searching: false searching: false
}) })
wx.showToast({
title: '网络异常',
})
}) })
socket.onMessage(data => { socket.onMessage(data => {
const cht = app.globalData.cht; const cht = app.globalData.cht;
@ -348,4 +360,4 @@ Page({
}) })
} }
} }
}); });

View File

@ -100,13 +100,17 @@ async def process_data(res, q, sid, auto_reset=None):
if status == 'Success': if status == 'Success':
item = res['item']['messages'] item = res['item']['messages']
if len(item) >= 2: if len(item) >= 2:
if 'text' not in item[1]: if 'adaptiveCards' in item[1]:
text = '响应异常' try:
logger.error('响应异常:%s', res) text = item[1]['adaptiveCards'][0]['body'][0]['text']
else: except KeyError:
text = item[1]['text'] pass
if re.search(r'\[\^\d+\^\]', text): if not text:
text = item[1]['adaptiveCards'][0]['body'][0]['text'] if 'text' not in item[1]:
text = '响应异常'
logger.error('响应异常:%s', res)
else:
text = item[1]['text']
text = re.sub(r'\[\^\d+\^\]', '', text) text = re.sub(r'\[\^\d+\^\]', '', text)
suggests = [x['text'] for x in item[1]['suggestedResponses']] if 'suggestedResponses' in item[1] else [] suggests = [x['text'] for x in item[1]['suggestedResponses']] if 'suggestedResponses' in item[1] else []
else: else: