rtc-voice-chat/backend/config/prompt_config.py
2026-04-02 09:40:23 +08:00

30 lines
982 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
提示词注册表。
- 每个提示词对应 prompts/ 目录下的一个 .md 文件
- 新增提示词1) 在 prompts/ 下新建 .md 文件2) 在 PROMPT_MAP 中追加一行
- 不同接口/模型调用 chat_stream(prompt_name="xxx") 来切换提示词
"""
from pathlib import Path
PROMPTS_DIR = Path(__file__).parent.parent / "prompts"
# name → .md 文件路径
PROMPT_MAP: dict[str, Path] = {
"default": PROMPTS_DIR / "default.md",
# 追加示例:
# "checkin": PROMPTS_DIR / "checkin.md",
}
def load_prompt(name: str = "default") -> str:
"""加载指定名称的提示词,文件不存在时抛出清晰的错误。"""
path = PROMPT_MAP.get(name)
if path is None:
available = list(PROMPT_MAP.keys())
raise ValueError(f"未知提示词名称: {name!r},可选: {available}")
if not path.exists():
raise FileNotFoundError(f"提示词文件不存在: {path}")
return path.read_text(encoding="utf-8").strip()