mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
使用chatgpt-api自带的超时机制,回复文字过多时使用图片发送 (#154)
* 修复引用转发,默认bing模式并发 * 开启stream增加稳定性 * fix: remove queue element only in non-bing mode * 使用chatgpt-api自带的超时逻辑,文字过多时启动切换到图片输出防止被吞 * Update chat.js --------- Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
545c8fd483
commit
2ca69ed758
2 changed files with 20 additions and 6 deletions
22
apps/chat.js
22
apps/chat.js
|
|
@ -327,11 +327,16 @@ export class chatgpt extends plugin {
|
||||||
/** 最后回复消息 */
|
/** 最后回复消息 */
|
||||||
await e.runtime.render('chatgpt-plugin', 'content/index', { content: converted, prompt, senderName: e.sender.nickname })
|
await e.runtime.render('chatgpt-plugin', 'content/index', { content: converted, prompt, senderName: e.sender.nickname })
|
||||||
} else {
|
} else {
|
||||||
|
if (response.length > 1000 ) {
|
||||||
|
// 文字过多时自动切换到图片模式输出
|
||||||
|
let converted = converter.makeHtml(response)
|
||||||
|
await e.runtime.render('chatgpt-plugin', 'content/index', { content: converted, prompt, quote: chatMessage.quote, senderName: e.sender.nickname })
|
||||||
|
} else
|
||||||
await this.reply(`${response}`, e.isGroup)
|
await this.reply(`${response}`, e.isGroup)
|
||||||
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.trim() != '') {
|
||||||
quotemessage.push(`${item}\n`)
|
quotemessage.push(`${item}\n`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -418,19 +423,28 @@ export class chatgpt extends plugin {
|
||||||
debug: Config.debug
|
debug: Config.debug
|
||||||
})
|
})
|
||||||
let response
|
let response
|
||||||
|
let reply = ''
|
||||||
try {
|
try {
|
||||||
|
/* bingAIClient中设置了无响应2分钟超时,应该不用单独处理了,后续看情况可以删掉这些代码
|
||||||
const responseP = new Promise(
|
const responseP = new Promise(
|
||||||
async (resolve, reject) => {
|
async (resolve, reject) => {
|
||||||
let bingResponse = await bingAIClient.sendMessage(prompt, conversation || {},(token) => {
|
let bingResponse = await bingAIClient.sendMessage(prompt, conversation || {},(token) => {
|
||||||
console.debug(token);
|
reply += token
|
||||||
})
|
})
|
||||||
return resolve(bingResponse)
|
return resolve(bingResponse)
|
||||||
})
|
})
|
||||||
response = await pTimeout(responseP, {
|
response = await pTimeout(responseP, {
|
||||||
milliseconds: Config.bingTimeoutMs,
|
milliseconds: Config.bingTimeoutMs,
|
||||||
message: 'Bing timed out waiting for response'
|
message: reply != '' ? `${reply}\n不行了,我的大脑过载了,处理不过来了!` : '必应的小脑子不好使了,不知道怎么回答!'
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
response = await bingAIClient.sendMessage(prompt, conversation || {}, (token) => {
|
||||||
|
reply += token
|
||||||
})
|
})
|
||||||
if (response.details.adaptiveCards?.[0]?.body?.[0]?.text?.trim()) {
|
if (response.details.adaptiveCards?.[0]?.body?.[0]?.text?.trim()) {
|
||||||
|
if (response.response === undefined) {
|
||||||
|
response.response = response.details.adaptiveCards?.[0]?.body?.[0]?.text?.trim()
|
||||||
|
}
|
||||||
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, '')
|
||||||
})
|
})
|
||||||
|
|
@ -444,7 +458,7 @@ export class chatgpt extends plugin {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
const message = error?.message || error?.data?.message || '与Bing通信时出错.'
|
const message = error?.message || error?.data?.message || '与Bing通信时出错.'
|
||||||
return {
|
return {
|
||||||
text: message
|
text: message === 'Timed out waiting for response. Try enabling debug mode to see more information.' ? (reply != '' ? `${reply}\n不行了,我的大脑过载了,处理不过来了!` : '必应的小脑瓜不好使了,不知道怎么回答!') : message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -60,11 +60,11 @@ export const Config = {
|
||||||
'2captchaToken': '',
|
'2captchaToken': '',
|
||||||
// http或socks5代理
|
// http或socks5代理
|
||||||
proxy: PROXY,
|
proxy: PROXY,
|
||||||
debug: true,
|
debug: false,
|
||||||
// 各个地方的默认超时时间
|
// 各个地方的默认超时时间
|
||||||
defaultTimeoutMs: 120000,
|
defaultTimeoutMs: 120000,
|
||||||
// bing默认超时时间,bing太慢了有的时候
|
// bing默认超时时间,bing太慢了有的时候
|
||||||
bingTimeoutMs: 360000,
|
//bingTimeoutMs: 360000,
|
||||||
// 浏览器默认超时,浏览器可能需要更高的超时时间
|
// 浏览器默认超时,浏览器可能需要更高的超时时间
|
||||||
chromeTimeoutMS: 120000
|
chromeTimeoutMS: 120000
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue