study-buddy / app /routers /wiki.py
GitHub Actions
deploy d092bea3608b7a29952f16357fda39b7a29e399b
2e818da
Raw
History Blame Contribute Delete
607 Bytes
from __future__ import annotations
from fastapi import APIRouter, HTTPException
from app.services.wikipedia_service import WikipediaService
router = APIRouter(prefix="/api/wiki", tags=["wiki"])
_service = WikipediaService()
@router.get("/search")
async def search_wikipedia(q: str):
return {"items": [item.model_dump() for item in await _service.search(q)]}
@router.get("/page")
async def get_wikipedia_page(title: str):
try:
return (await _service.page(title)).model_dump()
except Exception as exc:
raise HTTPException(404, f"Wikipedia page not found: {title}") from exc