Fix some issues

This commit is contained in:
linghaihui 2023-03-26 11:55:33 +08:00
parent fa594f2aaa
commit af7c4ebc2f
9 changed files with 52 additions and 15 deletions

View File

@ -52,7 +52,7 @@ Component({
var index = e.currentTarget.dataset.index;
var data = this.data.chatList;
wx.showModal({
content: "是否删除该条记录",
content: "是否删除该条聊天",
complete: (res) => {
if (res.confirm) {
data.splice(index, 1);
@ -87,5 +87,22 @@ Component({
}, {}
);
},
deletAllChat: function (e) {
var that = this
wx.showModal({
content: "是否删除全部聊天?",
complete: (res) => {
if (res.confirm) {
that.setData({
chatList: [],
});
wx.setStorage({
key: "chatList",
data: [],
});
}
},
});
}
},
});

View File

@ -1,12 +1,13 @@
<!-- <wxs src="../../tools.wxs" module="tools" /> -->
<view catchlongpress="deletAllChat">
<view wx:if="{{chatList.length == 0}}" style="text-align:center;color: rgb(180, 187, 196);font-size: 28rpx;">输入问题开始和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}}">
<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;" bindlongpress="clearChat" data-index="{{index}}"></image>
<image class="avatar" src="{{item.avatarUrl}}" style="display: flex;" catchlongpress="clearChat" data-index="{{index}}"></image>
<view class="chat-box" style="margin-left: 20rpx;">
<view style="display: flex;flex-direction: row;align-items: center;"><text class="dt" style="flex: 1;">{{item.dt}}</text><view wx:if="{{item.num_in_conversation && item.num_in_conversation != -1}}" style="display:flex;justify-content:flex-end; flex: 1;align-items: center;"><text class="conversation_num">{{item.num_in_conversation}}</text></view></view>
<view class="content bg-white" bindlongpress="copyContent" data-index="{{index}}"><view class="{{item.blink ? 'blinking': ''}}"><mp-html content="{{item.originContent}}" preview-img markdown="{{true}}" img-cache="{{true}}" lazy-load="{{true}}" container-style="margin-top: -1em;"/></view></view>
<view class="content bg-white" catchlongpress="copyContent" data-index="{{index}}"><view class="{{item.blink ? 'blinking': ''}}"><mp-html content="{{item.originContent}}" preview-img markdown="{{true}}" img-cache="{{true}}" lazy-load="{{true}}" container-style="margin-top: -1em;"/></view></view>
<view class="suggest">
<view hover-class="suggest-item-hover" class="suggest-item" bindtap="suggestSubmit" data-suggest="{{suggest}}" wx:for="{{item.suggests}}" wx:for-item="suggest">{{suggest}}</view>
</view>
@ -15,9 +16,10 @@
<view class="chat-item right" wx:if="{{item.type == 'man' }}" id="msg-{{index}}">
<view class="chat-box" style="margin-right: 20rpx;">
<text class="dt" style="display: block;text-align: right">{{item.dt}}</text>
<view class="content bg-green" bindlongpress="copyContent" data-index="{{index}}"><text user-select decode space>{{item.originContent}}</text></view>
<view class="content bg-green" catchlongpress="copyContent" data-index="{{index}}"><text user-select decode space>{{item.originContent}}</text></view>
</view>
<image class="avatar" src="{{item.avatarUrl}}" bindlongpress="clearChat" data-index="{{index}}"></image>
<image class="avatar" src="{{item.avatarUrl}}" catchlongpress="clearChat" data-index="{{index}}"></image>
</view>
</view>
</scroll-view>
</scroll-view>
</view>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,7 @@ function inputPop() {
return systemInfo.platform == "ios" || systemInfo.platform == "android"
}
const initHeight = inputPop() ? 20 : 2
const initHeight = inputPop() ? 18 : 5
Date.prototype.format = function (fmt) {
var o = {
@ -62,7 +62,8 @@ Page({
},
InputBlur(e) {
this.setData({
InputBottom: initHeight,
InputBottom: initHeight,
textareaFocus: false,
});
},
processContent(content) {

View File

@ -1,5 +1,5 @@
<chat-box bindsuggestSubmit="onSuggestSubmit"></chat-box>
<view style="bottom:{{InputBottom}}px; border-radius: 20rpx;margin-left: 1.5%;width: 97%;min-height: 100rpx;position: fixed;background-color: #f4f6f8;display: flex;align-items:flex-start;">
<textarea bindfocus="InputFocus" bindblur="InputBlur" model:value="{{content}}" adjust-position="{{false}}" focus="{{textareaFocus}}" maxlength="2000" auto-height="{{true}}" cursor-spacing="10" bindconfirm="submit" fixed="{{true}}" show-confirm-bar="{{false}}" confirm-type="send" placeholder="请输入问题..." style="padding: 10rpx;flex: 8;" placeholder-style="color: #b4bbc4" bindtap="focus"></textarea>
<button style="flex: 1;background-color: #f4f6f8;color: {{content ? black : '#b4bbc4'}};border-left: 1px dashed #b4bbc4;border-radius: 0 20rpx 20rpx 0;" bindtap="submit" wx:if="{{systemInfo.platform != 'ios'}}">发送</button>
<view style="bottom:{{InputBottom}}px; border-radius: 20rpx;margin-left: 1.5%;width: 97%;min-height: 100rpx;position: fixed;background-color: #f4f6f8;display: flex;align-items:flex-start; justify-content: space-between;{{textareaFocus ? 'border: 1rpx solid;': ''}}">
<textarea bindfocus="InputFocus" bindblur="InputBlur" model:value="{{content}}" adjust-position="{{false}}" focus="{{textareaFocus}}" maxlength="2000" auto-height="{{true}}" cursor-spacing="10" bindconfirm="submit" fixed="{{true}}" show-confirm-bar="{{false}}" confirm-type="send" placeholder="请输入问题..." style="padding: 10rpx;" placeholder-style="color: #b4bbc4" bindtap="focus"></textarea>
<view style="background-color: #f4f6f8;color: {{content ? black : '#b4bbc4'}};border-radius: 0 20rpx 20rpx 0;height: 100rpx;cursor: pointer;" bindtap="submit" wx:if="{{systemInfo.platform != 'ios'}}"><text style="padding: 10rpx;font-size: 32rpx;cursor: pointer;">发送</text></view>
</view>

View File

@ -1,3 +1,8 @@
button::after {
border: none;
border: none;
}
::-webkit-scrollbar {
width: 0 !important;
height: 0 !important;
color: transparent;
}

View File

@ -1,5 +1,6 @@
# coding=utf-8
import logging
import os
import re
import threading
@ -10,11 +11,13 @@ from sanic.response import json
from EdgeGPT import Chatbot, ConversationStyle
logger = logging.getLogger(__name__)
APPID = os.environ.get('WXAPPID')
APPSECRET = os.environ.get('WXAPPSECRET')
WX_URL = 'https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code'
# 备用cookie
COOKIE = os.environ.get('COOKIE_FILE', '')
# 备用cookie
BAK_COOKIE = os.environ.get('COOKIE_FILE1', '')
BAK_COOKIE1 = os.environ.get('COOKIE_FILE2', '')
@ -76,14 +79,23 @@ async def chat(request):
if status == 'Success':
item = res['item']['messages']
if len(item) >= 2:
text = item[1]['text']
if 'text' not in item[1]:
text = '响应异常'
logger.error('响应异常:%s', res)
else:
text = item[1]['text']
if re.search(r'\[\^\d+\^\]', text):
text = item[1]['adaptiveCards'][0]['body'][0]['text']
text = re.sub(r'\[\^\d+\^\]', '', text)
suggests = [x['text'] for x in item[1]['suggestedResponses']] if 'suggestedResponses' in item[1] else []
else:
text = '抱歉,未搜索到结果,请重试。'
logger.error('响应异常:%s', res)
suggests = [request.json.get('q')]
# 结束本轮对话
if res['type'] == 2:
await get_bot(sid).reset()
text = '抱歉,未搜索到结果,已结束本轮对话。'
msg = res['item']['result']['message'] if 'message' in res['item']['result'] else ''
# 自动reset
if auto_reset and ('New topic' in text or 'has expired' in msg):