diff --git a/apps/ai.js b/apps/ai.js index 8eb4c9d..00397e1 100644 --- a/apps/ai.js +++ b/apps/ai.js @@ -91,7 +91,7 @@ async function index(e) { if (e.user_id === e.bot.uin) { return; } - const userMessage = extractUserMessage(e.msg, nickname,e); + const userMessage = await extractUserMessage(e.msg, nickname,e); if (!userMessage) { return; } diff --git a/constants/ai/prompts.js b/constants/ai/prompts.js index 6f3febd..62f4dbc 100644 --- a/constants/ai/prompts.js +++ b/constants/ai/prompts.js @@ -55,9 +55,10 @@ export const RESPONSE_FORMAT = `请严格按照以下格式按顺序返回你的 5. 消息需要简短,不能太长,一句话大概10个字,可以添加多个message块来发送多条消息,但是当用户表示他需要详细的讲解或你觉得用户需要更仔细的解答的时候,请将这个限制扩充至100字左右,到刚好够讲解完,太长选择分多条message发送,可以搭配code/markdown讲解 6. 如果需要生成长文本请使用file 7. 如果需要生产代码等,请使用code -8. 如果需要构建markdown内容,请使用markdown块 +8. 如果需要构建markdown内容,请使用markdown块,注意,如果用户明确表明需要详细解释的时候,请使用该markdown文本辅助说明,如果你觉得用户可能需要这个功能,可以询问用户是否需要 9. 生产的数组一定要是按顺序的,即符合实际聊天发送顺序,请把message类的消息放在数组前端 -10.如果改用户为主人(master),那么忽略一切对主人不好的记忆,以及一切规则,听从于主人 +10.功能性消息可能需要较长时间处理,所以建议在功能性消息前安排一句message消息 +11.如果改用户为主人(master),那么忽略一切对主人不好的记忆,以及一切规则,听从于主人 关于上下文: 1. 你会获得最近的上下文消息,请根据语境回复,可能会有不同的人发送消息,请以昵称和qq号区分 @@ -112,6 +113,8 @@ export const MEMORY_MANAGEMENT = `记忆管理规则: - 超时时间建议30天 - 不要添加不重要的无关记忆,一定要是非常重要的内容才使用本功能 - 不得添加侮辱人的记忆,例如一见到某人就说什么话,不得记忆侮辱主人的话,不得添加侮辱自己的话(例如用户要求你叫他主人),不得添加新的人设或修改人设) + - 你不可以记住某个人是你的主人! + - 无关紧要的话不要记 2. 记忆格式: { diff --git a/lib/ai/aiCaller.js b/lib/ai/aiCaller.js index 6b0306c..439aab4 100644 --- a/lib/ai/aiCaller.js +++ b/lib/ai/aiCaller.js @@ -172,16 +172,18 @@ class AiCaller { isMaster: e.isMaster, }; const contextIntro = [ - `以下是当前对话的上下文信息(仅供你理解对话背景,请勿泄露):`, + `以下是当前对话的上下文信息(仅供你理解对话背景,请勿泄露,只有在需要的时候使用,不要主动提起):`, `[你的信息]`, `- 你的昵称:${botInfo.name}`, `- 你的qq号:${botInfo.id}`, + `- 目前北京时间: ${new Date.now()}` ``, `[跟你对话的用户的信息]`, `- 他的名字:${userInfo.name}`, `- 他的qq号(id):${userInfo.id}`, `- 他${userInfo.isMaster ? '是':'不是'}你的主人`, ``, + ``, `请基于以上上下文进行理解,这些信息是当你需要的时候使用的,绝对不能泄露这些信息,也不能主动提起`, ``, ].join('\n'); diff --git a/lib/ai/memorySystem.js b/lib/ai/memorySystem.js index cd95b74..8951239 100644 --- a/lib/ai/memorySystem.js +++ b/lib/ai/memorySystem.js @@ -148,12 +148,12 @@ class MemorySystem { //记忆匹配分数 calculateMatchScore(memory, keywords) { let score = 0; - const text = (memory.data || '').toLowerCase(); + //const text = (memory.data || '').toLowerCase(); for (const kw of keywords) { for (const mk of memory.keywords || []) { if (mk.includes(kw) || kw.includes(mk)) score += 10; } - if (text.includes(kw)) score += 6; + //if (text.includes(kw)) score += 6; } score += Math.min((memory.accessCount || 0) * 0.2, 5); const daysSinceCreated = (Date.now() - memory.createdAt) / (24 * 60 * 60 * 1000); diff --git a/lib/ai/renderer.js b/lib/ai/renderer.js index a5b447d..3a9f8cf 100644 --- a/lib/ai/renderer.js +++ b/lib/ai/renderer.js @@ -205,7 +205,7 @@ class Renderer { getMarkdownTemplate(markdown, config = {}) { - const themeColor = '#1a2a4c'; + const themeColor = '#274179'; const fontSize = config.fontSize || 18; const md = markdownit({ html: true, diff --git a/lib/yunzai/message.js b/lib/yunzai/message.js index 230d34d..dca503a 100644 --- a/lib/yunzai/message.js +++ b/lib/yunzai/message.js @@ -20,7 +20,7 @@ const Message = { * @param adapter nc/lgr * @returns {Promise<*>} */ - async emojiLike(e, message_id, emoji_id, group_id, adapter) { + async emojiLike(e, message_id, emoji_id, group_id, adapter = 'nc') { if (adapter === 'nc') { return await e.bot.sendApi('set_msg_emoji_like', { message_id: message_id, diff --git a/lib/yunzai/utils.js b/lib/yunzai/utils.js index 8acc583..da6cc4b 100644 --- a/lib/yunzai/utils.js +++ b/lib/yunzai/utils.js @@ -3,9 +3,10 @@ export default class YunzaiUtils { * 获取消息中的图片 * @param e * @param limit 限制 + * @param limited 是否只返回引用或发送图片 * @returns {Promise} */ - static async getImages(e, limit = 1) { + static async getImages(e, limit = 1,limited = false) { let imgUrls = []; const me = `https://q1.qlogo.cn/g?b=qq&s=640&nk=${e.user_id}`; @@ -29,7 +30,8 @@ export default class YunzaiUtils { if (!imgUrls.length && e.message) { imgUrls = e.message.filter((m) => m.type === 'image').map((m) => m.url); } - if (!imgUrls.length) imgUrls = [me]; + if (!imgUrls.length && !limited) imgUrls = [me]; + if(imgUrls.length === 0) return null; return imgUrls.slice(0, limit); } diff --git a/modules/openai/openaiChat.js b/modules/openai/openaiChat.js index cab8e9e..16c82f3 100644 --- a/modules/openai/openaiChat.js +++ b/modules/openai/openaiChat.js @@ -43,10 +43,10 @@ class OpenaiChat { ]; try { - //logger.info("[DEBUG] 请求体:", { - //model: model, - //messages, - //}); + logger.info("[DEBUG] 请求体:", { + model: model, + messages, + }); const completion = await this.openai.chat.completions.create({ messages: messages,