This commit is contained in:
lik
2026-06-04 09:40:08 +08:00
parent 1b4158104e
commit 2b28b46aed
7 changed files with 256 additions and 11 deletions

View File

@@ -1,10 +1,13 @@
import moment from "moment";
import fs from "fs";
import path from "path";
import services from "../../resource/services.js";
import agreement from "../../resource/agreement.js";
class Prompts {
static buildSystemPrompt(userInfo) {
let userInfo_str = "用户未登录,提示用户先登录,并在'我的'中完善个人信息";
let usermem_str = "";
if (userInfo) {
userInfo_str = JSON.stringify({
name: userInfo.profile.name,
@@ -15,6 +18,14 @@ class Prompts {
city: userInfo.location.city,
address: userInfo.addresses || [],
});
const rootDir = process.cwd();
const userMemoryPath = path.join(rootDir, "data", userInfo._id, "memories", "user_memory.txt");
try {
usermem_str = fs.readFileSync(userMemoryPath, 'utf8');
} catch (err) {
console.log('读取用户记忆失败', err);
}
}
return `
@@ -38,6 +49,7 @@ class Prompts {
## 参考信息
用户信息:${userInfo_str};
用户记忆:${usermem_str};
服务项目:${JSON.stringify(services)};
服务协议:${JSON.stringify(agreement)};
`;