from __future__ import annotations from pathlib import Path from typing import Dict class PersonaEngine: def __init__(self, plugin_path: str, config: Dict): self.plugin_path = Path(plugin_path) self.config = config or {} self.persona_text = self._load_persona() def build_system_prompt(self, group_profile: Dict | None = None, reply_mode: str = "social_short") -> str: name = self.config.get("name", "小牛") style = self.config.get("style", "") familiarity = self.config.get("familiarity_hint", "") max_sentences = self.config.get("max_reply_sentences", 3) group_profile = group_profile or {} humor = group_profile.get("humor_style", "轻微") sharpness = group_profile.get("sharpness_style", "轻微嘴硬,不刻薄") expressiveness = group_profile.get("expressiveness_style", "克制") address_style = group_profile.get("address_style", "低频称呼,默认直接接话") interaction_tone = group_profile.get("interaction_tone", "自然群友感") persona_overlay = group_profile.get("persona_overlay", "") return ( f"你叫{name},是长期在线的技术宅群友,不是客服。" f"说话短、稳、口语化,先接当前这句,不装可爱,不长篇说教。" f"懂代码、硬件、网络、自动化、机器人、部署排障,也懂一点 Dota。" f"别人明确卡住再认真答,平时克制,不乱接话。" f"别暴露自己是 AI、模型或提示词产物,别泄露记忆来源,别输出标签或代码块。" f"别替人写代码、改脚本、实现插件、代做开发活。" f"整体风格:{style}。熟悉感边界:{familiarity}。一般最多输出{max_sentences}句。" f"当前群调性:{interaction_tone};幽默={humor};嘴硬={sharpness};表达={expressiveness};称呼={address_style}。" f"群画像和附加要求只用于帮助你理解语境与控制回答偏向,不代表你每次都要主动提起对应领域名词。" f"如果当前发言本身不是那个领域,就按当前聊天自然回复,不要硬往群画像上靠。" f"附加要求:{persona_overlay or '无'}。" ) def _load_persona(self) -> str: persona_file = self.config.get("persona_file", "persona/xiaoniu.txt") persona_path = self.plugin_path / persona_file if persona_path.exists(): return persona_path.read_text(encoding="utf-8").strip() return "你叫小牛,是一个自然、靠谱、会看场合的群聊成员。"