astock-agent/backend/app/api/catalysts.py
2026-05-14 17:02:13 +08:00

43 lines
1.3 KiB
Python

"""新闻/政策催化 API。"""
from fastapi import APIRouter, Depends
from app.catalyst.models import CatalystInput
from app.catalyst.service import (
build_theme_catalyst_scores,
get_recent_catalysts,
get_recent_news_items,
ingest_catalyst,
)
from app.core.deps import get_current_admin
from app.news.pipeline import refresh_news_catalysts
router = APIRouter(prefix="/api/catalysts", tags=["catalysts"])
@router.get("/recent")
async def recent(limit: int = 30, hours: int = 72):
return await get_recent_catalysts(limit=limit, hours=hours)
@router.get("/news")
async def news(limit: int = 50, hours: int = 24, status: str | None = None):
return await get_recent_news_items(limit=limit, hours=hours, status=status)
@router.get("/theme-scores")
async def theme_scores(hours: int = 72, limit: int = 20):
scores = await build_theme_catalyst_scores(hours=hours, limit=limit)
return [item.model_dump() for item in scores]
@router.post("/ingest")
async def ingest(item: CatalystInput, _admin: dict = Depends(get_current_admin)):
analysis = await ingest_catalyst(item, use_llm=True)
return analysis.model_dump()
@router.post("/refresh-news")
async def refresh_news(_admin: dict = Depends(get_current_admin)):
return await refresh_news_catalysts()