read.markets/app/schemas.py
Giorgio Gilestro 2013bfa8cc news: auto-tag headlines + market-aware cadence + filter UI
- Move news_job from hourly to 3x/hour (cron 10,30,50), with a CadencePolicy
  gate that throttles to active hours (07-21 UTC weekdays at 20 min), off-hours
  (3 h), weekends (6 h). Keeps the daytime feed fresh without spamming RSS
  sources overnight.
- Tag each headline on ingestion via DeepSeek (BATCH_SIZE=25, max_tokens=4000,
  json.JSONDecoder().raw_decode + per-row regex recovery for resilient parsing).
  Vocabulary: 16 tags including new EU / USA / AI / Conflict. NULL tags are
  picked up automatically on the next news_job run, so back-tagging is implicit
  rather than a separate migration step.
- Tag UI: pill bar above the feed with off → include → exclude cycle on click;
  shift-click jumps straight to exclude. State persists in localStorage and is
  injected into /api/news requests via htmx:configRequest. Per-row chips sit to
  the right of the headline (new 5-column grid: age | source | title | tags |
  UTC) so vertical density stays high.
- Strategic log header bug: model was hallucinating "(Updated 21:30 UTC)" in
  future tense. Bumped PROMPT_VERSION 6→7, added explicit ban on time-of-day
  clauses, and supply the actual current UTC time in the user prompt so the
  model has no need to invent one.

Migration 0012 adds headlines.tags (JSON, nullable). Tests cover vocabulary
integrity, validation/normalisation, and the JSON-recovery parser (17 tests).
2026-05-21 23:25:03 +01:00

55 lines
1.2 KiB
Python

"""Pydantic response shapes for the JSON API."""
from __future__ import annotations
from datetime import datetime
from pydantic import BaseModel
class QuoteOut(BaseModel):
symbol: str
source: str
label: str
group_name: str
price: float | None
currency: str | None
as_of: str | None
changes: dict | None
fetched_at: datetime
error: str | None = None
class HeadlineOut(BaseModel):
source: str
category: str
title: str
url: str
published_at: datetime
tags: list[str] | None = None # populated by news_tagging; null = pending
class JobStatus(BaseModel):
name: str
last_started: datetime | None = None
last_finished: datetime | None = None
status: str | None = None
error: str | None = None
items_written: int | None = None
class HealthOut(BaseModel):
db: str # "ok" | "down"
jobs: list[JobStatus]
class StrategicLogOut(BaseModel):
generated_at: datetime
model: str
anchor_date: str | None
content: str
prompt_tokens: int | None
completion_tokens: int | None
# PositionOut / PortfolioSummary removed in Phase G — the server no
# longer holds positions; the browser computes P/L from /api/universe.