File size: 1,198 Bytes
cacd912
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from scholarly import scholarly

def fetch_latest_research_papers(keywords: list, num_results: int = 5) -> list:
    """Fetches the latest research papers from Google Scholar based on provided keywords.
    
    Args:
        keywords: A list of keywords to search for relevant papers.
        num_results: The number of papers to fetch (default is 5).
    
    Returns:
        A list of dictionaries containing paper details.
    """
    try:
        query = " ".join(keywords)
        search_results = scholarly.search_pubs(query)
        papers = []
        for i in range(num_results):
            paper = next(search_results, None)
            if paper:
                papers.append({
                    "title": paper['bib'].get('title', 'No Title'),
                    "authors": paper['bib'].get('author', 'Unknown Authors'),
                    "year": paper['bib'].get('pub_year', 'Unknown Year'),
                    "abstract": paper['bib'].get('abstract', 'No Abstract Available'),
                    "link": paper.get('pub_url', 'No Link Available')
                })
        return papers
    except Exception as e:
        return [f"Error fetching research papers: {str(e)}"]