File size: 3,151 Bytes
2a5c31d | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | """
Paper Research API - Search arXiv, Semantic Scholar, OpenAlex.
"""
from fastapi import APIRouter, Query
from pydantic import BaseModel
from typing import Optional
from src.agents.paper_research_agent import PaperResearchAgent
router = APIRouter(prefix="/papers", tags=["papers", "research"])
class PaperSearchRequest(BaseModel):
"""Request model for paper search."""
query: str = Query(..., min_length=3, max_length=500,
description="Search query for academic papers")
source: str = Query("all",
description="Source: arxiv, semantic, openalex, or all")
max_results: int = Query(5, ge=1, le=50,
description="Max results per source")
store_in_memory: bool = Query(True,
description="Store results in memory for learning")
@router.post("/search")
async def search_papers(request: PaperSearchRequest) -> dict:
"""
Search academic papers across arXiv, Semantic Scholar, and OpenAlex.
"""
agent = PaperResearchAgent()
result = await agent.execute(
context=None,
query=request.query,
source=request.source,
max_results=request.max_results,
store_in_memory=request.store_in_memory
)
return result
@router.get("/search")
async def search_papers_get(
query: str = Query(..., min_length=3, max_length=500),
source: str = "all",
max_results: int = 5,
store_in_memory: bool = True
) -> dict:
"""
GET endpoint for searching papers.
"""
agent = PaperResearchAgent()
result = await agent.execute(
context=None,
query=query,
source=source,
max_results=max_results,
store_in_memory=store_in_memory
)
return result
@router.post("/arxiv")
async def search_arxiv(
query: str = Query(..., min_length=3, max_length=500),
max_results: int = 5,
store_in_memory: bool = True
) -> dict:
"""Search arXiv papers only."""
agent = PaperResearchAgent()
result = await agent.execute(
context=None,
query=query,
source="arxiv",
max_results=max_results,
store_in_memory=store_in_memory
)
return result
@router.post("/semantic")
async def search_semantic(
query: str = Query(..., min_length=3, max_length=500),
max_results: int = 5,
store_in_memory: bool = True
) -> dict:
"""Search Semantic Scholar papers only."""
agent = PaperResearchAgent()
result = await agent.execute(
context=None,
query=query,
source="semantic",
max_results=max_results,
store_in_memory=store_in_memory
)
return result
@router.post("/openalex")
async def search_openalex(
query: str = Query(..., min_length=3, max_length=500),
max_results: int = 5,
store_in_memory: bool = True
) -> dict:
"""Search OpenAlex papers only."""
agent = PaperResearchAgent()
result = await agent.execute(
context=None,
query=query,
source="openalex",
max_results=max_results,
store_in_memory=store_in_memory
)
return result
|