Spaces:
Sleeping
Sleeping
Delete tools.py
Browse files
tools.py
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
from langchain.tools import tool
|
2 |
-
from scholarly import scholarly
|
3 |
-
from Bio import Entrez
|
4 |
-
from bs4 import BeautifulSoup
|
5 |
-
import requests
|
6 |
-
import datetime
|
7 |
-
|
8 |
-
@tool
|
9 |
-
def pmc_search(query: str) -> str:
|
10 |
-
"""Search PubMed Central (PMC) for articles"""
|
11 |
-
Entrez.email = "[email protected]"
|
12 |
-
handle = Entrez.esearch(db="pmc", term=query, retmax=10)
|
13 |
-
record = Entrez.read(handle)
|
14 |
-
handle.close()
|
15 |
-
|
16 |
-
articles = []
|
17 |
-
for id in record["IdList"]:
|
18 |
-
handle = Entrez.efetch(db="pmc", id=id, rettype="full", retmode="xml")
|
19 |
-
article = BeautifulSoup(handle.read(), 'xml')
|
20 |
-
handle.close()
|
21 |
-
|
22 |
-
title = article.find("article-title")
|
23 |
-
title = title.text if title else "No title"
|
24 |
-
|
25 |
-
abstract = article.find("abstract")
|
26 |
-
abstract = abstract.text if abstract else "No abstract"
|
27 |
-
|
28 |
-
articles.append({
|
29 |
-
"id": id,
|
30 |
-
"title": title,
|
31 |
-
"abstract": abstract
|
32 |
-
})
|
33 |
-
|
34 |
-
return str(articles)
|
35 |
-
|
36 |
-
@tool
|
37 |
-
def google_scholar_search(query: str) -> str:
|
38 |
-
"""Search Google Scholar for articles"""
|
39 |
-
search_query = scholarly.search_pubs(query)
|
40 |
-
results = []
|
41 |
-
count = 0
|
42 |
-
|
43 |
-
for result in search_query:
|
44 |
-
if count >= 10:
|
45 |
-
break
|
46 |
-
pub = {
|
47 |
-
"title": result.bib.get('title', 'No title'),
|
48 |
-
"author": result.bib.get('author', 'No author'),
|
49 |
-
"year": result.bib.get('year', 'No year'),
|
50 |
-
"abstract": result.bib.get('abstract', 'No abstract')
|
51 |
-
}
|
52 |
-
results.append(pub)
|
53 |
-
count += 1
|
54 |
-
|
55 |
-
return str(results)
|
56 |
-
|
57 |
-
@tool
|
58 |
-
def today_tool() -> str:
|
59 |
-
"""Get today's date"""
|
60 |
-
return str(datetime.date.today())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|