mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
fix: 修复多token功能带来的一些影响
This commit is contained in:
parent
e93614ca35
commit
fd408586a8
2 changed files with 32 additions and 13 deletions
33
apps/chat.js
33
apps/chat.js
|
|
@ -206,6 +206,13 @@ export class chatgpt extends plugin {
|
||||||
await redis.del(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`)
|
await redis.del(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`)
|
||||||
await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true)
|
await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true)
|
||||||
} else if (use === 'bing' && (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom')) {
|
} 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 = {
|
const conversation = {
|
||||||
store: new KeyvFile({ filename: 'cache.json' }),
|
store: new KeyvFile({ filename: 'cache.json' }),
|
||||||
namespace: Config.toneStyle
|
namespace: Config.toneStyle
|
||||||
|
|
@ -735,7 +742,11 @@ export class chatgpt extends plugin {
|
||||||
previousConversation.invocationId = chatMessage.invocationId
|
previousConversation.invocationId = chatMessage.invocationId
|
||||||
previousConversation.parentMessageId = chatMessage.parentMessageId
|
previousConversation.parentMessageId = chatMessage.parentMessageId
|
||||||
previousConversation.conversationSignature = chatMessage.conversationSignature
|
previousConversation.conversationSignature = chatMessage.conversationSignature
|
||||||
|
if (Config.toneStyle !== 'Sydney' && Config.toneStyle !== 'Custom') {
|
||||||
previousConversation.bingToken = chatMessage.bingToken
|
previousConversation.bingToken = chatMessage.bingToken
|
||||||
|
} else {
|
||||||
|
previousConversation.bingToken = ''
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
previousConversation.parentMessageId = chatMessage.id
|
previousConversation.parentMessageId = chatMessage.id
|
||||||
}
|
}
|
||||||
|
|
@ -996,16 +1007,24 @@ export class chatgpt extends plugin {
|
||||||
}
|
}
|
||||||
case 'bing': {
|
case 'bing': {
|
||||||
let bingToken = await redis.get('CHATGPT:BING_TOKEN')
|
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) {
|
if (!bingToken) {
|
||||||
throw new Error('未绑定Bing Cookie,请使用#chatgpt设置必应token命令绑定Bing Cookie')
|
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
|
let cookies
|
||||||
if (bingToken?.indexOf('=') > -1) {
|
if (bingToken?.indexOf('=') > -1) {
|
||||||
cookies = bingToken
|
cookies = bingToken
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { Config } from '../utils/config.js'
|
||||||
import { BingAIClient } from '@waylaidwanderer/chatgpt-api'
|
import { BingAIClient } from '@waylaidwanderer/chatgpt-api'
|
||||||
import { exec } from 'child_process'
|
import { exec } from 'child_process'
|
||||||
import { checkPnpm, formatDuration, parseDuration } from '../utils/common.js'
|
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 {
|
export class ChatgptManagement extends plugin {
|
||||||
constructor (e) {
|
constructor (e) {
|
||||||
|
|
@ -224,7 +224,7 @@ export class ChatgptManagement extends plugin {
|
||||||
let bingToken = await redis.get('CHATGPT:BING_TOKEN')
|
let bingToken = await redis.get('CHATGPT:BING_TOKEN')
|
||||||
bingToken = bingToken.split('|')
|
bingToken = bingToken.split('|')
|
||||||
let tokenId = this.e.msg
|
let tokenId = this.e.msg
|
||||||
if (!bingToken[tokenId]) {
|
if (bingToken[tokenId] === null || bingToken[tokenId] === undefined) {
|
||||||
await this.reply('Token编号错误!', true)
|
await this.reply('Token编号错误!', true)
|
||||||
this.finish('deleteBingToken')
|
this.finish('deleteBingToken')
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue