mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-12-05 15:41:56 +00:00
feat:优化细节
This commit is contained in:
parent
54dc165357
commit
064d05500a
@ -51,7 +51,7 @@
|
||||
},
|
||||
"?markdownRenderer": "Markdown渲染配置",
|
||||
"markdownRenderer": {
|
||||
"theme": "light",
|
||||
"theme": "dark",
|
||||
"fontSize": 14,
|
||||
"codeTheme": "github"
|
||||
},
|
||||
|
||||
@ -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)),一般用于提醒用户,不常用
|
||||
|
||||
@ -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<null|string>}
|
||||
*/
|
||||
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)}`;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ class OpenaiChat {
|
||||
});
|
||||
|
||||
const aiResponse = completion.choices[0].message.content;
|
||||
//logger.info(aiResponse);
|
||||
logger.info(aiResponse);
|
||||
return {
|
||||
success: true,
|
||||
aiResponse: aiResponse,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user