news: get_news degrades softly on topic miss (news-13) — any-term ranked fallback, recent+note, language hint in schema; idle-impulse default varies form
This commit is contained in:
+17
-2
@@ -198,7 +198,12 @@ GET_NEWS_TOOL = {
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"topic": {"type": "string", "description": "Optional keywords to filter by, e.g. 'Nordland', 'football', 'weather'."},
|
||||
"topic": {
|
||||
"type": "string",
|
||||
"description": "Optional filter: one or two keywords, in the language the feeds are written in "
|
||||
"(e.g. Norwegian for Norwegian news: 'Nordland', 'fotball', 'trafikkulykke'). If nothing matches "
|
||||
"exactly, related or recent items come back with a `note` saying so.",
|
||||
},
|
||||
"source": {"type": "string", "description": "Optional source label, e.g. 'NRK', 'Aftenposten', 'Verden', 'Sport'."},
|
||||
"limit": {"type": "integer", "description": "How many items to return (default 10, max 30)."},
|
||||
},
|
||||
@@ -220,8 +225,15 @@ def query_news(
|
||||
limit = max(1, min(int(limit or 10), 30))
|
||||
src = (str(source).strip() or None) if source else None
|
||||
terms = _news_terms(topic)
|
||||
note = None
|
||||
try:
|
||||
rows = store.search_news(terms, limit, src) if terms else store.recent_news(limit, src)
|
||||
if terms and not rows: # NEWS-13: soft degradation, never empty-handed
|
||||
rows = store.search_news(terms, limit, src, match_any=True)
|
||||
note = "no item matches all keywords; showing items matching some of them"
|
||||
if terms and not rows:
|
||||
rows = store.recent_news(limit, src)
|
||||
note = "nothing matches the topic; showing the newest stored items instead"
|
||||
except Exception as err:
|
||||
logging.warning(f"news: query failed: {err!r}")
|
||||
return {"error": "news lookup failed"}
|
||||
@@ -234,7 +246,10 @@ def query_news(
|
||||
}
|
||||
for row in rows
|
||||
]
|
||||
return {"topic": topic or "", "source": src or "", "results": results}
|
||||
payload = {"topic": topic or "", "source": src or "", "results": results}
|
||||
if note:
|
||||
payload["note"] = note
|
||||
return payload
|
||||
|
||||
|
||||
def _open_store(config: Dict[str, Any]) -> Any:
|
||||
|
||||
Reference in New Issue
Block a user