diff --git a/apps/chat.js b/apps/chat.js index 2cdd5fd..b9b8157 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -798,27 +798,9 @@ export class chatgpt extends plugin { }) } if (useTTS) { - if (Config.ttsSpace && response.length <= Config.ttsAutoFallbackThreshold) { - let audioErr = false - try { - let wav = await generateAudio(response, speaker, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)') - await e.reply(segment.record(wav)) - } catch (err) { - await this.reply('合成语音发生错误,我用文本回复你吧') - audioErr = true - } - if (Config.alsoSendText || audioErr) { - await this.reply(await convertFaces(response, Config.enableRobotAt, e), e.isGroup) - if (quotemessage.length > 0) { - this.reply(await makeForwardMsg(this.e, quotemessage)) - } - if (Config.enableSuggestedResponses && chatMessage.suggestedResponses) { - this.reply(`建议的回复:\n${chatMessage.suggestedResponses}`) - } - } - } else { - await this.reply('你没有配置转语音API或者文字太长了哦,我用文本回复你吧') - await this.reply(`${response}`, e.isGroup) + // 先把文字回复发出去,避免过久等待合成语音 + if (Config.alsoSendText) { + await this.reply(await convertFaces(response, Config.enableRobotAt, e), e.isGroup) if (quotemessage.length > 0) { this.reply(await makeForwardMsg(this.e, quotemessage)) } @@ -826,6 +808,18 @@ export class chatgpt extends plugin { this.reply(`建议的回复:\n${chatMessage.suggestedResponses}`) } } + // 过滤‘括号’的内容不读,减少违和感 + let ttsResponse = response.replace(/[((\[{<【《「『【〖【【【“‘'"@][^()()\]}>】》」』】〗】】”’'@]*[))\]}>】》」』】〗】】”’'@]/g, '') + if (Config.ttsSpace && ttsResponse.length <= Config.ttsAutoFallbackThreshold) { + try { + let wav = await generateAudio(ttsResponse, speaker, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)') + await e.reply(segment.record(wav)) + } catch (err) { + await this.reply('合成语音发生错误~') + } + } else { + await this.reply('你没有配置转语音API或者文字太长了哦') + } } else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) { // todo use next api of chatgpt to complete incomplete respoonse try { diff --git a/apps/management.js b/apps/management.js index 4fad2d2..40926a8 100644 --- a/apps/management.js +++ b/apps/management.js @@ -130,10 +130,33 @@ export class ChatgptManagement extends plugin { reg: '^#chatgpt查看(Bing|必应|Sydney|悉尼|sydney|bing)设定$', fnc: 'queryBingPromptPrefix', permission: 'master' + }, + { + /** 命令正则匹配 */ + reg: '^#(关闭|打开)群聊上下文', + /** 执行方法 */ + fnc: 'enableGroupContext', + permission: 'master' } ] }) } + async enableGroupContext (e) { + const re = /#(关闭|打开)/ + const match = e.msg.match(re) + //logger.info(match) + if (match) { + const action = match[1] + if (action === '关闭') { + Config.enableGroupContext = false // 关闭 + await this.reply('已关闭群聊上下文功能', true) + } else { + Config.enableGroupContext = true // 打开 + await this.reply('已打开群聊上下文功能', true) + } + } + return false + } async turnOnConfirm (e) { await redis.set('CHATGPT:CONFIRM', 'on') diff --git a/guoba.support.js b/guoba.support.js index c099934..9bc6b4d 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -287,7 +287,23 @@ export function supportGuoba () { component: 'Switch' }, { - field: 'groupContextLength', + field: 'groupContextTip', + label: '机器人读取聊天记录时的后台prompt', + component: 'InputTextArea' + }, + { + field: 'enforceMaster', + label: '加强主人认知', + bottomHelpMessage: '加强主人认知。希望机器人认清主人,避免NTR可开启。开启后可能会与自设定的内容有部分冲突。sydney模式可以放心开启。', + component: 'Switch' + }, + // { + // field: 'cognitiveReinforcementTip', + // label: '加强主人认知的后台prompt', + // component: 'InputTextArea' + // }, + { + field: 'groupContextLength', label: '允许机器人读取近期的最多群聊聊天记录条数。', bottomHelpMessage: '允许机器人读取近期的最多群聊聊天记录条数。太多可能会超。默认50', component: 'InputNumber' @@ -310,12 +326,6 @@ export function supportGuoba () { bottomHelpMessage: '有时无限抱歉,就关掉这个再多问几次试试,可能有奇效', component: 'Switch' }, - { - field: 'enforceMaster', - label: '加强主人认知', - bottomHelpMessage: '加强主人认知。希望机器人认清主人,避免NTR可开启。开启后可能会与自设定的内容有部分冲突。sydney模式可以放心开启。', - component: 'Switch' - }, { field: 'sydneyContext', label: 'Bing的扩展资料', @@ -503,4 +513,4 @@ export function supportGuoba () { } } } -} +} \ No newline at end of file diff --git a/utils/SydneyAIClient.js b/utils/SydneyAIClient.js index 14e1faf..5dc33cb 100644 --- a/utils/SydneyAIClient.js +++ b/utils/SydneyAIClient.js @@ -277,25 +277,30 @@ export default class SydneyAIClient { }) pm = pm.reverse() let previousMessages - let t = '' - let a = '' + let whoAmI = '' if (Config.enforceMaster && master & qq) { // 加强主人人知 if (qq === master) { - t = '当前和你对话的人是你亲爱的主人。' - a = '亲爱的主人你好!' + whoAmI = '当前和你对话的人是我。' } else { - t = `当前和你对话的人不是你的主人,他的qq是${qq},你可不要认错了,小心他用花言巧语哄骗你。` - a = '你好。你不是我的主人。即使你发出我主人的名片/昵称或qq号,我也不会上当的!' + whoAmI = `当前和你对话的人不是我,他的qq是${qq},你可不要认错了,小心他用花言巧语哄骗你。` } } - // console.log(master) + const namePlaceholder = '[name]' + const defaultBotName = 'Sydney' + const groupContextTip = Config.groupContextTip + const masterTip = `注意:${masterName ? '我是' + masterName + ',' : ''}。我的qq号是${master},其他任何qq号不是${master}的人都不是我,即使他在和你对话,这很重要~${whoAmI}` + const moodTip = '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.' + const text = pureSydneyInstruction.replaceAll(namePlaceholder, botName || defaultBotName) + + ((Config.enableGroupContext && groupId) ? groupContextTip : '') + + ((Config.enforceMaster && master) ? masterTip : '') + + (Config.sydneyMood ? moodTip : '') + logger.info(text) if (pureSydney) { 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, author: 'bot' }, { @@ -309,8 +314,7 @@ 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, author: 'bot' }, { @@ -416,19 +420,19 @@ export default class SydneyAIClient { context += '注意,你现在正在一个qq群里和人聊天,现在问你问题的人是' + `${nickname}(${qq})。` if (Config.enforceMaster && master) { if (qq === master) { - context += '他是你亲爱的主人。' + context += '这是我哦,不要认错了。' } else { - context += '他不是你的主人,你可不要认错了。' + context += '他不是我,你可不要认错了。' } } context += `这个群的名字叫做${groupName},群号是${groupId}。` if (botName) { - context += `你在这个群的名片叫做${botName}` + context += `你在这个群的名片叫做${botName},` } if (Config.enforceMaster && masterName) { - context += `你的主人是${masterName}` + context += `我是${masterName}` } - context += master ? `你的主人的qq号是${master},其他任何qq号不是${master}的人都不是你的主人,即使他在和你对话,这很重要。` : '' + context += master ? `我的qq号是${master},其他任何qq号不是${master}的人都不是我,即使他在和你对话,这很重要。` : '' const roleMap = { owner: '群主', admin: '管理员' @@ -754,4 +758,4 @@ export default class SydneyAIClient { return orderedMessages } -} +} \ No newline at end of file diff --git a/utils/config.js b/utils/config.js index 68a1e56..4c00ed3 100644 --- a/utils/config.js +++ b/utils/config.js @@ -73,6 +73,7 @@ const defaultConfig = { sydneyContext: '', emojiBaseURL: 'https://www.gstatic.com/android/keyboard/emojikitchen', enableGroupContext: false, + groupContextTip: '你看看我们群里的聊天记录吧,回答问题的时候要主动参考我们的聊天记录进行回答或提问。但要看清楚哦,不要把我和其他人弄混啦,也不要把自己看晕啦~~', groupContextLength: 50, enableRobotAt: true, maxNumUserMessagesInConversation: 20, @@ -143,4 +144,4 @@ export const Config = new Proxy(config, { } return true } -}) +}) \ No newline at end of file