Fix some issues
This commit is contained in:
parent
c9985629b0
commit
532420d7f1
@ -33,16 +33,8 @@ Component({
|
||||
},
|
||||
lifetimes: {
|
||||
attached() {
|
||||
var that = this
|
||||
app.globalData.cht = that
|
||||
that.initMessageHistory()
|
||||
wx.getSystemInfo({
|
||||
success: function (res) {
|
||||
that.setData({
|
||||
systemInfo: res,
|
||||
})
|
||||
},
|
||||
})
|
||||
app.globalData.cht = this
|
||||
this.initMessageHistory()
|
||||
},
|
||||
detached() {
|
||||
try {} catch (error) {}
|
||||
@ -55,6 +47,7 @@ Component({
|
||||
closeShareOnCopy: closeShareOnCopy,
|
||||
showShare: false,
|
||||
loadingData: false,
|
||||
systemInfo: systemInfo,
|
||||
height: systemInfo.windowHeight - parseInt(100 / 750 * systemInfo.windowWidth) - ((systemInfo.platform == "ios" || systemInfo.platform == "android") ? 22 : 5)
|
||||
},
|
||||
methods: {
|
||||
@ -106,13 +99,13 @@ Component({
|
||||
if (filterData.length == 0 && e) {
|
||||
setTimeout(() => {
|
||||
wx.showToast({
|
||||
title: "已加载完成"
|
||||
title: "已全部加载完成"
|
||||
})
|
||||
}, 300)
|
||||
}, 100)
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
wx.hideLoading()
|
||||
}, 300)
|
||||
}, 100)
|
||||
}
|
||||
})
|
||||
}).catch(res => {
|
||||
@ -122,7 +115,6 @@ Component({
|
||||
})
|
||||
},
|
||||
initMessageHistory() {
|
||||
//this.bindscrolltoupper()
|
||||
var that = this
|
||||
wx.getStorage({
|
||||
key: "chatList",
|
||||
@ -133,7 +125,12 @@ Component({
|
||||
that.setData({
|
||||
chatList: data,
|
||||
})
|
||||
} else {
|
||||
that.bindscrolltoupper()
|
||||
}
|
||||
},
|
||||
fail: function () {
|
||||
that.bindscrolltoupper()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@ -45,6 +45,13 @@ app.config.WEBSOCKET_PING_TIMEOUT = 30
|
||||
OPENAI_CONVERSATION = defaultdict(lambda: [])
|
||||
|
||||
|
||||
def show_chatgpt(sid):
|
||||
for openid in conversation_ctr.get_openai_whitelist():
|
||||
if openid.decode() in sid:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
def reset_cookie():
|
||||
if not LOCK.acquire(blocking=False):
|
||||
return
|
||||
@ -217,6 +224,8 @@ async def ws_openai_chat(_, ws):
|
||||
data = raw_json.loads(await ws.recv())
|
||||
logger.info('[openai] Websocket receive data: %s', data)
|
||||
sid = data['sid']
|
||||
if not show_chatgpt(sid):
|
||||
raise Exception('无权限访问此服务')
|
||||
q = data['q']
|
||||
# 保存30个对话
|
||||
history_conversation = OPENAI_CONVERSATION[sid][-30:]
|
||||
@ -227,7 +236,7 @@ async def ws_openai_chat(_, ws):
|
||||
response = openai.ChatCompletion.create(
|
||||
model='gpt-3.5-turbo',
|
||||
messages=history_conversation,
|
||||
temperature=1.2,
|
||||
temperature=0.8,
|
||||
stream=True,
|
||||
)
|
||||
chunks = []
|
||||
@ -269,6 +278,8 @@ async def openai_chat(request):
|
||||
try:
|
||||
logger.info('[openai] Http request payload: %s', request.json)
|
||||
sid = request.json.get('sid')
|
||||
if not show_chatgpt(sid):
|
||||
raise Exception('无权限访问此服务')
|
||||
q = request.json.get('q')
|
||||
history_conversation = OPENAI_CONVERSATION[sid][-30:]
|
||||
history_conversation.append({
|
||||
@ -278,7 +289,7 @@ async def openai_chat(request):
|
||||
response = openai.ChatCompletion.create(
|
||||
model='gpt-3.5-turbo',
|
||||
messages=history_conversation,
|
||||
temperature=1.2,
|
||||
temperature=0.8,
|
||||
stream=True,
|
||||
)
|
||||
chunks = []
|
||||
@ -306,7 +317,7 @@ async def last_sync_time(request):
|
||||
@app.post('/save')
|
||||
async def save(request):
|
||||
conversation_ctr.save(request.json.get('sid'), request.json.get('conversations'))
|
||||
return json({'saved': 0})
|
||||
return json({'saved': show_chatgpt(request.json.get('sid'))})
|
||||
|
||||
|
||||
@app.route('/query')
|
||||
|
||||
@ -15,6 +15,7 @@ class ConversationCtr:
|
||||
|
||||
LAST_SYNC_TIME_KEY = 'bing:last_sync_time:%s'
|
||||
CONVERSATION_LIST_KEY = 'bing:conversation_list:%s'
|
||||
OPENAI_WHITE_LIST_KEY = 'bing:openai_white_list'
|
||||
|
||||
def __init__(self, client=None) -> None:
|
||||
self.redis_client = client
|
||||
@ -54,5 +55,8 @@ class ConversationCtr:
|
||||
key = self.CONVERSATION_LIST_KEY % sid
|
||||
self.redis_client.delete(key)
|
||||
|
||||
def get_openai_whitelist(self):
|
||||
return self.redis_client.lrange(self.OPENAI_WHITE_LIST_KEY, 0, 10000)
|
||||
|
||||
|
||||
conversation_ctr = ConversationCtr()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user