init the project
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
# 动态人格装配器:从 .zeekerwatchmen/soul/ 加载 Agent 人格
|
||||
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
|
||||
from server.config import settings
|
||||
|
||||
|
||||
class PersonalityLoader:
|
||||
"""从 .zeekerwatchmen/soul/ 加载 principles 和 persona 配置"""
|
||||
|
||||
def __init__(self, soul_dir: Path | None = None):
|
||||
self.soul_dir = soul_dir or settings.SOUL_DIR
|
||||
|
||||
def load_principles(self) -> dict:
|
||||
"""加载 principles.yaml,返回原则列表"""
|
||||
path = self.soul_dir / "principles.yaml"
|
||||
if not path.exists():
|
||||
return {"principles": []}
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return yaml.safe_load(f)
|
||||
|
||||
def load_persona(self) -> dict:
|
||||
"""加载 persona.yaml,返回人格配置"""
|
||||
path = self.soul_dir / "persona.yaml"
|
||||
if not path.exists():
|
||||
return {"persona": {}}
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return yaml.safe_load(f)
|
||||
|
||||
def build_system_context(self) -> dict:
|
||||
"""组装完整的人格上下文,用于注入 LLM 系统提示词"""
|
||||
principles = self.load_principles()
|
||||
persona = self.load_persona()
|
||||
return {
|
||||
"principles": principles.get("principles", []),
|
||||
"persona": persona.get("persona", {}),
|
||||
}
|
||||
|
||||
|
||||
personality = PersonalityLoader()
|
||||
Reference in New Issue
Block a user