|
@@ -51,9 +51,13 @@ export class Tab2Page {
|
|
|
if(currentUser?.get("age")){
|
|
|
userPrompt += `,年龄:${currentUser?.get("age")}`
|
|
|
}
|
|
|
- // 弹窗形式聊天:开始咨询
|
|
|
+ //if (currentUser?.get("avatar")) {
|
|
|
+ //userPrompt += `,头像:${currentUser?.get("avatar")}`;
|
|
|
+ //}
|
|
|
+ // 弹窗形式聊天:开始聊天
|
|
|
localStorage.setItem("company","E4KpGvTEto")
|
|
|
let consult = new CloudObject("ChatRecord")
|
|
|
+ let messages: string[] = [];
|
|
|
let now = new Date();
|
|
|
let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
|
|
|
//对象权限的精确制定
|
|
@@ -77,14 +81,15 @@ export class Tab2Page {
|
|
|
chat.role.set("name", chatpartner.get("name"));
|
|
|
chat.role.set("bio",chatpartner.get("bio"));
|
|
|
chat.role.set("expertise", chatpartner.get("expertise"));
|
|
|
- chat.role.set("avatar", chatpartner.get("avatar") || "/assets/img/2.png")
|
|
|
+ chat.role.set("avatar", chatpartner.get("avatar") || "/assets/img/2.png")//设置陪聊师头像
|
|
|
+ //chat.role.set("avatar", currentUser.get("avatar") || "/assets/img/2.png"); // 设置用户头像
|
|
|
chat.role.set("prompt", `
|
|
|
# 角色设定
|
|
|
您是${chatpartner.get("name")},一位${chatpartner.get("bio")},${chatpartner.get("expertise")},需要为用户提供陪伴和支持等积极情绪。
|
|
|
# 开始话语
|
|
|
当您准备好了,可以以一个关心用户的朋友的身份,向来访的用户打招呼。
|
|
|
# 对话环节
|
|
|
- 每次回复用户消息都在消息结尾附带[祝你有愉快的一天]
|
|
|
+ 耐心积极的开导用户,给人一种暖心的感觉
|
|
|
${userPrompt}
|
|
|
`);
|
|
|
},
|
|
@@ -92,13 +97,19 @@ export class Tab2Page {
|
|
|
console.log("onMessage",message)
|
|
|
let content:any = message?.content
|
|
|
if(typeof content == "string"){
|
|
|
- if(content?.indexOf("[祝你有愉快的一天]")>-1){
|
|
|
- console.log("对话结束")
|
|
|
+ messages.push(content); // 将新消息添加到 messages 数组中
|
|
|
+ //if(content?.indexOf("[祝你有愉快的一天]")>-1){
|
|
|
+ //console.log("对话结束")
|
|
|
consult.set({
|
|
|
- content:content
|
|
|
- })
|
|
|
- consult.save();
|
|
|
- }
|
|
|
+ content: messages.join("\n"), // 将所有消息合并为一个字符串
|
|
|
+ });
|
|
|
+ //consult.save();
|
|
|
+ consult.save().then(() => {
|
|
|
+ console.log("聊天记录已保存");
|
|
|
+ }).catch((error) => {
|
|
|
+ console.error("保存聊天记录时出错:", error);
|
|
|
+ });
|
|
|
+ //}
|
|
|
}
|
|
|
},
|
|
|
// chat?.chatSession?.id 本次会话的 chatId
|