fix: matcher 提示词补 {conversation} 占位符

generateSummary 只替换 {conversation} 占位符,而 buildInstruction 没有它,
导致拼好的「聊天内容+候选角色」从没发给 LLM,全程幻觉。
补上占位符 + 收一下调试日志(不记录聊天原文)。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
SerenNoble 2026-06-28 20:33:31 +08:00
parent 7b2b520cf5
commit 0e229dffa6

View file

@ -122,6 +122,7 @@ public class PersonaMatcherServiceImpl implements PersonaMatcherService {
.filter(s -> s != null && !s.isBlank()) .filter(s -> s != null && !s.isBlank())
.collect(Collectors.joining("\n")); .collect(Collectors.joining("\n"));
String conversation = buildConversation(topics, candidates, cur); String conversation = buildConversation(topics, candidates, cur);
log.info("[persona-match] user={} 候选{}个 主题{}字符", userId, candidates.size(), topics.length());
String promptTemplate = buildInstruction(); String promptTemplate = buildInstruction();
String resp; String resp;
try { try {
@ -172,7 +173,8 @@ public class PersonaMatcherServiceImpl implements PersonaMatcherService {
private String buildInstruction() { private String buildInstruction() {
return "你是儿童陪伴角色匹配器。根据【孩子近期聊天】从【候选陪伴角色】的编号列表里选最贴合的一个。" return "你是儿童陪伴角色匹配器。根据【孩子近期聊天】从【候选陪伴角色】的编号列表里选最贴合的一个。"
+ "若【当前角色】已足够合适,务必保留当前(孩子需要稳定陪伴)。仅当另一角色明显更贴合时才换。" + "若【当前角色】已足够合适,务必保留当前(孩子需要稳定陪伴)。仅当另一角色明显更贴合时才换。\n\n"
+ "{conversation}\n\n"
+ "只返回JSON,不要多余文字:{\"choice\":选中角色的编号(整数),\"score\":0.0到1.0,\"reason\":\"一句话\"}"; + "只返回JSON,不要多余文字:{\"choice\":选中角色的编号(整数),\"score\":0.0到1.0,\"reason\":\"一句话\"}";
} }