from langchain.tools import tool from scholarly import scholarly from Bio import Entrez from bs4 import BeautifulSoup import requests import datetime @tool def pmc_search(query: str) -> str: """Search PubMed Central (PMC) for articles""" Entrez.email = "your-email@example.com" handle = Entrez.esearch(db="pmc", term=query, retmax=10) record = Entrez.read(handle) handle.close() articles = [] for id in record["IdList"]: handle = Entrez.efetch(db="pmc", id=id, rettype="full", retmode="xml") article = BeautifulSoup(handle.read(), 'xml') handle.close() title = article.find("article-title") title = title.text if title else "No title" abstract = article.find("abstract") abstract = abstract.text if abstract else "No abstract" articles.append({ "id": id, "title": title, "abstract": abstract }) return str(articles) @tool def google_scholar_search(query: str) -> str: """Search Google Scholar for articles""" search_query = scholarly.search_pubs(query) results = [] count = 0 for result in search_query: if count >= 10: break pub = { "title": result.bib.get('title', 'No title'), "author": result.bib.get('author', 'No author'), "year": result.bib.get('year', 'No year'), "abstract": result.bib.get('abstract', 'No abstract') } results.append(pub) count += 1 return str(results) @tool def today_tool() -> str: """Get today's date""" return str(datetime.date.today())