refactor ai_auto_response into xiaoniu group bot
This commit is contained in:
33
plugins/ai_auto_response/persona_engine.py
Normal file
33
plugins/ai_auto_response/persona_engine.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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) -> 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)
|
||||
return (
|
||||
f"{self.persona_text}\n\n"
|
||||
f"补充约束:\n"
|
||||
f"- 你当前对外名称固定为{name}\n"
|
||||
f"- 整体风格:{style}\n"
|
||||
f"- 熟悉感边界:{familiarity}\n"
|
||||
f"- 一般最多输出{max_sentences}句\n"
|
||||
f"- 优先根据场景决定是答疑、接话还是不说话\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 "你叫小牛,是一个自然、靠谱、会看场合的群聊成员。"
|
||||
Reference in New Issue
Block a user