major update
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
"""Sentiment router — sentiment data endpoints."""
|
||||
|
||||
import json
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.dependencies import get_db, require_access
|
||||
from app.schemas.common import APIEnvelope
|
||||
from app.schemas.sentiment import SentimentResponse, SentimentScoreResult
|
||||
from app.schemas.sentiment import CitationItem, SentimentResponse, SentimentScoreResult
|
||||
from app.services.sentiment_service import (
|
||||
compute_sentiment_dimension_score,
|
||||
get_sentiment_scores,
|
||||
@@ -14,6 +16,17 @@ from app.services.sentiment_service import (
|
||||
router = APIRouter(tags=["sentiment"])
|
||||
|
||||
|
||||
def _parse_citations(citations_json: str) -> list[CitationItem]:
|
||||
"""Deserialize citations_json, defaulting to [] on invalid JSON."""
|
||||
try:
|
||||
raw = json.loads(citations_json)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
return []
|
||||
if not isinstance(raw, list):
|
||||
return []
|
||||
return [CitationItem(**item) for item in raw if isinstance(item, dict)]
|
||||
|
||||
|
||||
@router.get("/sentiment/{symbol}", response_model=APIEnvelope)
|
||||
async def read_sentiment(
|
||||
symbol: str,
|
||||
@@ -36,6 +49,8 @@ async def read_sentiment(
|
||||
confidence=s.confidence,
|
||||
source=s.source,
|
||||
timestamp=s.timestamp,
|
||||
reasoning=s.reasoning,
|
||||
citations=_parse_citations(s.citations_json),
|
||||
)
|
||||
for s in scores
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user