plutoa386 commited on
Commit
55e1e48
·
1 Parent(s): bc49ec4

added debug for gather news doctor

Browse files
Files changed (1) hide show
  1. crew.py +33 -38
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
- def run_crewai_news_doctor(count: int = 5) -> dict:
714
- try:
715
- original_gather = doctor_news.tools[0]
716
-
717
- # Wrap tool to inject count
718
- def gather_with_count(query=None):
719
- return gather_news_doctor(count=count)
720
-
721
- # Replace tool temporarily
722
- doctor_news.tools = [gather_with_count]
723
-
724
- # Run crew with static task
725
- crew = Crew(
726
- agents=[doctor_news],
727
- tasks=[get_news_task_doctor],
728
- verbose=True
729
- )
730
- raw_output = str(crew.kickoff()).strip()
731
-
732
- # Restore original tool
733
- doctor_news.tools = [original_gather]
734
-
735
- # Parse JSON
736
- result = _parse_json_output(raw_output)
737
-
738
- # Validate structure
739
- for key in ["titles", "snippets", "urls"]:
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}