From 12dc262dfc3ca9eb99e1d73c49c640c33e6fd26e Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Thu, 30 Mar 2023 20:54:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dbing=E5=87=BA=E9=94=99?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E5=AF=B9=E8=AF=9D=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88=E5=A4=A7=E6=A6=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 33 ++++++++++++++++++++------------- utils/SydneyAIClient.js | 8 ++++---- utils/config.js | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index e4f7a93..7fb14db 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -22,7 +22,7 @@ import fetch from 'node-fetch' import { deleteConversation, getConversations, getLatestMessageIdByConversationId } from '../utils/conversation.js' import { convertSpeaker, generateAudio, speakers } from '../utils/tts.js' import ChatGLMClient from '../utils/chatglm.js' -import {convertFaces} from "../utils/face.js"; +import { convertFaces } from '../utils/face.js' try { await import('keyv') } catch (err) { @@ -729,7 +729,7 @@ export class chatgpt extends plugin { previousConversation.conversation = { conversationId: chatMessage.conversationId } - if (use === 'bing') { + if (use === 'bing' && !chatMessage.error) { previousConversation.clientId = chatMessage.clientId previousConversation.invocationId = chatMessage.invocationId previousConversation.parentMessageId = chatMessage.parentMessageId @@ -740,8 +740,11 @@ export class chatgpt extends plugin { if (Config.debug) { logger.info(chatMessage) } - previousConversation.num = previousConversation.num + 1 - await redis.set(key, JSON.stringify(previousConversation), Config.conversationPreserveTime > 0 ? { EX: Config.conversationPreserveTime } : {}) + if (!chatMessage.error) { + // 没错误的时候再更新,不然易出错就对话没了 + previousConversation.num = previousConversation.num + 1 + await redis.set(key, JSON.stringify(previousConversation), Config.conversationPreserveTime > 0 ? { EX: Config.conversationPreserveTime } : {}) + } } let response = chatMessage?.text let mood = 'blandness' @@ -760,7 +763,7 @@ export class chatgpt extends plugin { temp_response = completeJSON(response) temp_response = JSON.parse(temp_response) } catch (error) { - logger.error('数据格式错误',error) + logger.error('数据格式错误', error) } } if (temp_response.text) response = temp_response.text @@ -774,14 +777,14 @@ export class chatgpt extends plugin { await this.reply('返回内容存在敏感词,我不想回答你', true) return false } - //处理中断的代码区域 - const codeBlockCount = (response.match(/```/g) || []).length; - const shouldAddClosingBlock = codeBlockCount % 2 === 1 && !response.endsWith('```'); + // 处理中断的代码区域 + const codeBlockCount = (response.match(/```/g) || []).length + const shouldAddClosingBlock = codeBlockCount % 2 === 1 && !response.endsWith('```') if (shouldAddClosingBlock) { - response += '\n```'; + response += '\n```' } if (codeBlockCount && !shouldAddClosingBlock) { - response = response.replace(/```$/, '\n```'); + response = response.replace(/```$/, '\n```') } let quotemessage = [] @@ -958,7 +961,7 @@ export class chatgpt extends plugin { prompt: new Buffer.from(prompt).toString('base64'), senderName: e.sender.nickname, style: Config.toneStyle, - mood: mood, + mood, quote }, bing: use === 'bing', @@ -982,7 +985,7 @@ export class chatgpt extends plugin { quotes: quote, cache: cacheData, style: Config.toneStyle, - mood: mood, + mood, version }, { retType: Config.quoteReply ? 'base64' : '' }), e.isGroup && Config.quoteReply) } @@ -1104,7 +1107,11 @@ export class chatgpt extends plugin { } } while (retry > 0) if (errorMessage) { - return { text: errorMessage } + response = response || {} + return { + text: errorMessage, + error: true + } } else { return { text: response.response, diff --git a/utils/SydneyAIClient.js b/utils/SydneyAIClient.js index a8058b0..d58b8b1 100644 --- a/utils/SydneyAIClient.js +++ b/utils/SydneyAIClient.js @@ -286,8 +286,8 @@ export default class SydneyAIClient { previousMessages = invocationId === 0 ? [ { - 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.` : ''), + 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.' : ''), author: 'bot' }, { @@ -301,8 +301,8 @@ export default class SydneyAIClient { previousMessages = invocationId === 0 ? [ { - 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.` : ''), + 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.' : ''), author: 'bot' }, { diff --git a/utils/config.js b/utils/config.js index 0dcb060..a65f906 100644 --- a/utils/config.js +++ b/utils/config.js @@ -77,7 +77,7 @@ const defaultConfig = { maxNumUserMessagesInConversation: 20, sydneyApologyIgnored: true, enforceMaster: false, - version: 'v2.4.9' + version: 'v2.4.10' } const _path = process.cwd() let config = {}