fix: 修复多token功能带来的一些影响

This commit is contained in:
ikechan8370 2023-04-01 12:25:20 +08:00
parent e93614ca35
commit fd408586a8
2 changed files with 32 additions and 13 deletions

View file

@ -206,6 +206,13 @@ export class chatgpt extends plugin {
await redis.del(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`)
await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true)
} else if (use === 'bing' && (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom')) {
let c = await redis.get(`CHATGPT:CONVERSATIONS_BING:${e.sender.user_id}`)
if (!c) {
await this.reply('当前没有开启对话', true)
return
} else {
await redis.del(`CHATGPT:CONVERSATIONS_BING:${e.sender.user_id}`)
}
const conversation = {
store: new KeyvFile({ filename: 'cache.json' }),
namespace: Config.toneStyle
@ -735,7 +742,11 @@ export class chatgpt extends plugin {
previousConversation.invocationId = chatMessage.invocationId
previousConversation.parentMessageId = chatMessage.parentMessageId
previousConversation.conversationSignature = chatMessage.conversationSignature
previousConversation.bingToken = chatMessage.bingToken
if (Config.toneStyle !== 'Sydney' && Config.toneStyle !== 'Custom') {
previousConversation.bingToken = chatMessage.bingToken
} else {
previousConversation.bingToken = ''
}
} else {
previousConversation.parentMessageId = chatMessage.id
}
@ -996,16 +1007,24 @@ export class chatgpt extends plugin {
}
case 'bing': {
let bingToken = await redis.get('CHATGPT:BING_TOKEN')
// 负载均衡
if (!conversation.bingToken) {
const bingTokens = bingToken.split('|')
const select = Math.floor(Math.random() * bingTokens.length)
bingToken = bingTokens[select]
} else bingToken = conversation.bingToken
if (!bingToken) {
throw new Error('未绑定Bing Cookie请使用#chatgpt设置必应token命令绑定Bing Cookie')
}
const bingTokens = bingToken.split('|')
// 负载均衡
if (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom') {
// sydney下不需要保证同一token
const select = Math.floor(Math.random() * bingTokens.length)
bingToken = bingTokens[select]
} else {
// bing 下需要保证同一对话使用同一账号的token
if (!conversation.bingToken) {
const select = Math.floor(Math.random() * bingTokens.length)
bingToken = bingTokens[select]
} else if (bingTokens.indexOf(conversation.bingToken) > -1) {
bingToken = conversation.bingToken
}
}
let cookies
if (bingToken?.indexOf('=') > -1) {
cookies = bingToken