fix(summarizer): stamp ticker and map urls from the article, not the model
The reduce model returns url="" and save_batch was persisting that blank. Match each headline to a selected article title and store that article's url. A null article url or an ambiguous match stores "" — never a guessed or model-supplied URL.
This commit is contained in:
parent
d04ddc9afa
commit
653e02b09f
3 changed files with 298 additions and 4 deletions
|
|
@ -38,6 +38,7 @@ from zoneinfo import ZoneInfo
|
|||
import psycopg2
|
||||
|
||||
from intel import (
|
||||
article_url_for_row,
|
||||
dedupe_blocks,
|
||||
join_blocks,
|
||||
parse_map_scores,
|
||||
|
|
@ -511,9 +512,19 @@ def _already_recapped_today() -> bool:
|
|||
|
||||
|
||||
def save_batch(
|
||||
summary_en: str, model: str, ticker: list, map_items: list, *, kind: str = "interval"
|
||||
summary_en: str,
|
||||
model: str,
|
||||
ticker: list,
|
||||
map_items: list,
|
||||
*,
|
||||
kind: str = "interval",
|
||||
articles: list | None = None,
|
||||
) -> int | None:
|
||||
"""Insert the master brief plus flagged ticker/map rows. Returns the new summary id."""
|
||||
"""Insert the master brief plus flagged ticker/map rows. Returns the new summary id.
|
||||
|
||||
``news_items.url`` is the matched selected article's url, never the model's
|
||||
``url`` field. A null article url is stored as ``""``.
|
||||
"""
|
||||
ticker_rows = select_ticker(ticker or [])
|
||||
map_rows = select_map(map_items or [])
|
||||
text = (summary_en or "").strip()
|
||||
|
|
@ -547,7 +558,7 @@ def save_batch(
|
|||
None,
|
||||
None,
|
||||
None,
|
||||
row.get("url"),
|
||||
article_url_for_row(row, articles),
|
||||
),
|
||||
)
|
||||
for row in map_rows:
|
||||
|
|
@ -563,7 +574,7 @@ def save_batch(
|
|||
row.get("lon"),
|
||||
row.get("location_confidence"),
|
||||
row.get("category"),
|
||||
row.get("url"),
|
||||
article_url_for_row(row, articles),
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
|
|
@ -786,12 +797,18 @@ def summarize_news() -> None:
|
|||
logger.warning("Reduce phase returned empty — nothing to persist.")
|
||||
return
|
||||
parsed = parse_reduce_json(master_raw)
|
||||
selected_articles = [
|
||||
block["article"]
|
||||
for block in selected
|
||||
if isinstance(block.get("article"), dict)
|
||||
]
|
||||
summary_id = save_batch(
|
||||
parsed["summary_en"],
|
||||
model,
|
||||
parsed["ticker"],
|
||||
parsed["map_items"],
|
||||
kind="daily_recap" if recap else "interval",
|
||||
articles=selected_articles,
|
||||
)
|
||||
persist_article_scores(distinct + duplicate_blocks, summary_id=summary_id, model=model)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue