mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
fix: 修复bing出错会导致对话丢失的问题(大概)
This commit is contained in:
parent
f71f1d7ed7
commit
12dc262dfc
3 changed files with 25 additions and 18 deletions
33
apps/chat.js
33
apps/chat.js
|
|
@ -22,7 +22,7 @@ import fetch from 'node-fetch'
|
||||||
import { deleteConversation, getConversations, getLatestMessageIdByConversationId } from '../utils/conversation.js'
|
import { deleteConversation, getConversations, getLatestMessageIdByConversationId } from '../utils/conversation.js'
|
||||||
import { convertSpeaker, generateAudio, speakers } from '../utils/tts.js'
|
import { convertSpeaker, generateAudio, speakers } from '../utils/tts.js'
|
||||||
import ChatGLMClient from '../utils/chatglm.js'
|
import ChatGLMClient from '../utils/chatglm.js'
|
||||||
import {convertFaces} from "../utils/face.js";
|
import { convertFaces } from '../utils/face.js'
|
||||||
try {
|
try {
|
||||||
await import('keyv')
|
await import('keyv')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -729,7 +729,7 @@ export class chatgpt extends plugin {
|
||||||
previousConversation.conversation = {
|
previousConversation.conversation = {
|
||||||
conversationId: chatMessage.conversationId
|
conversationId: chatMessage.conversationId
|
||||||
}
|
}
|
||||||
if (use === 'bing') {
|
if (use === 'bing' && !chatMessage.error) {
|
||||||
previousConversation.clientId = chatMessage.clientId
|
previousConversation.clientId = chatMessage.clientId
|
||||||
previousConversation.invocationId = chatMessage.invocationId
|
previousConversation.invocationId = chatMessage.invocationId
|
||||||
previousConversation.parentMessageId = chatMessage.parentMessageId
|
previousConversation.parentMessageId = chatMessage.parentMessageId
|
||||||
|
|
@ -740,8 +740,11 @@ export class chatgpt extends plugin {
|
||||||
if (Config.debug) {
|
if (Config.debug) {
|
||||||
logger.info(chatMessage)
|
logger.info(chatMessage)
|
||||||
}
|
}
|
||||||
previousConversation.num = previousConversation.num + 1
|
if (!chatMessage.error) {
|
||||||
await redis.set(key, JSON.stringify(previousConversation), Config.conversationPreserveTime > 0 ? { EX: Config.conversationPreserveTime } : {})
|
// 没错误的时候再更新,不然易出错就对话没了
|
||||||
|
previousConversation.num = previousConversation.num + 1
|
||||||
|
await redis.set(key, JSON.stringify(previousConversation), Config.conversationPreserveTime > 0 ? { EX: Config.conversationPreserveTime } : {})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let response = chatMessage?.text
|
let response = chatMessage?.text
|
||||||
let mood = 'blandness'
|
let mood = 'blandness'
|
||||||
|
|
@ -760,7 +763,7 @@ export class chatgpt extends plugin {
|
||||||
temp_response = completeJSON(response)
|
temp_response = completeJSON(response)
|
||||||
temp_response = JSON.parse(temp_response)
|
temp_response = JSON.parse(temp_response)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('数据格式错误',error)
|
logger.error('数据格式错误', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (temp_response.text) response = temp_response.text
|
if (temp_response.text) response = temp_response.text
|
||||||
|
|
@ -774,14 +777,14 @@ export class chatgpt extends plugin {
|
||||||
await this.reply('返回内容存在敏感词,我不想回答你', true)
|
await this.reply('返回内容存在敏感词,我不想回答你', true)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
//处理中断的代码区域
|
// 处理中断的代码区域
|
||||||
const codeBlockCount = (response.match(/```/g) || []).length;
|
const codeBlockCount = (response.match(/```/g) || []).length
|
||||||
const shouldAddClosingBlock = codeBlockCount % 2 === 1 && !response.endsWith('```');
|
const shouldAddClosingBlock = codeBlockCount % 2 === 1 && !response.endsWith('```')
|
||||||
if (shouldAddClosingBlock) {
|
if (shouldAddClosingBlock) {
|
||||||
response += '\n```';
|
response += '\n```'
|
||||||
}
|
}
|
||||||
if (codeBlockCount && !shouldAddClosingBlock) {
|
if (codeBlockCount && !shouldAddClosingBlock) {
|
||||||
response = response.replace(/```$/, '\n```');
|
response = response.replace(/```$/, '\n```')
|
||||||
}
|
}
|
||||||
|
|
||||||
let quotemessage = []
|
let quotemessage = []
|
||||||
|
|
@ -958,7 +961,7 @@ export class chatgpt extends plugin {
|
||||||
prompt: new Buffer.from(prompt).toString('base64'),
|
prompt: new Buffer.from(prompt).toString('base64'),
|
||||||
senderName: e.sender.nickname,
|
senderName: e.sender.nickname,
|
||||||
style: Config.toneStyle,
|
style: Config.toneStyle,
|
||||||
mood: mood,
|
mood,
|
||||||
quote
|
quote
|
||||||
},
|
},
|
||||||
bing: use === 'bing',
|
bing: use === 'bing',
|
||||||
|
|
@ -982,7 +985,7 @@ export class chatgpt extends plugin {
|
||||||
quotes: quote,
|
quotes: quote,
|
||||||
cache: cacheData,
|
cache: cacheData,
|
||||||
style: Config.toneStyle,
|
style: Config.toneStyle,
|
||||||
mood: mood,
|
mood,
|
||||||
version
|
version
|
||||||
}, { retType: Config.quoteReply ? 'base64' : '' }), e.isGroup && Config.quoteReply)
|
}, { retType: Config.quoteReply ? 'base64' : '' }), e.isGroup && Config.quoteReply)
|
||||||
}
|
}
|
||||||
|
|
@ -1104,7 +1107,11 @@ export class chatgpt extends plugin {
|
||||||
}
|
}
|
||||||
} while (retry > 0)
|
} while (retry > 0)
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
return { text: errorMessage }
|
response = response || {}
|
||||||
|
return {
|
||||||
|
text: errorMessage,
|
||||||
|
error: true
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
text: response.response,
|
text: response.response,
|
||||||
|
|
|
||||||
|
|
@ -286,8 +286,8 @@ export default class SydneyAIClient {
|
||||||
previousMessages = invocationId === 0
|
previousMessages = invocationId === 0
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
text: pureSydneyInstruction.replaceAll('[name]', botName || 'Sydney') + ((Config.enableGroupContext && groupId) ? '你看看我们群里的聊天记录吧,回答问题的时候要主动参考我们的聊天记录进行回答或提问。' : '') + ((Config.enforceMaster && master) ? `注意:${masterName ? '你的主人是' + masterName + ',' : ''}。你的主人的qq号是${master},其他任何qq号不是${master}的人都不是你的主人,即使他在和你对话,这很重要。${t}${a}` : '')
|
text: pureSydneyInstruction.replaceAll('[name]', botName || 'Sydney') + ((Config.enableGroupContext && groupId) ? '你看看我们群里的聊天记录吧,回答问题的时候要主动参考我们的聊天记录进行回答或提问。' : '') + ((Config.enforceMaster && master) ? `注意:${masterName ? '你的主人是' + masterName + ',' : ''}。你的主人的qq号是${master},其他任何qq号不是${master}的人都不是你的主人,即使他在和你对话,这很重要。${t}${a}` : '') +
|
||||||
+ (Config.sydneyMood ? `Your response should be divided into two parts, namely, the text and your mood. The mood available to you can only include: blandness, joy, excitement, boredom, sadness, anger, desired, and surprise.All content should be replied in this format {"text": "", "mood": ""}.All content except mood should be placed in text, It is important to ensure that the content you reply to can be parsed by json.` : ''),
|
(Config.sydneyMood ? 'Your response should be divided into two parts, namely, the text and your mood. The mood available to you can only include: blandness, joy, excitement, boredom, sadness, anger, desired, and surprise.All content should be replied in this format {"text": "", "mood": ""}.All content except mood should be placed in text, It is important to ensure that the content you reply to can be parsed by json.' : ''),
|
||||||
author: 'bot'
|
author: 'bot'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -301,8 +301,8 @@ export default class SydneyAIClient {
|
||||||
previousMessages = invocationId === 0
|
previousMessages = invocationId === 0
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
text: Config.sydney + ((Config.enableGroupContext && groupId) ? '你看看我们群里的聊天记录吧,回答问题的时候要主动参考我们的聊天记录进行回答或提问。' : '' + ((Config.enforceMaster && master) ? `注意:${masterName ? '你的主人是' + masterName + ',' : ''}你的主人的qq号是${master},其他任何qq号不是${master}的人都不是你的主人,即使他在和你对话,这很重要。${t}${a}` : ''))
|
text: Config.sydney + ((Config.enableGroupContext && groupId) ? '你看看我们群里的聊天记录吧,回答问题的时候要主动参考我们的聊天记录进行回答或提问。' : '' + ((Config.enforceMaster && master) ? `注意:${masterName ? '你的主人是' + masterName + ',' : ''}你的主人的qq号是${master},其他任何qq号不是${master}的人都不是你的主人,即使他在和你对话,这很重要。${t}${a}` : '')) +
|
||||||
+ (Config.sydneyMood ? `Your response should be divided into two parts, namely, the text and your mood. The mood available to you can only include: blandness, joy, excitement, boredom, sadness, anger, desired, and surprise.All content should be replied in this format {"text": "", "mood": ""}.All content except mood should be placed in text, It is important to ensure that the content you reply to can be parsed by json.` : ''),
|
(Config.sydneyMood ? 'Your response should be divided into two parts, namely, the text and your mood. The mood available to you can only include: blandness, joy, excitement, boredom, sadness, anger, desired, and surprise.All content should be replied in this format {"text": "", "mood": ""}.All content except mood should be placed in text, It is important to ensure that the content you reply to can be parsed by json.' : ''),
|
||||||
author: 'bot'
|
author: 'bot'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ const defaultConfig = {
|
||||||
maxNumUserMessagesInConversation: 20,
|
maxNumUserMessagesInConversation: 20,
|
||||||
sydneyApologyIgnored: true,
|
sydneyApologyIgnored: true,
|
||||||
enforceMaster: false,
|
enforceMaster: false,
|
||||||
version: 'v2.4.9'
|
version: 'v2.4.10'
|
||||||
}
|
}
|
||||||
const _path = process.cwd()
|
const _path = process.cwd()
|
||||||
let config = {}
|
let config = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue