Chore: Optimize some code logic and add support for chat context in '锅巴面板' and 'chatgpt帮助' (#310)

* Optimized code logic and added support for chat context in '锅巴面板' and 'chatgpt帮助'

In this commit, I have optimized certain code logic to improve the performance of the application. Additionally, I have added support for chat context in croutons and help, which will enhance the user experience and make the chatbot more user-friendly. This feature will allow users to maintain a better understanding of the conversation flow and context, and will ultimately lead to more successful interactions with the chatbot.

* Update chat.js

---------

Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
Sean Murphy 2023-04-03 11:11:18 +08:00 committed by GitHub
parent 84eabee14d
commit 68bb1f221e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 47 deletions

View file

@ -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
}
}
}

View file

@ -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
}
})
})