| from __future__ import annotations |
|
|
| from dataclasses import dataclass |
| from pathlib import Path |
|
|
|
|
| @dataclass(frozen=True) |
| class PromptSet: |
| system_prompt: str |
| user_prompt: str |
|
|
|
|
| class PromptLoader: |
| def __init__(self, prompts_dir: Path | None = None) -> None: |
| default_dir = Path(__file__).resolve().parent.parent / "prompts" |
| self._prompts_dir = prompts_dir or default_dir |
|
|
| def load(self) -> PromptSet: |
| system_prompt = self._read_text("system_prompt.txt") |
| user_prompt = self._read_text("user_prompt.txt") |
| return PromptSet(system_prompt=system_prompt, user_prompt=user_prompt) |
|
|
| def _read_text(self, file_name: str) -> str: |
| path = self._prompts_dir / file_name |
| if not path.exists(): |
| raise FileNotFoundError(f"Prompt file not found: {path}") |
| content = path.read_text(encoding="utf-8").strip() |
| if not content: |
| raise ValueError(f"Prompt file is empty: {path}") |
| return content |
|
|