45 lines
1 KiB
Python
45 lines
1 KiB
Python
|
|
"""News article Pydantic schemas for Redis Stream messages."""
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
from pydantic import BaseModel, Field
|
||
|
|
|
||
|
|
|
||
|
|
class RawArticle(BaseModel):
|
||
|
|
"""Published to ``news:raw`` by the news fetcher."""
|
||
|
|
|
||
|
|
source: str
|
||
|
|
url: str
|
||
|
|
title: str
|
||
|
|
content: str
|
||
|
|
published_at: datetime | None = None
|
||
|
|
fetched_at: datetime
|
||
|
|
content_hash: str
|
||
|
|
|
||
|
|
model_config = {"from_attributes": True}
|
||
|
|
|
||
|
|
|
||
|
|
class ScoredArticle(BaseModel):
|
||
|
|
"""Published to ``news:scored`` by the sentiment analyzer.
|
||
|
|
|
||
|
|
Inherits all fields from RawArticle conceptually plus scoring metadata.
|
||
|
|
"""
|
||
|
|
|
||
|
|
# Original article fields
|
||
|
|
source: str
|
||
|
|
url: str
|
||
|
|
title: str
|
||
|
|
content: str
|
||
|
|
published_at: datetime | None = None
|
||
|
|
fetched_at: datetime
|
||
|
|
content_hash: str
|
||
|
|
|
||
|
|
# Scoring fields
|
||
|
|
ticker: str
|
||
|
|
sentiment_score: float = Field(ge=-1.0, le=1.0)
|
||
|
|
confidence: float = Field(ge=0.0, le=1.0)
|
||
|
|
model_used: str
|
||
|
|
entities: list[str] = Field(default_factory=list)
|
||
|
|
|
||
|
|
model_config = {"from_attributes": True}
|