sentiment.py 653 B

123456789101112131415161718
  1. """AI 舆情分析流式 API — 实现方案约定路径"""
  2. from fastapi import APIRouter
  3. from fastapi.responses import StreamingResponse
  4. from app.api.agent_api import AnalysisRequest, iter_sentiment_analysis_ndjson
  5. router = APIRouter(prefix="/sentiment", tags=["AI舆情分析"])
  6. @router.post("/analyze/stream")
  7. async def sentiment_analyze_stream(body: AnalysisRequest):
  8. """POST /api/v1/sentiment/analyze/stream"""
  9. return StreamingResponse(
  10. iter_sentiment_analysis_ndjson(body.stock_code, body.stock_name),
  11. media_type="application/x-ndjson",
  12. headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"},
  13. )