Revert "feat: rebuild news summarizer on local Ollama"
This reverts commit 58ff43bdee.
This commit is contained in:
parent
58ff43bdee
commit
c10b617f1f
15 changed files with 339 additions and 336 deletions
73
docs/news.md
73
docs/news.md
|
|
@ -1,12 +1,11 @@
|
|||
# News pipeline — scraper + local Ollama summarizer
|
||||
# News pipeline — scraper + Nous Portal summarizer
|
||||
|
||||
The OSINT dashboard ingests ~257 global news RSS sources hourly and produces
|
||||
an English LLM brief plus flagged ticker/map rows. Both services were vendored
|
||||
from the upstream `~/Projects/newsPipeline` project and re-integrated here to
|
||||
replace the old k8s CronJob choreography with in-compose scheduling against
|
||||
the EXISTING osint-db — **no second Postgres**. The LLM is **local Ollama**
|
||||
(`LLM_URL`, default `http://127.0.0.1:11434`) — the newsPipeline `local_llm`
|
||||
path (`POST /api/generate`). No API key.
|
||||
the EXISTING osint-db — **no second Postgres**. The LLM is **Nous Portal**
|
||||
(`inference-api.nousresearch.com`) — not Gemini.
|
||||
|
||||
## Architecture
|
||||
|
||||
|
|
@ -17,7 +16,7 @@ path (`POST /api/generate`). No API key.
|
|||
news-scraper (Scrapy, hourly :00) ──► articles table (osint-db)
|
||||
│ │
|
||||
│ ▼
|
||||
news-summarizer (Ollama map-reduce, :05) ──► article_summaries + news_items
|
||||
news-summarizer (Nous Portal map-reduce, :05) ──► article_summaries + news_items
|
||||
│
|
||||
▼
|
||||
GET /api/news · /api/news/summaries · /api/news/ticker · /api/news/map
|
||||
|
|
@ -47,8 +46,8 @@ feeds (`GET /api/news` exact key set is unchanged on purpose).
|
|||
(`ON CONFLICT (url) DO NOTHING`).
|
||||
2. **Summarizer** — `news/summerizer/run_news_summarizer.py` runs
|
||||
`summarizer.py` at :05 past each hour. It reads articles from the last
|
||||
`SUMMARY_WINDOW_HOURS`, map-reduces them through local Ollama
|
||||
(`SUMMARY_MODEL` / Settings, default `qwen3:30b-a3b`), writes the English
|
||||
`SUMMARY_WINDOW_HOURS`, map-reduces them through Nous Portal
|
||||
(`SUMMARY_MODEL` / Settings, default `Hermes-4.3-36B`), writes the English
|
||||
brief to `article_summaries` (column `model` is the LLM id), and flagged
|
||||
ticker/map rows to `news_items`.
|
||||
|
||||
|
|
@ -68,16 +67,17 @@ Container startup order doesn't matter.
|
|||
|
||||
## Keys and Settings
|
||||
|
||||
- **No API key.** Ollama on the GPU host; the summarizer container calls
|
||||
`LLM_URL` (`POST /api/generate`, `GET /api/tags`).
|
||||
- **Idle without Ollama** — if `/api/tags` is down or the chosen model is not
|
||||
pulled, the summarizer logs and idles (never crashes). News intel APIs
|
||||
return `[]`.
|
||||
- **`NOUS_API_KEY`** — paste in the dashboard **Keys** UI (`api_keys` /
|
||||
`keystore.KEY_REGISTRY`). Env / `.env` is an **override** (env wins, same
|
||||
as FIRMS). Never returned by any API; never emitted into `index.html`;
|
||||
never proxied from the browser.
|
||||
- **Idle without a key** — if env is unset **and** the keystore row is empty,
|
||||
the summarizer logs and idles (never crashes). News intel APIs return `[]`.
|
||||
- **Model** — non-secret. Settings UI model selector `PUT /api/settings`
|
||||
`{ "summary_model": "…" }` stores `SUMMARY_MODEL` in `app_settings` (1–128
|
||||
chars). `GET /api/settings` echoes `{summary_model, llm_url}`.
|
||||
`llm_url` is read-only. Default `qwen3:30b-a3b`. Live catalog is
|
||||
best-effort `GET /api/news/models` (`GET {LLM_URL}/api/tags`).
|
||||
chars). `GET /api/settings` echoes `{summary_model, nous_base_url}`.
|
||||
`nous_base_url` is read-only. Default `Hermes-4.3-36B`. Live catalog is
|
||||
best-effort `GET /api/news/models`.
|
||||
|
||||
## Endpoints
|
||||
|
||||
|
|
@ -192,15 +192,15 @@ Never 502s. `{ "source": "live"|"fallback", "models": [{"id": "…"}] }`.
|
|||
### GET /api/settings · PUT /api/settings
|
||||
|
||||
```json
|
||||
{ "summary_model": "qwen3:30b-a3b", "llm_url": "http://127.0.0.1:11434" }
|
||||
{ "summary_model": "Hermes-4.3-36B", "nous_base_url": "https://inference-api.nousresearch.com/v1" }
|
||||
```
|
||||
|
||||
PUT body is `{ "summary_model": "<1–128 char id>" }`. `llm_url` is
|
||||
PUT body is `{ "summary_model": "<1–128 char id>" }`. `nous_base_url` is
|
||||
ignored even if sent.
|
||||
|
||||
## Reduce JSON contract
|
||||
|
||||
Reduce phase (`format: json` on Ollama generate, English only) must be a single
|
||||
Reduce phase (`response_format: json_object`, English only) must be a single
|
||||
object. Parser (`intel.parse_reduce_json`) strips `<think>…</think>` and
|
||||
markdown json fences, then brace-slices:
|
||||
|
||||
|
|
@ -234,8 +234,9 @@ lands in `article_summaries.summary_text`.
|
|||
|
||||
| Var | Default | Notes |
|
||||
|---|---|---|
|
||||
| `LLM_URL` | `http://127.0.0.1:11434` | Ollama origin. Pi container must point at the GPU host (e.g. Tailscale). Compose leaves this empty so `.env` wins. |
|
||||
| `SUMMARY_MODEL` | `qwen3:30b-a3b` | Leave compose unset so Settings → `app_settings.SUMMARY_MODEL` reaches the worker. Env wins when set. |
|
||||
| `NOUS_API_KEY` | *(blank)* | **Required for summaries.** Prefer Keys UI; env overrides. Unset in **both** env and `api_keys` = summarizer logs and idles (never crashes); APIs return `[]`. |
|
||||
| `NOUS_BASE_URL` | `https://inference-api.nousresearch.com/v1` | Read-only in Settings. |
|
||||
| `SUMMARY_MODEL` | `Hermes-4.3-36B` | Compose default. Operator-facing choice is Settings → `app_settings.SUMMARY_MODEL`. |
|
||||
| `NEWS_BATCH_SIZE` | `50` | Articles per map-phase batch (compose maps to container `BATCH_SIZE`). |
|
||||
| `SUMMARY_WINDOW_HOURS` | `1` | How far back the summarizer looks for new articles. |
|
||||
| `INCLUDE_FUTURES` | `0` | Legacy futures-prices coupling (upstream pipeline). OFF for OSINT; set `1` + install `yfinance` to enable. |
|
||||
|
|
@ -245,14 +246,15 @@ lands in `article_summaries.summary_text`.
|
|||
| `NEWS_SUMMARIZE_RUN_ON_START` | `1` | Run one summarize immediately on container start. |
|
||||
| `NEWS_SUMMARIZE_FORCE` | `0` | `1` ignores the current-UTC-hour idempotency skip (double-pins on recreate). |
|
||||
| `NEWS_LOG_LEVEL` | `INFO` | Scrapy log level. |
|
||||
| `OSINT_USER_AGENT` | `osint-dashboard-news-summarizer` | Sent on every outbound Ollama call. |
|
||||
| `OSINT_USER_AGENT` | `osint-dashboard-news-summarizer` | Sent on every outbound Nous call. |
|
||||
| `TELEGRAM_TOKEN` / `TELEGRAM_CHAT_ID` | *(blank)* | Reserved for the (out-of-scope) Telegram delivery bot. |
|
||||
|
||||
DB_* for both services is mapped to the shared osint-db credentials
|
||||
(`DB_HOST=db`, same `DB_USER/DB_PASSWORD/DB_NAME` as the rest of the stack).
|
||||
|
||||
Ollama generate: `POST {LLM_URL}/api/generate` via `news/summerizer/ollama_client.py`
|
||||
(`httpx`, no `ollama` Python SDK). No API key. Reduce uses `format: json`.
|
||||
Nous chat: `POST {NOUS_BASE_URL}/chat/completions` via `news/summerizer/nous_client.py`
|
||||
(`httpx`, no `openai` SDK). Auth is a Bearer token from `NOUS_API_KEY`.
|
||||
No Hermes-4 reasoning system prompt. Reduce uses `json_mode=True`.
|
||||
|
||||
## Prompts
|
||||
|
||||
|
|
@ -266,7 +268,7 @@ language is gated behind `INCLUDE_FUTURES=1`.
|
|||
|
||||
```bash
|
||||
PYTHONPATH=news/summerizer pytest news/summerizer/tests -v
|
||||
# intel + ollama_client tests PASS (no network)
|
||||
# intel + nous_client tests PASS (no network)
|
||||
|
||||
PYTHONPATH=app pytest tests/test_api_news.py \
|
||||
tests/test_api_settings.py tests/test_api_live_layers.py -v
|
||||
|
|
@ -278,17 +280,16 @@ PYTHONPATH=app pytest tests/test_api_news.py \
|
|||
|
||||
After deploy / compose rebuild of `news-summarizer` on the Pi:
|
||||
|
||||
1. Run Ollama on the GPU host and pull the model (`ollama pull qwen3:30b-a3b`).
|
||||
2. Set `LLM_URL` on the Pi to that host (Tailscale IP + `:11434`).
|
||||
3. Settings: pick a model → Save → `GET /api/settings` echoes it.
|
||||
4. `docker compose --profile ingest logs -f news-summarizer` — next run (or
|
||||
1. Keys UI: save `NOUS_API_KEY` → status `****last4`.
|
||||
2. Settings: pick a model → Save → `GET /api/settings` echoes it.
|
||||
3. `docker compose --profile ingest logs -f news-summarizer` — next run (or
|
||||
`NEWS_SUMMARIZE_RUN_ON_START=1` recreate) logs `Processing N articles with <model>`.
|
||||
5. `curl -s localhost:8000/api/news/summaries?limit=1` — English `summary_text`, `model` set.
|
||||
6. `curl -s localhost:8000/api/news/ticker` — flagged headlines only.
|
||||
7. `curl -s localhost:8000/api/news/map` — only rows with lat/lon.
|
||||
8. HUD: NEWS ticker scrolls flagged items; map overlay pins popup with location.
|
||||
9. Ollama down / model missing → summarizer logs idle, APIs return `[]`, no crash.
|
||||
4. `curl -s localhost:8000/api/news/summaries?limit=1` — English `summary_text`, `model` set.
|
||||
5. `curl -s localhost:8000/api/news/ticker` — flagged headlines only.
|
||||
6. `curl -s localhost:8000/api/news/map` — only rows with lat/lon.
|
||||
7. HUD: NEWS ticker scrolls flagged items; map overlay pins popup with location.
|
||||
8. Unset key + empty keystore → summarizer logs idle, APIs return `[]`, no crash.
|
||||
|
||||
**Operator action after merge:** start Ollama on the laptop GPU, set `LLM_URL`
|
||||
in Pi `.env`, pick a model in Settings if the default `qwen3:30b-a3b` is not
|
||||
wanted; rebuild `osint-news-summarizer` on the Pi (`pi-app-deploy` / compose).
|
||||
**Operator action after merge:** paste a Nous Portal API key in API Keys; pick
|
||||
a model in Settings if the default `Hermes-4.3-36B` is not wanted; rebuild
|
||||
`osint-news-summarizer` on the Pi (`pi-app-deploy` / compose).
|
||||
|
|
|
|||
Loading…
Reference in a new issue