added debug for gather news doctor
Browse files
crew.py
CHANGED
|
@@ -369,7 +369,9 @@ patient_news = Agent(
|
|
| 369 |
backstory="You find and share clear, trustworthy news about dementia—like new treatments, daily care tips, and support resources—written for patients and caregivers.",
|
| 370 |
verbose=True,
|
| 371 |
llm=llm_news,
|
| 372 |
-
tools=[gather_news_patient]
|
|
|
|
|
|
|
| 373 |
)
|
| 374 |
|
| 375 |
doctor_news = Agent(
|
|
@@ -378,7 +380,9 @@ doctor_news = Agent(
|
|
| 378 |
backstory="You find and summarize the latest clinical studies, guidelines, and expert insights on dementia—focused on diagnosis, treatment, and research for healthcare providers.",
|
| 379 |
verbose=True,
|
| 380 |
llm=llm_news,
|
| 381 |
-
tools=[gather_news_doctor]
|
|
|
|
|
|
|
| 382 |
)
|
| 383 |
|
| 384 |
# Define tasks for agents
|
|
@@ -710,39 +714,30 @@ def run_crewai_news_patient(count: int = 5) -> dict:
|
|
| 710 |
except Exception as e:
|
| 711 |
return {"status": "error", "message": str(e)}
|
| 712 |
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
if key not in result or not isinstance(result[key], list):
|
| 741 |
-
raise ValueError(f"Missing or invalid '{key}' in result")
|
| 742 |
-
if not (len(result["titles"]) == len(result["snippets"]) == len(result["urls"])):
|
| 743 |
-
raise ValueError("Mismatched list lengths in doctor news result")
|
| 744 |
-
|
| 745 |
-
return {"status": "success", **result}
|
| 746 |
-
|
| 747 |
-
except Exception as e:
|
| 748 |
-
return {"status": "error", "message": str(e)}
|
|
|
|
| 369 |
backstory="You find and share clear, trustworthy news about dementia—like new treatments, daily care tips, and support resources—written for patients and caregivers.",
|
| 370 |
verbose=True,
|
| 371 |
llm=llm_news,
|
| 372 |
+
tools=[gather_news_patient],
|
| 373 |
+
function_calling=True,
|
| 374 |
+
tool_choice="required"
|
| 375 |
)
|
| 376 |
|
| 377 |
doctor_news = Agent(
|
|
|
|
| 380 |
backstory="You find and summarize the latest clinical studies, guidelines, and expert insights on dementia—focused on diagnosis, treatment, and research for healthcare providers.",
|
| 381 |
verbose=True,
|
| 382 |
llm=llm_news,
|
| 383 |
+
tools=[gather_news_doctor],
|
| 384 |
+
function_calling=True,
|
| 385 |
+
tool_choice="required"
|
| 386 |
)
|
| 387 |
|
| 388 |
# Define tasks for agents
|
|
|
|
| 714 |
except Exception as e:
|
| 715 |
return {"status": "error", "message": str(e)}
|
| 716 |
|
| 717 |
+
@tool("gather_news_doctor")
|
| 718 |
+
def gather_news_doctor(count: int = 5) -> dict:
|
| 719 |
+
from webscraper import search_dementia_news, scrape_article_content
|
| 720 |
+
print(f"[DEBUG] Searching for {count} doctor articles...") # ← HF logs will show this
|
| 721 |
+
articles = search_dementia_news(audience="doctor", max_results=min(count, 10))
|
| 722 |
+
print(f"[DEBUG] Found {len(articles)} raw results") # ← check if 0
|
| 723 |
+
clean_articles = []
|
| 724 |
+
for i, art in enumerate(articles):
|
| 725 |
+
if "error" in art:
|
| 726 |
+
print(f"[ERROR] Search error: {art['error']}")
|
| 727 |
+
continue
|
| 728 |
+
print(f"[DEBUG] {i+1}. Title: {art['title'][:50]} | URL: {art['url']}")
|
| 729 |
+
try:
|
| 730 |
+
content = scrape_article_content(art["url"])
|
| 731 |
+
if "[Content extraction failed" in content:
|
| 732 |
+
print(f"[WARN] Content failed for {art['url']}")
|
| 733 |
+
continue
|
| 734 |
+
clean_articles.append({
|
| 735 |
+
"title": art["title"],
|
| 736 |
+
"url": art["url"],
|
| 737 |
+
"content": content[:3000]
|
| 738 |
+
})
|
| 739 |
+
except Exception as e:
|
| 740 |
+
print(f"[EXC] Scraping failed for {art['url']}: {e}")
|
| 741 |
+
continue
|
| 742 |
+
print(f"[DEBUG] Returning {len(clean_articles)} clean articles")
|
| 743 |
+
return {"articles": clean_articles}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|