mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: 修复多token功能带来的一些影响
This commit is contained in:
parent
e93614ca35
commit
fd408586a8
2 changed files with 32 additions and 13 deletions
35
apps/chat.js
35
apps/chat.js
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Config } from '../utils/config.js'
|
|||
import { BingAIClient } from '@waylaidwanderer/chatgpt-api'
|
||||
import { exec } from 'child_process'
|
||||
import { checkPnpm, formatDuration, parseDuration } from '../utils/common.js'
|
||||
import SydneyAIClient from "../utils/SydneyAIClient.js";
|
||||
import SydneyAIClient from '../utils/SydneyAIClient.js'
|
||||
|
||||
export class ChatgptManagement extends plugin {
|
||||
constructor (e) {
|
||||
|
|
@ -168,7 +168,7 @@ export class ChatgptManagement extends plugin {
|
|||
await this.reply(`${tokens}`, true)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
async delBingAccessToken (e) {
|
||||
this.setContext('deleteBingToken')
|
||||
let tokens = await redis.get('CHATGPT:BING_TOKEN')
|
||||
|
|
@ -211,7 +211,7 @@ export class ChatgptManagement extends plugin {
|
|||
let bingToken = await redis.get('CHATGPT:BING_TOKEN')
|
||||
bingToken = bingToken.split('|')
|
||||
if (!bingToken.includes(token)) bingToken.push(token)
|
||||
bingToken = bingToken.filter (function (element) { return element !== '' })
|
||||
bingToken = bingToken.filter(function (element) { return element !== '' })
|
||||
token = bingToken.join('|')
|
||||
}
|
||||
await redis.set('CHATGPT:BING_TOKEN', token)
|
||||
|
|
@ -224,14 +224,14 @@ export class ChatgptManagement extends plugin {
|
|||
let bingToken = await redis.get('CHATGPT:BING_TOKEN')
|
||||
bingToken = bingToken.split('|')
|
||||
let tokenId = this.e.msg
|
||||
if (!bingToken[tokenId]) {
|
||||
if (bingToken[tokenId] === null || bingToken[tokenId] === undefined) {
|
||||
await this.reply('Token编号错误!', true)
|
||||
this.finish('deleteBingToken')
|
||||
return
|
||||
}
|
||||
const removeToken = bingToken[tokenId]
|
||||
bingToken.splice(tokenId, 1)
|
||||
bingToken = bingToken.filter (function (element) { return element !== '' })
|
||||
bingToken = bingToken.filter(function (element) { return element !== '' })
|
||||
let token = bingToken.join('|')
|
||||
await redis.set('CHATGPT:BING_TOKEN', token)
|
||||
await this.reply(`Token ${removeToken.substring(0, 5 / 2) + '...' + removeToken.substring(removeToken.length - 5 / 2, removeToken.length)} 移除成功`, true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue