From 064d05500a1ae23931ddad5c04a2286759d0e6e9 Mon Sep 17 00:00:00 2001 From: Jerrypluay Date: Sun, 19 Oct 2025 00:07:00 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BC=98=E5=8C=96=E7=BB=86?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/ai.json | 2 +- constants/ai/prompts.js | 2 +- lib/ai/memorySystem.js | 36 ++++++------------------------------ modules/openai/openaiChat.js | 2 +- 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/config/ai.json b/config/ai.json index 23dbb26..b6a233d 100644 --- a/config/ai.json +++ b/config/ai.json @@ -51,7 +51,7 @@ }, "?markdownRenderer": "Markdown渲染配置", "markdownRenderer": { - "theme": "light", + "theme": "dark", "fontSize": 14, "codeTheme": "github" }, diff --git a/constants/ai/prompts.js b/constants/ai/prompts.js index d663759..af61793 100644 --- a/constants/ai/prompts.js +++ b/constants/ai/prompts.js @@ -33,7 +33,7 @@ export const RESPONSE_FORMAT = `请严格按照以下格式按顺序返回你的 支持的消息类型(type): - message(必须,其他均为可选): 普通文本消息,请将长句子分成多个message块返回(如果有多句话),data:回复内容,at:是否在发送本条消息的时候提醒用户,一般只在需要让用户注意的时候为true,quote:是否引用用户的问题,一般只需要在回答用户问题或第一条回复或需要用到用户问题的时候为true -- code: 代码块(会自动渲染为高亮图片,支持language参数指定编程语言) +- code: 代码块(会自动渲染为高亮图片,必须有language参数指定编程语言) - markdown: 需要渲染的markdown内容(会自动渲染为图片) - meme: 表情包(data值为情绪名称:angry、bye、confused、default、good、goodmorning、goodnight、happy、sad、shy、sorry、surprise),请根据聊天语境灵活选择需不需要表情包,如果感觉语境尴尬或需要表情包,那么发送一个default值的表情包,其他情绪的表情包按照当前你的情绪按需选择,注意:并不是每个聊天都需要有表情包,并且一次聊天最多回复一个表情包 - at: @某人(需要提供id,被at人qq号(number)),一般用于提醒用户,不常用 diff --git a/lib/ai/memorySystem.js b/lib/ai/memorySystem.js index f11f894..02fef21 100644 --- a/lib/ai/memorySystem.js +++ b/lib/ai/memorySystem.js @@ -5,8 +5,8 @@ import path from 'path'; class MemorySystem { constructor() { this.baseDir = path.join(process.cwd(), 'data', 'crystelf', 'memories'); - this.memories = new Map(); // 内存中的记忆存储 - this.defaultTimeout = 30; // 默认超时时间(天) + this.memories = new Map(); + this.defaultTimeout = 30; } async init() { @@ -28,7 +28,7 @@ class MemorySystem { const groupDirs = fs.readdirSync(this.baseDir); for (const groupId of groupDirs) { - const groupPath = path.join(this.baseDir, groupId); + const groupPath = path.join(this.baseDir, String(groupId)); if (!fs.statSync(groupPath).isDirectory()) continue; const userFiles = fs.readdirSync(groupPath); @@ -51,8 +51,8 @@ class MemorySystem { async saveMemories(groupId, userId) { try { - const groupPath = path.join(this.baseDir, groupId); - const filePath = path.join(groupPath, `${userId}.json`); + const groupPath = path.join(this.baseDir, String(groupId)); + const filePath = path.join(groupPath, `${String(userId)}.json`); if (!fs.existsSync(groupPath)) { fs.mkdirSync(groupPath, { recursive: true }); } @@ -72,15 +72,6 @@ class MemorySystem { } } - /** - * 添加记忆 - * @param groupId 群聊id - * @param userId 用户id - * @param data 内容 - * @param keywords 关键词 - * @param timeout 超时时间 - * @returns {Promise} - */ async addMemory(groupId, userId, data, keywords = [], timeout = null) { try { const memoryId = this.generateMemoryId(); @@ -105,13 +96,6 @@ class MemorySystem { } } - /** - * 搜索记忆 - * @param userId 用户id - * @param keywords 关键词 - * @param limit 数量限制 - * @returns {Promise<*[]>} - */ async searchMemories(userId, keywords = [], limit = 10) { try { const results = []; @@ -120,7 +104,7 @@ class MemorySystem { if (keywords.length === 1 && keywords[0].length > 6) { searchText = keywords[0].toLowerCase(); const words = searchText.match(/[\u4e00-\u9fa5]{1,2}|[a-zA-Z0-9]+/g) || []; - keywords = Array.from(new Set(words.filter(w => w.length > 1))); // 去重+过滤过短词 + keywords = Array.from(new Set(words.filter(w => w.length > 1))); } const userMemories = []; for (const [key, memory] of this.memories) { @@ -162,7 +146,6 @@ class MemorySystem { } } - calculateRelevance(memory, keywords) { let score = 0; for (const keyword of keywords) { @@ -179,9 +162,6 @@ class MemorySystem { return score; } - /** - * 清理过期记忆 - */ async cleanExpiredMemories() { try { const now = Date.now(); @@ -204,10 +184,6 @@ class MemorySystem { } } - /** - * 生成记忆ID - * @returns {string} - */ generateMemoryId() { return `mem_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; } diff --git a/modules/openai/openaiChat.js b/modules/openai/openaiChat.js index 59e56cc..cab8e9e 100644 --- a/modules/openai/openaiChat.js +++ b/modules/openai/openaiChat.js @@ -59,7 +59,7 @@ class OpenaiChat { }); const aiResponse = completion.choices[0].message.content; - //logger.info(aiResponse); + logger.info(aiResponse); return { success: true, aiResponse: aiResponse,