Skip to content

Commit 906de3b

Browse files
committed
Added logic to verify news summary
1 parent 8b94163 commit 906de3b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

agents/news.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ def get_news(topic, max=10):
284284
break
285285
return articles
286286

287-
def fetch_news(topic):
287+
def fetch_news(topic, retries=3):
288+
if retries == 0:
289+
return "Unable to fetch news", "Unable to fetch news"
288290
log("Get News")
289291
context_str = get_news(topic, 25)
290292
log(f"News Raw Context = {context_str}")
@@ -293,24 +295,32 @@ def fetch_news(topic):
293295
# Replace IDs in answer with URLs
294296
result = ""
295297
text_only = ""
298+
all_lines = []
296299
for line in answer.split("\n"):
297300
if "ID:" in line:
298301
elements = line.split("ID: ")
299302
title = elements[0].strip()
303+
all_lines.append(title)
300304
text_only += title + "\n"
301305
if len(elements) > 1:
302306
uuid = elements[1].strip()
303307
# Ensure we have a valid UUId that is a integer
304308
if not uuid.isdigit():
305309
result += line
306-
continue
310+
continue
307311
url = news_cache.get(int(uuid))
308312
result += f"{title} <a href=\"{url}\">[Link]</a>"
309313
else:
310314
result += line
311315
else:
312316
result += line
313317
result += "\n"
318+
# Query the LLM to see if all_lines are duplicated
319+
prompt = expand_prompt(prompts["rag"], {"context_str": "\n".join(all_lines), "prompt": "Are these news items all about the same thing?"})
320+
answer = ask(prompt)
321+
if "yes" in answer.lower():
322+
log("News items are all about the same thing")
323+
return fetch_news(topic, retries-1)
314324
return result, text_only
315325

316326
def handle_weather_command(p):

0 commit comments

Comments
 (0)