The map prompt now grades every article 0-100 against an explicit rubric as the first line of its block; the summarizer parses Score:, falls back to the Importance: label when the line is missing, ranks blocks best-first and passes only score >= SUMMARY_MIN_SCORE (capped at SUMMARY_TOP_N) to the reduce phase. - new pure helpers in intel.py: parse_map_scores(), select_graded(), join_blocks() - reduce prompts drop the 'fill the brief with minor incidents and crime' filler instructions and the 'fill ticker with medium then low' clause - new article_scores table (ensure_tables + alembic 012) persists every grade with selected/summary_id/model so thresholds can be tuned from data - SUMMARY_MIN_SCORE (60), SUMMARY_TOP_N (12), SUMMARY_FALLBACK_TOP (3) env knobs
90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
"""Default prompts: breaking news, ignore futures/market tape."""
|
||
|
||
from summarizer import MAP_PROMPT_DEFAULT, RECAP_PROMPT_DEFAULT, SUMMARY_PROMPT_DEFAULT
|
||
|
||
|
||
def _assert_breaking_not_futures(prompt: str) -> None:
|
||
p = prompt.lower()
|
||
assert "breaking" in p
|
||
assert "futures" in p
|
||
assert "ignore" in p or "do not" in p or "not" in p
|
||
assert "es=f" not in p
|
||
assert "yfinance" not in p
|
||
|
||
|
||
def test_map_prompt_focuses_on_breaking_news_not_futures():
|
||
_assert_breaking_not_futures(MAP_PROMPT_DEFAULT)
|
||
|
||
|
||
def test_summary_prompt_focuses_on_breaking_news_not_futures():
|
||
_assert_breaking_not_futures(SUMMARY_PROMPT_DEFAULT)
|
||
p = SUMMARY_PROMPT_DEFAULT.lower()
|
||
assert "commodity" in p or "market" in p
|
||
|
||
|
||
def test_map_prompt_has_the_grading_rubric_and_score_first_block():
|
||
p = MAP_PROMPT_DEFAULT
|
||
assert "- Score: <0-100>" in p
|
||
assert "Importance: critical|high|medium|low|none" in p
|
||
for band in (
|
||
"90–100",
|
||
"70–89",
|
||
"40–69",
|
||
"10–39",
|
||
"0–9",
|
||
"event-calendar/schedule listings",
|
||
):
|
||
assert band in p
|
||
# Score must be the first line of the per-article output block.
|
||
block = p.split("Article 1:", 1)[1]
|
||
first_lines = [line.strip() for line in block.splitlines() if line.strip()]
|
||
assert first_lines[0].startswith("- Score:")
|
||
|
||
|
||
def test_reduce_prompts_do_not_demand_filler():
|
||
for prompt in (SUMMARY_PROMPT_DEFAULT, RECAP_PROMPT_DEFAULT):
|
||
p = prompt.lower()
|
||
assert "fill the brief with minor incidents" not in p
|
||
assert "fill the recap with minor incidents" not in p
|
||
assert "fill ticker with medium then low" not in p
|
||
assert "pre-filtered by score" in p
|
||
assert "never promote an item above its score" in p
|
||
assert "No significant developments in this window." in prompt
|
||
|
||
|
||
def test_summary_prompt_ranks_by_score_and_stays_complete():
|
||
p = SUMMARY_PROMPT_DEFAULT.lower()
|
||
assert "critical" in p
|
||
assert "highest-scoring" in p
|
||
assert "pre-filtered" in p
|
||
assert "complete" in p or "truncat" in p or "mid-sentence" in p
|
||
|
||
|
||
def test_summary_prompt_does_not_bail_out_with_canned_empty_brief():
|
||
p = SUMMARY_PROMPT_DEFAULT
|
||
assert "AND STOP" not in p
|
||
assert "REPEAT 3 TIMES" not in p
|
||
assert "No qualifying" not in p
|
||
assert "no-qualifying" not in p.lower()
|
||
low = p.lower()
|
||
assert "always" in low
|
||
assert "recap" in low or "summar" in low
|
||
|
||
|
||
def test_recap_prompt_does_not_bail_out_with_canned_empty_brief():
|
||
p = RECAP_PROMPT_DEFAULT
|
||
assert "AND STOP" not in p
|
||
assert "No qualifying" not in p
|
||
assert "no-qualifying" not in p.lower()
|
||
low = p.lower()
|
||
assert "always" in low
|
||
assert "daily" in low
|
||
assert "24" in low
|
||
|
||
p = RECAP_PROMPT_DEFAULT.lower()
|
||
_assert_breaking_not_futures(RECAP_PROMPT_DEFAULT)
|
||
assert "daily" in p
|
||
assert "24" in p
|
||
assert "summary_en" in p
|
||
assert "ticker" in p
|
||
assert "map_items" in p
|