mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +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
21
apps/chat.js
21
apps/chat.js
|
|
@ -201,7 +201,8 @@ export class chatgpt extends plugin {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const use = await redis.get('CHATGPT:USE')
|
||||||
|
if (use != 'bing') {
|
||||||
let randomId = uuid()
|
let randomId = uuid()
|
||||||
// 队列队尾插入,开始排队
|
// 队列队尾插入,开始排队
|
||||||
await redis.rPush('CHATGPT:CHAT_QUEUE', [randomId])
|
await redis.rPush('CHATGPT:CHAT_QUEUE', [randomId])
|
||||||
|
|
@ -226,7 +227,7 @@ export class chatgpt extends plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
logger.info(`chatgpt prompt: ${prompt}`)
|
logger.info(`chatgpt prompt: ${prompt}`)
|
||||||
// try {
|
// try {
|
||||||
// await this.chatGPTApi.init()
|
// await this.chatGPTApi.init()
|
||||||
|
|
@ -254,7 +255,6 @@ export class chatgpt extends plugin {
|
||||||
conversationSignature: previousConversation.conversationSignature
|
conversationSignature: previousConversation.conversationSignature
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const use = await redis.get('CHATGPT:USE')
|
|
||||||
try {
|
try {
|
||||||
if (Config.debug) {
|
if (Config.debug) {
|
||||||
logger.mark(conversation)
|
logger.mark(conversation)
|
||||||
|
|
@ -331,20 +331,25 @@ export class chatgpt extends plugin {
|
||||||
if (chatMessage?.quote) {
|
if (chatMessage?.quote) {
|
||||||
let quotemessage = []
|
let quotemessage = []
|
||||||
chatMessage.quote.forEach(function (item, index) {
|
chatMessage.quote.forEach(function (item, index) {
|
||||||
if (item) {
|
if (item != '') {
|
||||||
quotemessage.push(`${item}\n`)
|
quotemessage.push(`${item}\n`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if(quotemessage.length > 0)
|
||||||
this.reply(await makeForwardMsg(this.e, quotemessage))
|
this.reply(await makeForwardMsg(this.e, quotemessage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (use !== 'bing') {
|
||||||
// 移除队列首位,释放锁
|
// 移除队列首位,释放锁
|
||||||
await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
if (use !== 'bing') {
|
||||||
// 异常了也要腾地方(todo 大概率后面的也会异常,要不要一口气全杀了)
|
// 异常了也要腾地方(todo 大概率后面的也会异常,要不要一口气全杀了)
|
||||||
await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
||||||
await this.reply(`与OpenAI通信异常,请稍后重试:${e}`, true, { recallMsg: e.isGroup ? 10 : 0 })
|
}
|
||||||
|
await this.reply(`通信异常,请稍后重试:${e}`, true, { recallMsg: e.isGroup ? 10 : 0 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -411,7 +416,9 @@ export class chatgpt extends plugin {
|
||||||
try {
|
try {
|
||||||
const responseP = new Promise(
|
const responseP = new Promise(
|
||||||
async (resolve, reject) => {
|
async (resolve, reject) => {
|
||||||
let bingResponse = await bingAIClient.sendMessage(prompt, conversation || {})
|
let bingResponse = await bingAIClient.sendMessage(prompt, conversation || {},(token) => {
|
||||||
|
console.debug(token);
|
||||||
|
})
|
||||||
return resolve(bingResponse)
|
return resolve(bingResponse)
|
||||||
})
|
})
|
||||||
response = await pTimeout(responseP, {
|
response = await pTimeout(responseP, {
|
||||||
|
|
@ -422,7 +429,7 @@ export class chatgpt extends plugin {
|
||||||
response.response = response.response.replace(/\[\^[0-9]+\^\]/g, (str) => {
|
response.response = response.response.replace(/\[\^[0-9]+\^\]/g, (str) => {
|
||||||
return str.replace(/[/^]/g, '')
|
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) {
|
} catch (error) {
|
||||||
const code = error?.data?.code || 503
|
const code = error?.data?.code || 503
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue