优化ai_auto_response回复长度并强化@画像回复
变更项: 1. 收紧回复长度策略:social_short/qa_fast/qa_with_context 全部缩短,减少长句与说明文风格。 2. 强化提示词约束:默认30字内、最多2句且总长不超过55字,禁止大段铺垫。 3. 新增@画像高优先通道:当消息为@或强定向时,构建并注入 at_member_profile_prompt。 4. Dify输入同步注入@画像与 is_at/is_directed 控制字段,保证不同LLM后端行为一致。
This commit is contained in:
@@ -43,6 +43,8 @@ class ContextBuilder:
|
||||
"member_context": member_context or {},
|
||||
},
|
||||
"speaker_name_clean": self._clean_display_name(sender_name),
|
||||
"is_at": bool(trigger.get("is_at", False)),
|
||||
"is_directed": bool(trigger.get("is_directed", False)),
|
||||
"recent_message_items": self._build_recent_message_items(selected_messages),
|
||||
"recent_messages": recent_lines,
|
||||
"recent_summary": "",
|
||||
@@ -50,6 +52,12 @@ class ContextBuilder:
|
||||
"reply_mode": reply_mode,
|
||||
"flow_state": flow_state,
|
||||
"memory_prompt": self._build_member_memory_prompt(member_context, member_memory_focus or []),
|
||||
"at_member_profile_prompt": self._build_at_member_profile_prompt(
|
||||
member_context=member_context or {},
|
||||
focus_lines=member_memory_focus or [],
|
||||
is_at=bool(trigger.get("is_at", False)),
|
||||
is_directed=bool(trigger.get("is_directed", False)),
|
||||
),
|
||||
"vector_memory_prompt": self._build_vector_memory_prompt(vector_memories),
|
||||
"social_memory_prompt": self._build_social_memory_prompt(social_memory or {}),
|
||||
"group_facts_prompt": self._build_group_facts_prompt(group_facts or {}),
|
||||
@@ -229,6 +237,39 @@ class ContextBuilder:
|
||||
]
|
||||
return "\n".join([line for line in lines if line])
|
||||
|
||||
@staticmethod
|
||||
def _build_at_member_profile_prompt(
|
||||
member_context: Dict,
|
||||
focus_lines: List[str] | None = None,
|
||||
is_at: bool = False,
|
||||
is_directed: bool = False,
|
||||
) -> str:
|
||||
# 只有明确 @ 或强定向时才给“高优先级成员画像”,避免平时过度套人设
|
||||
if not (is_at or is_directed):
|
||||
return ""
|
||||
if not member_context:
|
||||
return "本次是对方点名发起,但暂无稳定画像,按自然群友口吻短回复。"
|
||||
|
||||
meta = member_context.get("meta", {}) or {}
|
||||
summary = str(member_context.get("summary_text", "") or "").strip()
|
||||
interaction_style = str(member_context.get("interaction_style", "") or "").strip()
|
||||
response_hint = str(member_context.get("response_style_hint", "") or "").strip()
|
||||
topics = ContextBuilder._stringify_items(member_context.get("topics_of_interest", []) or [], 4)
|
||||
focus = ";".join((focus_lines or [])[:3]).strip()
|
||||
lines = [
|
||||
"本次为点名互动,优先参考该成员画像后再回复:",
|
||||
f"成员摘要:{summary}" if summary else "",
|
||||
f"互动风格:{interaction_style}" if interaction_style else "",
|
||||
f"偏好回复方式:{response_hint}" if response_hint else "",
|
||||
f"近期相关记忆:{focus}" if focus else "",
|
||||
f"长期兴趣:{topics}" if topics else "",
|
||||
f"禁忌提醒:{ContextBuilder._stringify_items(meta.get('reply_taboos', []), 3)}"
|
||||
if meta.get("reply_taboos")
|
||||
else "",
|
||||
"语气要像熟悉的群友,短句、自然,不要客服腔。",
|
||||
]
|
||||
return "\n".join([line for line in lines if line])
|
||||
|
||||
@staticmethod
|
||||
def _stringify_items(items: List | str, limit: int) -> str:
|
||||
if isinstance(items, str):
|
||||
|
||||
Reference in New Issue
Block a user