major update
Some checks failed
Deploy / lint (push) Failing after 8s
Deploy / test (push) Has been skipped
Deploy / deploy (push) Has been skipped

This commit is contained in:
Dennis Thiessen
2026-02-27 16:08:09 +01:00
parent 61ab24490d
commit 181cfe6588
71 changed files with 7647 additions and 281 deletions

View File

@@ -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
],