20 lines
652 B
Python
20 lines
652 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from pathlib import Path
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
import yaml
|
||
|
|
|
||
|
|
PROMPT_ROOT = Path(__file__).resolve().parent / "prompt"
|
||
|
|
|
||
|
|
def load_prompt(agent_name: str, language: str = "zh") -> dict[str, Any]:
|
||
|
|
lang = "zh" if language.lower().startswith("zh") else "zh"
|
||
|
|
path = PROMPT_ROOT / lang / f"{agent_name}.yaml"
|
||
|
|
if not path.exists():
|
||
|
|
raise FileNotFoundError(f"Prompt file not found: {path}")
|
||
|
|
with path.open("r", encoding="utf-8") as f:
|
||
|
|
data = yaml.safe_load(f) or {}
|
||
|
|
if not isinstance(data, dict):
|
||
|
|
raise ValueError(f"Prompt file must contain a YAML object: {path}")
|
||
|
|
return data
|