osint-dashboard/news/summerizer/prompts.py
Sirius DevOps 1c47ecbc5a feat: load k8s news prompts from env/files, not Python
Bundled MAP_PROMPT/SUMMARY_PROMPT from the customer1 deepseek
configmap. Env wins over prompt files; blank compose injection
is treated as unset. Parser maps market_overview JSON onto the
dashboard ticker/map contract.
2026-08-28 20:04:47 -04:00

36 lines
1.1 KiB
Python

"""Load map/reduce prompts: env wins, else file, else bundled k8s prompts.
Blank ``MAP_PROMPT`` / ``SUMMARY_PROMPT`` (compose ``${VAR:-}``) is treated as
unset so a host .env can swap text without rebuilding the image.
"""
from __future__ import annotations
import os
from pathlib import Path
_BUNDLED = Path(__file__).resolve().parent / "prompt_files"
_MAP_FILE = "map.txt"
_SUMMARY_FILE = "summary.txt"
def resolve_prompt(env_name: str, file_env: str, bundled_name: str) -> str:
raw = (os.getenv(env_name) or "").strip()
if raw:
return raw
path = (os.getenv(file_env) or "").strip() or str(_BUNDLED / bundled_name)
try:
text = Path(path).read_text(encoding="utf-8")
except OSError as exc:
raise RuntimeError(f"{env_name} unset and prompt file unreadable: {path}") from exc
if not text.strip():
raise RuntimeError(f"{env_name} unset and prompt file empty: {path}")
return text
def map_prompt_template() -> str:
return resolve_prompt("MAP_PROMPT", "MAP_PROMPT_FILE", _MAP_FILE)
def summary_prompt_template() -> str:
return resolve_prompt("SUMMARY_PROMPT", "SUMMARY_PROMPT_FILE", _SUMMARY_FILE)