add multimodal quote handling for xiaoniu bot

This commit is contained in:
liuwei
2026-04-07 13:51:15 +08:00
parent 61edbbe987
commit 7c12738967
3 changed files with 184 additions and 9 deletions

View File

@@ -21,6 +21,7 @@ class ContextBuilder:
flow_state: str,
reply_mode: str,
vector_memories: List[Dict],
quote_context: Dict | None = None,
) -> Dict:
recent_lines = []
for item in recent_messages[-self.recent_context_size:]:
@@ -43,6 +44,7 @@ class ContextBuilder:
"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 {}),
"quote_prompt": self._build_quote_prompt(quote_context or {}),
"current_message": f"{sender_name}: {content}",
}
@@ -116,3 +118,21 @@ class ContextBuilder:
str(style_profile.get("expressiveness_style", "") or "").strip(),
]
).strip(" /")
@staticmethod
def _build_quote_prompt(quote_context: Dict) -> str:
if not quote_context:
return ""
quote_type = quote_context.get("quote_type_label", "引用消息")
quote_sender = quote_context.get("quote_sender_name", "") or "未知成员"
quote_body = quote_context.get("quote_body", "") or ""
title = quote_context.get("title", "") or ""
lines = [
f"用户这次是在引用消息后发言。",
f"引用类型:{quote_type}",
f"被引用发送者:{quote_sender}",
f"图片附件:已附带原图" if quote_context.get("has_image_attachment") else "",
f"引用标题:{title}" if title else "",
f"被引用内容:{quote_body}" if quote_body else "",
]
return "\n".join([line for line in lines if line])