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.
This commit is contained in:
parent
c10b617f1f
commit
1c47ecbc5a
11 changed files with 444 additions and 73 deletions
|
|
@ -49,3 +49,49 @@ def test_select_map_caps_20():
|
|||
out = select_map(items)
|
||||
assert len(out) == 20
|
||||
assert all(r["importance"] in ("critical", "high") for r in out)
|
||||
|
||||
|
||||
def test_parse_k8s_market_intel_reduce_json():
|
||||
raw = """{
|
||||
"market_overview": {
|
||||
"overall_sentiment": "bearish",
|
||||
"sentiment_score": -40,
|
||||
"key_themes": ["oil supply", "rates"],
|
||||
"critical_events": [
|
||||
{
|
||||
"headline": "Strike on Kharkiv",
|
||||
"impact_level": "high",
|
||||
"description": "Infrastructure hit.",
|
||||
"location_name": "Kharkiv",
|
||||
"lat": 49.99,
|
||||
"lon": 36.23
|
||||
},
|
||||
{
|
||||
"headline": "Mild CPI print",
|
||||
"impact_level": "low",
|
||||
"description": "No surprise."
|
||||
}
|
||||
]
|
||||
},
|
||||
"geopolitical_osint": {
|
||||
"active_conflicts": [
|
||||
{
|
||||
"region": "Ukraine",
|
||||
"status": "escalating",
|
||||
"intelligence": "Front-line push near Kharkiv",
|
||||
"lat": 50.0,
|
||||
"lon": 36.2
|
||||
}
|
||||
]
|
||||
}
|
||||
}"""
|
||||
out = parse_reduce_json(raw)
|
||||
assert "bearish" in out["summary_en"]
|
||||
assert "Strike on Kharkiv" in out["summary_en"]
|
||||
assert [t["headline"] for t in out["ticker"]] == ["Strike on Kharkiv"]
|
||||
assert out["ticker"][0]["importance"] == "high"
|
||||
mapped = select_map(out["map_items"])
|
||||
headlines = [r["headline"] for r in mapped]
|
||||
assert "Front-line push near Kharkiv" in headlines
|
||||
assert "Strike on Kharkiv" in headlines
|
||||
|
||||
|
|
|
|||
40
news/summerizer/tests/test_prompts.py
Normal file
40
news/summerizer/tests/test_prompts.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from pathlib import Path
|
||||
|
||||
from prompts import map_prompt_template, resolve_prompt, summary_prompt_template
|
||||
|
||||
|
||||
def test_bundled_prompts_contain_placeholders():
|
||||
assert "{batch_text}" in map_prompt_template()
|
||||
assert "{final_input}" in summary_prompt_template()
|
||||
assert "Market Intelligence Extractor" in map_prompt_template()
|
||||
assert "Lead Market Intelligence Analyst" in summary_prompt_template()
|
||||
|
||||
|
||||
def test_env_prompt_wins_over_file(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("MAP_PROMPT", "ENV {batch_text}")
|
||||
monkeypatch.setenv("MAP_PROMPT_FILE", str(tmp_path / "missing.txt"))
|
||||
assert resolve_prompt("MAP_PROMPT", "MAP_PROMPT_FILE", "map.txt") == "ENV {batch_text}"
|
||||
|
||||
|
||||
def test_blank_env_falls_through_to_file(monkeypatch, tmp_path):
|
||||
f = tmp_path / "custom.txt"
|
||||
f.write_text("FILE {batch_text}\n")
|
||||
monkeypatch.setenv("MAP_PROMPT", " ")
|
||||
monkeypatch.setenv("MAP_PROMPT_FILE", str(f))
|
||||
assert resolve_prompt("MAP_PROMPT", "MAP_PROMPT_FILE", "map.txt") == "FILE {batch_text}\n"
|
||||
|
||||
|
||||
def test_missing_file_raises(monkeypatch, tmp_path):
|
||||
monkeypatch.delenv("MAP_PROMPT", raising=False)
|
||||
monkeypatch.setenv("MAP_PROMPT_FILE", str(tmp_path / "nope.txt"))
|
||||
try:
|
||||
resolve_prompt("MAP_PROMPT", "MAP_PROMPT_FILE", "map.txt")
|
||||
assert False, "expected RuntimeError"
|
||||
except RuntimeError as exc:
|
||||
assert "unreadable" in str(exc)
|
||||
|
||||
|
||||
def test_bundled_files_exist():
|
||||
root = Path(__file__).resolve().parents[1] / "prompt_files"
|
||||
assert (root / "map.txt").is_file()
|
||||
assert (root / "summary.txt").is_file()
|
||||
Loading…
Reference in a new issue