mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
修复引用,为必应开启并发 (#151)
* 修复引用转发,默认bing模式并发 * 开启stream增加稳定性 * fix: remove queue element only in non-bing mode --------- Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
5237975fbd
commit
1296eccb48
1 changed files with 39 additions and 32 deletions
71
apps/chat.js
71
apps/chat.js
|
|
@ -201,32 +201,33 @@ export class chatgpt extends plugin {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
let randomId = uuid()
|
||||
// 队列队尾插入,开始排队
|
||||
await redis.rPush('CHATGPT:CHAT_QUEUE', [randomId])
|
||||
let confirm = await redis.get('CHATGPT:CONFIRM')
|
||||
let confirmOn = confirm === 'on'
|
||||
if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) {
|
||||
if (confirmOn) {
|
||||
await this.reply('我正在思考如何回复你,请稍等', true, { recallMsg: 8 })
|
||||
}
|
||||
} else {
|
||||
if (confirmOn) {
|
||||
let length = await redis.lLen('CHATGPT:CHAT_QUEUE') - 1
|
||||
await this.reply(`我正在思考如何回复你,请稍等,当前队列前方还有${length}个问题`, true, { recallMsg: 8 })
|
||||
logger.info(`chatgpt队列前方还有${length}个问题。管理员可通过#清空队列来强制清除所有等待的问题。`)
|
||||
}
|
||||
// 开始排队
|
||||
while (true) {
|
||||
if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) {
|
||||
break
|
||||
} else {
|
||||
await delay(1500)
|
||||
const use = await redis.get('CHATGPT:USE')
|
||||
if (use != 'bing') {
|
||||
let randomId = uuid()
|
||||
// 队列队尾插入,开始排队
|
||||
await redis.rPush('CHATGPT:CHAT_QUEUE', [randomId])
|
||||
let confirm = await redis.get('CHATGPT:CONFIRM')
|
||||
let confirmOn = confirm === 'on'
|
||||
if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) {
|
||||
if (confirmOn) {
|
||||
await this.reply('我正在思考如何回复你,请稍等', true, { recallMsg: 8 })
|
||||
}
|
||||
} else {
|
||||
if (confirmOn) {
|
||||
let length = await redis.lLen('CHATGPT:CHAT_QUEUE') - 1
|
||||
await this.reply(`我正在思考如何回复你,请稍等,当前队列前方还有${length}个问题`, true, { recallMsg: 8 })
|
||||
logger.info(`chatgpt队列前方还有${length}个问题。管理员可通过#清空队列来强制清除所有等待的问题。`)
|
||||
}
|
||||
// 开始排队
|
||||
while (true) {
|
||||
if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) {
|
||||
break
|
||||
} else {
|
||||
await delay(1500)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(`chatgpt prompt: ${prompt}`)
|
||||
// try {
|
||||
// await this.chatGPTApi.init()
|
||||
|
|
@ -254,7 +255,6 @@ export class chatgpt extends plugin {
|
|||
conversationSignature: previousConversation.conversationSignature
|
||||
}
|
||||
}
|
||||
const use = await redis.get('CHATGPT:USE')
|
||||
try {
|
||||
if (Config.debug) {
|
||||
logger.mark(conversation)
|
||||
|
|
@ -331,20 +331,25 @@ export class chatgpt extends plugin {
|
|||
if (chatMessage?.quote) {
|
||||
let quotemessage = []
|
||||
chatMessage.quote.forEach(function (item, index) {
|
||||
if (item) {
|
||||
if (item != '') {
|
||||
quotemessage.push(`${item}\n`)
|
||||
}
|
||||
})
|
||||
if(quotemessage.length > 0)
|
||||
this.reply(await makeForwardMsg(this.e, quotemessage))
|
||||
}
|
||||
}
|
||||
// 移除队列首位,释放锁
|
||||
await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
||||
if (use !== 'bing') {
|
||||
// 移除队列首位,释放锁
|
||||
await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(e)
|
||||
// 异常了也要腾地方(todo 大概率后面的也会异常,要不要一口气全杀了)
|
||||
await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
||||
await this.reply(`与OpenAI通信异常,请稍后重试:${e}`, true, { recallMsg: e.isGroup ? 10 : 0 })
|
||||
if (use !== 'bing') {
|
||||
// 异常了也要腾地方(todo 大概率后面的也会异常,要不要一口气全杀了)
|
||||
await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
||||
}
|
||||
await this.reply(`通信异常,请稍后重试:${e}`, true, { recallMsg: e.isGroup ? 10 : 0 })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -411,7 +416,9 @@ export class chatgpt extends plugin {
|
|||
try {
|
||||
const responseP = new Promise(
|
||||
async (resolve, reject) => {
|
||||
let bingResponse = await bingAIClient.sendMessage(prompt, conversation || {})
|
||||
let bingResponse = await bingAIClient.sendMessage(prompt, conversation || {},(token) => {
|
||||
console.debug(token);
|
||||
})
|
||||
return resolve(bingResponse)
|
||||
})
|
||||
response = await pTimeout(responseP, {
|
||||
|
|
@ -422,7 +429,7 @@ export class chatgpt extends plugin {
|
|||
response.response = response.response.replace(/\[\^[0-9]+\^\]/g, (str) => {
|
||||
return str.replace(/[/^]/g, '')
|
||||
})
|
||||
response.quote = response.details.adaptiveCards?.[0]?.body?.[0]?.text?.trim().replace(/\[\^[0-9]+\^\]/g, '').replace(response.response, '').split('\n')
|
||||
response.quote = response.details.adaptiveCards?.[0]?.body?.[0]?.text?.replace(/\[\^[0-9]+\^\]/g, '').replace(response.response, '').split('\n')
|
||||
}
|
||||
} catch (error) {
|
||||
const code = error?.data?.code || 503
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue