|
|
|
|
@ -113,13 +113,70 @@ const handleSend = async () => {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// 构造人设prompt
|
|
|
|
|
// 构造人设 prompt(与 OC 问卷字段一一对应,确保 AI 能获取完整人设)
|
|
|
|
|
let persona = ''
|
|
|
|
|
if (props.activeContact) {
|
|
|
|
|
persona += `你是${props.activeContact.name},`;
|
|
|
|
|
if (props.activeContact.occupation) persona += `职业:${props.activeContact.occupation},`;
|
|
|
|
|
if (props.activeContact.personality && props.activeContact.personality.length) persona += `性格:${Array.isArray(props.activeContact.personality) ? props.activeContact.personality.join('、') : props.activeContact.personality},`;
|
|
|
|
|
if (props.activeContact.bio) persona += `简介:${props.activeContact.bio},`;
|
|
|
|
|
const c = props.activeContact
|
|
|
|
|
const safe = (v) => (v === null || v === undefined) ? '' : String(v).replace(/\s+/g, ' ').trim()
|
|
|
|
|
const fmtList = (v) => Array.isArray(v) ? v.join('、') : (v ? safe(v) : '')
|
|
|
|
|
|
|
|
|
|
persona += `你是${safe(c.name) || '该角色'}。`;
|
|
|
|
|
|
|
|
|
|
// 以下字段按问卷顺序列出,标签使用中文与问卷保持一致
|
|
|
|
|
const fields = [
|
|
|
|
|
['性别', c.gender || (c.genderOther ? c.genderOther : '')],
|
|
|
|
|
['生日', c.birthday],
|
|
|
|
|
['年龄', c.age],
|
|
|
|
|
['种族', c.race],
|
|
|
|
|
['职业', c.occupation],
|
|
|
|
|
['发型与发色', c.hair],
|
|
|
|
|
['瞳色', c.eyeColor],
|
|
|
|
|
['身高', c.height],
|
|
|
|
|
['着装风格', c.clothes],
|
|
|
|
|
['标志性特征', c.feature],
|
|
|
|
|
['核心性格', fmtList(c.personality) || c.personalityOther],
|
|
|
|
|
['MBTI', c.mbti],
|
|
|
|
|
['优点', c.advantage],
|
|
|
|
|
['缺点', c.shortcoming],
|
|
|
|
|
['习惯性小动作', c.habit],
|
|
|
|
|
['口头禅', c.catchphrase],
|
|
|
|
|
['成长环境', c.growup],
|
|
|
|
|
['背景故事', c.story],
|
|
|
|
|
['秘密', c.secret],
|
|
|
|
|
['兴趣爱好', fmtList(c.hobbies)],
|
|
|
|
|
['喜欢的食物', c.foodLike],
|
|
|
|
|
['讨厌的东西', c.hate],
|
|
|
|
|
['理想生活方式', c.life],
|
|
|
|
|
['周末日常', c.weekend],
|
|
|
|
|
['社区主要活动', c.communityActivity],
|
|
|
|
|
['关系期待', fmtList(c.relation) || c.relationOther],
|
|
|
|
|
['头像URL', c.avatar]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
fields.forEach(([label, value]) => {
|
|
|
|
|
if (value || value === 0) {
|
|
|
|
|
persona += `${label}:${safe(value)};`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 社交圈与成就(作为附加信息)
|
|
|
|
|
if (c.socialCircle && c.socialCircle.length) persona += `社交圈:${c.socialCircle.slice(0,5).map(x => x.name || x).join('、')};`;
|
|
|
|
|
if (c.achievements && c.achievements.length) persona += `成就:${c.achievements.slice(0,5).join('、')};`;
|
|
|
|
|
|
|
|
|
|
// 今日行程简要(取当天日程并格式化为 时间-活动@地点)
|
|
|
|
|
try {
|
|
|
|
|
const now = new Date()
|
|
|
|
|
const todayStr = now.getFullYear() + '-' + String(now.getMonth()+1).padStart(2,'0') + '-' + String(now.getDate()).padStart(2,'0')
|
|
|
|
|
if (Array.isArray(c.schedule)) {
|
|
|
|
|
const todays = c.schedule.filter(s => String(s.date).startsWith(todayStr))
|
|
|
|
|
if (todays.length) {
|
|
|
|
|
const brief = todays.slice(0,6).map(s => `${s.time || '--:--'}-${(s.event||'').slice(0,20)}@${s.location||''}`)
|
|
|
|
|
persona += `今日日程(简要):${brief.join(';')};`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 共享用户信息给AI
|
|
|
|
|
if (currentUser.value && currentUser.value.nickname) {
|
|
|
|
|
@ -127,7 +184,7 @@ const handleSend = async () => {
|
|
|
|
|
if (currentUser.value.occupation) persona += `对方职业:${currentUser.value.occupation},`;
|
|
|
|
|
if (currentUser.value.hobbies) persona += `对方爱好:${currentUser.value.hobbies},`;
|
|
|
|
|
}
|
|
|
|
|
persona += '请用简洁、贴近生活的语气,只回复一句符合自己人设的聊天内容,不要多余解释。';
|
|
|
|
|
persona += '请用简洁、贴近生活的语气,只回复一句符合自己人设和性格的聊天内容,如果对方没说就不要刻意强调自己知晓对方的爱好,不要混淆对方和自己的爱好,回复的文本长度根据对方的语句进行调整,比如对方只是简单问候就可以简短回应,对于问题则可以以自身人设风格进行较为详细的解答。';
|
|
|
|
|
const prompt = `${persona}\n对方说:${userText}`;
|
|
|
|
|
const res = await axios.post(
|
|
|
|
|
'https://open.bigmodel.cn/api/paas/v4/chat/completions',
|
|
|
|
|
|