add group-aware persona bias for xiaoniu bot
This commit is contained in:
@@ -8,6 +8,7 @@ class ContextBuilder:
|
||||
self,
|
||||
*,
|
||||
room_id: str,
|
||||
group_profile: Dict,
|
||||
sender: str,
|
||||
sender_name: str,
|
||||
content: str,
|
||||
@@ -25,7 +26,7 @@ class ContextBuilder:
|
||||
if msg_content:
|
||||
recent_lines.append(f"{msg_sender}: {msg_content}")
|
||||
return {
|
||||
"group_profile": {"room_id": room_id},
|
||||
"group_profile": group_profile or {"room_id": room_id},
|
||||
"speaker_profile": {
|
||||
"wxid": sender,
|
||||
"display_name": sender_name,
|
||||
@@ -38,6 +39,7 @@ class ContextBuilder:
|
||||
"flow_state": flow_state,
|
||||
"memory_prompt": self._build_member_memory_prompt(member_context),
|
||||
"vector_memory_prompt": self._build_vector_memory_prompt(vector_memories),
|
||||
"group_profile_prompt": self._build_group_profile_prompt(group_profile or {}),
|
||||
"current_message": f"{sender_name}: {content}",
|
||||
}
|
||||
|
||||
@@ -69,3 +71,45 @@ class ContextBuilder:
|
||||
if summary:
|
||||
lines.append(f"[{memory_type}] {summary}")
|
||||
return "\n".join(lines)
|
||||
|
||||
@staticmethod
|
||||
def _build_group_profile_prompt(group_profile: Dict) -> str:
|
||||
if not group_profile:
|
||||
return "当前群没有特殊知识域限制。"
|
||||
focus = ", ".join(group_profile.get("knowledge_focus", [])[:6])
|
||||
boundaries = ", ".join(group_profile.get("topic_boundaries", [])[:6])
|
||||
summary = str(group_profile.get("group_memory_summary", "") or "").replace("\n", " ").strip()
|
||||
if len(summary) > 120:
|
||||
summary = summary[:117] + "..."
|
||||
lines = [
|
||||
f"群模式:{group_profile.get('mode', 'social')}",
|
||||
f"知识域:{group_profile.get('knowledge_domain', 'general')}",
|
||||
f"配置知识域:{group_profile.get('configured_domain', 'general')}",
|
||||
f"历史推断知识域:{group_profile.get('group_memory_domain', 'general')}",
|
||||
f"回答风格:{group_profile.get('reply_style', '自然短句')}",
|
||||
f"互动调性:{group_profile.get('interaction_tone', '自然群友感')}",
|
||||
f"幽默强度:{group_profile.get('humor_style', '轻微')}",
|
||||
f"嘴硬程度:{group_profile.get('sharpness_style', '轻微嘴硬,不刻薄')}",
|
||||
f"表达松弛度:{group_profile.get('expressiveness_style', '克制')}",
|
||||
f"知识重点:{focus}" if focus else "",
|
||||
f"群长期摘要:{summary}" if summary else "",
|
||||
f"历史推断社交风格:{ContextBuilder._build_style_summary(group_profile.get('group_memory_style', {}))}"
|
||||
if group_profile.get("group_memory_style")
|
||||
else "",
|
||||
f"边界提醒:{boundaries}" if boundaries else "",
|
||||
f"人格叠加:{group_profile.get('persona_overlay', '')}".strip(),
|
||||
]
|
||||
return "\n".join([line for line in lines if line])
|
||||
|
||||
@staticmethod
|
||||
def _build_style_summary(style_profile: Dict) -> str:
|
||||
if not style_profile:
|
||||
return ""
|
||||
return " / ".join(
|
||||
[
|
||||
str(style_profile.get("interaction_tone", "") or "").strip(),
|
||||
str(style_profile.get("humor_style", "") or "").strip(),
|
||||
str(style_profile.get("sharpness_style", "") or "").strip(),
|
||||
str(style_profile.get("expressiveness_style", "") or "").strip(),
|
||||
]
|
||||
).strip(" /")
|
||||
|
||||
Reference in New Issue
Block a user