Spaces:
Runtime error
Runtime error
| """System prompt and knowledge orchestration for KORA.""" | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| from app.utils.config import Settings | |
| class PromptService: | |
| """Loads and injects KORA identity/context into requests.""" | |
| settings: Settings | |
| def _read_file(self, path: Path) -> str: | |
| return path.read_text(encoding="utf-8").strip() | |
| def build_system_prompt(self) -> str: | |
| """Build a single injected system instruction block.""" | |
| core_prompt = self._read_file(self.settings.system_prompt_file) | |
| knowledge = self._read_file(self.settings.knowledge_file) | |
| return ( | |
| f"{core_prompt}\n\n" | |
| "---\n" | |
| "KONTYRA KNOWLEDGE BASE (authoritative context):\n" | |
| f"{knowledge}" | |
| ) | |
| def inject_system_prompt(self, messages: list[dict[str, str]]) -> list[dict[str, str]]: | |
| """Prepend enforced KORA system prompt to every chat request.""" | |
| # Remove user-supplied system messages so identity rules remain stable. | |
| non_system_messages = [m for m in messages if m.get("role") != "system"] | |
| return [{"role": "system", "content": self.build_system_prompt()}, *non_system_messages] | |