prompt_loader.py 547 B

1234567891011121314151617181920
  1. from pathlib import Path
  2. from typing import Optional
  3. PROMPT_DIR = Path(__file__).parent
  4. def load_prompt(name: str, encoding: str = 'utf-8') -> str:
  5. """Load a prompt file content by name from prompt directory.
  6. Args:
  7. name: filename like 'core_task.md'
  8. encoding: file encoding
  9. Returns:
  10. file text
  11. Raises:
  12. FileNotFoundError if not exists
  13. """
  14. p = PROMPT_DIR / name
  15. if not p.is_file():
  16. raise FileNotFoundError(f"Prompt file not found: {p}")
  17. return p.read_text(encoding=encoding)