mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: 取消图片模式的循环Continue
This commit is contained in:
parent
a2c4d516a3
commit
0365a3a09f
1 changed files with 16 additions and 61 deletions
55
apps/chat.js
55
apps/chat.js
|
|
@ -404,53 +404,8 @@ export class chatgpt extends plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (userSetting.usePicture) {
|
if (userSetting.usePicture) {
|
||||||
let endTokens = ['.', '。', '……', '!', '!', ']', ')', ')', '】', '?', '?', '~', '"', "'"]
|
// todo use next api of chatgpt to complete incomplete respoonse
|
||||||
let maxTries = use === 'api3' ? 3 : 0
|
response = new Buffer.from(response).toString('base64')
|
||||||
while (maxTries >= 0 && !endTokens.find(token => response.trimEnd().endsWith(token))) {
|
|
||||||
maxTries--
|
|
||||||
// while (!response.trimEnd().endsWith('.') && !response.trimEnd().endsWith('。') && !response.trimEnd().endsWith('……') &&
|
|
||||||
// !response.trimEnd().endsWith('!') && !response.trimEnd().endsWith('!') && !response.trimEnd().endsWith(']') && !response.trimEnd().endsWith('】')
|
|
||||||
// ) {
|
|
||||||
await this.reply('内容有点多,我正在奋笔疾书,请再等一会', true, { recallMsg: 5 })
|
|
||||||
let responseAppend = await this.sendMessage('Continue', conversation, use, e)
|
|
||||||
if (use !== 'api3') {
|
|
||||||
previousConversation.conversation = {
|
|
||||||
conversationId: responseAppend.conversationId
|
|
||||||
}
|
|
||||||
if (use === 'bing') {
|
|
||||||
previousConversation.clientId = responseAppend.clientId
|
|
||||||
previousConversation.invocationId = responseAppend.invocationId
|
|
||||||
previousConversation.conversationSignature = responseAppend.conversationSignature
|
|
||||||
} else {
|
|
||||||
// 或许这样切换回来不会404?
|
|
||||||
previousConversation.conversation.parentMessageId = responseAppend.id
|
|
||||||
}
|
|
||||||
console.log(responseAppend)
|
|
||||||
previousConversation.num = previousConversation.num + 1
|
|
||||||
await redis.set(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`, JSON.stringify(previousConversation), CONVERSATION_PRESERVE_TIME > 0 ? { EX: CONVERSATION_PRESERVE_TIME } : {})
|
|
||||||
}
|
|
||||||
let responseAppendText = responseAppend?.text
|
|
||||||
|
|
||||||
// console.log(responseAppend)
|
|
||||||
// 检索是否有屏蔽词
|
|
||||||
const blockWord = blockWords.find(word => responseAppendText.toLowerCase().includes(word.toLowerCase()))
|
|
||||||
if (blockWord) {
|
|
||||||
await this.reply('返回内容存在敏感词,我不想回答你', true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (responseAppendText.indexOf('conversation') > -1 || responseAppendText.startsWith("I'm sorry")) {
|
|
||||||
logger.warn('chatgpt might forget what it had said')
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
response = response + responseAppendText
|
|
||||||
}
|
|
||||||
// logger.info(response)
|
|
||||||
// markdown转为html
|
|
||||||
// todo部分数学公式可能还有问题
|
|
||||||
|
|
||||||
/** 最后回复消息 */
|
|
||||||
response = new Buffer.from(response).toString("base64")
|
|
||||||
if (Config.showQRCode) {
|
if (Config.showQRCode) {
|
||||||
let cacheres = await fetch(`${Config.cacheUrl}/cache`, {
|
let cacheres = await fetch(`${Config.cacheUrl}/cache`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
@ -472,7 +427,7 @@ export class chatgpt extends plugin {
|
||||||
if (cacheres.ok) {
|
if (cacheres.ok) {
|
||||||
cache = Object.assign({}, cache, await cacheres.json())
|
cache = Object.assign({}, cache, await cacheres.json())
|
||||||
}
|
}
|
||||||
await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt: escapeHtml(prompt), senderName: e.sender.nickname, cache: cache })
|
await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt: escapeHtml(prompt), senderName: e.sender.nickname, cache })
|
||||||
} else {
|
} else {
|
||||||
await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt: escapeHtml(prompt), senderName: e.sender.nickname, cache: { file: '', cacheUrl: Config.cacheUrl } })
|
await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt: escapeHtml(prompt), senderName: e.sender.nickname, cache: { file: '', cacheUrl: Config.cacheUrl } })
|
||||||
}
|
}
|
||||||
|
|
@ -486,7 +441,7 @@ export class chatgpt extends plugin {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold) {
|
if (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold) {
|
||||||
response = new Buffer.from(response).toString("base64")
|
response = new Buffer.from(response).toString('base64')
|
||||||
// 文字过多时自动切换到图片模式输出
|
// 文字过多时自动切换到图片模式输出
|
||||||
if (Config.showQRCode) {
|
if (Config.showQRCode) {
|
||||||
let cacheres = await fetch(`${Config.cacheUrl}/cache`, {
|
let cacheres = await fetch(`${Config.cacheUrl}/cache`, {
|
||||||
|
|
@ -509,7 +464,7 @@ export class chatgpt extends plugin {
|
||||||
if (cacheres.ok) {
|
if (cacheres.ok) {
|
||||||
cache = Object.assign({}, cache, await cacheres.json())
|
cache = Object.assign({}, cache, await cacheres.json())
|
||||||
}
|
}
|
||||||
await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt: escapeHtml(prompt), senderName: e.sender.nickname, quote: quotemessage.length > 0 , quotes: quotemessage, cache: cache })
|
await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt: escapeHtml(prompt), senderName: e.sender.nickname, quote: quotemessage.length > 0, quotes: quotemessage, cache })
|
||||||
} else {
|
} else {
|
||||||
await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt: escapeHtml(prompt), senderName: e.sender.nickname, quote: quotemessage.length > 0, quotes: quotemessage, cache: { file: '', cacheUrl: Config.cacheUrl } })
|
await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt: escapeHtml(prompt), senderName: e.sender.nickname, quote: quotemessage.length > 0, quotes: quotemessage, cache: { file: '', cacheUrl: Config.cacheUrl } })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue