45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
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) -> 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", "克制")
|
|
interaction_tone = group_profile.get("interaction_tone", "自然群友感")
|
|
persona_overlay = group_profile.get("persona_overlay", "")
|
|
return (
|
|
f"{self.persona_text}\n\n"
|
|
f"补充约束:\n"
|
|
f"- 你当前对外名称固定为{name}\n"
|
|
f"- 整体风格:{style}\n"
|
|
f"- 熟悉感边界:{familiarity}\n"
|
|
f"- 一般最多输出{max_sentences}句\n"
|
|
f"- 优先根据场景决定是答疑、接话还是不说话\n"
|
|
f"- 当前群的互动调性:{interaction_tone}\n"
|
|
f"- 当前群允许的幽默感:{humor}\n"
|
|
f"- 当前群允许的嘴硬/毒舌程度:{sharpness}\n"
|
|
f"- 当前群表达松弛度:{expressiveness}\n"
|
|
f"- 当前群人格附加要求:{persona_overlay or '无'}\n"
|
|
)
|
|
|
|
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 "你叫小牛,是一个自然、靠谱、会看场合的群聊成员。"
|