mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-12-05 15:41:56 +00:00
✨ feat(aiCaller.js): add method to calculate time difference for memory timestamps in context introduction
This commit is contained in:
parent
134f068bec
commit
0dd31c9458
@ -96,6 +96,32 @@ class AiCaller {
|
|||||||
return fullPrompt;
|
return fullPrompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算时间差
|
||||||
|
* @param pastTime 过去时间戳
|
||||||
|
* @returns {string} 时间差字符串
|
||||||
|
*/
|
||||||
|
calculateTimeDifference(pastTime) {
|
||||||
|
const now = Date.now();
|
||||||
|
const diff = now - pastTime;
|
||||||
|
|
||||||
|
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
||||||
|
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||||||
|
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
||||||
|
|
||||||
|
let result = '';
|
||||||
|
if (days > 0) {
|
||||||
|
result += `${days}天`;
|
||||||
|
}
|
||||||
|
if (hours > 0) {
|
||||||
|
result += `${hours}小时`;
|
||||||
|
}
|
||||||
|
if (minutes > 0) {
|
||||||
|
result += `${minutes}分钟`;
|
||||||
|
}
|
||||||
|
return result || '刚刚';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统提示词
|
* 获取系统提示词
|
||||||
* @param {object} e 上下文事件对象
|
* @param {object} e 上下文事件对象
|
||||||
@ -140,7 +166,8 @@ class AiCaller {
|
|||||||
if (memories && memories.length > 0) {
|
if (memories && memories.length > 0) {
|
||||||
contextIntro += '你可能会用到的记忆,请按情况使用,如果不合语境请忽略,请结合记忆时间和当前时间智能判断:\n';
|
contextIntro += '你可能会用到的记忆,请按情况使用,如果不合语境请忽略,请结合记忆时间和当前时间智能判断:\n';
|
||||||
memories.forEach((memory, index) => {
|
memories.forEach((memory, index) => {
|
||||||
contextIntro += `${index + 1}. 关键词:${memory.keywords},内容:${memory.data},记忆创建时间:${memory.createdAt}\n`;
|
const timeDiff = this.calculateTimeDifference(memory.createdAt);
|
||||||
|
contextIntro += `${index + 1}. 关键词:${memory.keywords},内容:${memory.data},记忆创建时间:${memory.createdAt},距离现在:${timeDiff}\\n`;
|
||||||
});
|
});
|
||||||
contextIntro += '\n';
|
contextIntro += '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user