Skip to content

Add OpenAI article summaries - #92

Open
paskal wants to merge 1 commit into
masterfrom
openai-summaries
Open

paskal wants to merge 1 commit into
masterfrom
openai-summaries

Conversation

@paskal

@paskal paskal commented Oct 11, 2026

Copy link
Copy Markdown
Member

Previously, the summary feature was in #32, stacked on the auto-extraction branch. This change brings it to master on its own and adds optional OpenAI article summaries to the parser API and rule previews.

  • GET /api/content/v1/parser?...&summary=true adds a summary field. It requires --openai.api-key, a configured server token and a valid token query parameter.
  • When the key is set, rule previews in the web UI show the summary as escaped text.
  • The configuration options are --openai.api-key, --openai.model (default gpt-6-luna), --openai.summary-prompt and --openai.max-content-length (characters).
  • Summaries are cached in MongoDB for 30 days, keyed by model, prompt and the article text sent to OpenAI. A TTL index on expires_at removes old entries, and expired entries are never returned.
  • Extraction and summaries share a 140-second budget per request, so the response is written before the 150-second server write timeout. Previews extract every URL first and then summarise them in order with the time left; URLs reached after the budget is spent are shown without a summary.

Compared with #32: the OpenAI client is created once at startup, input is truncated by characters instead of bytes, model output is no longer rendered as raw HTML, an empty reply is an error instead of a panic, and the metrics endpoint, rate limiter and cleanup goroutine are removed.

Validation used go test -race ./... and golangci-lint. Each new test was checked to fail with its defect restored: preview escaping (TestServer_PreviewSummaryIsEscaped), truncation and empty replies (TestGenerateSummary), the TTL index (TestSummariesTTLIndex), expiry filtering (TestSummariesSaveAndGet), cache-key inputs (TestSummaryID) and the request budget (TestServer_SummaryBudget). The new summary datastore tests use testcontainers. The Docker image was also run against MongoDB 7: the TTL index is created, summary=true returns 400 without a key, and with a placeholder key the request reaches the OpenAI API and is rejected there for the key. A call with a real key was not made.

This replaces #32 and is related to #27.

Parser API clients can request a short summary with the extracted text,
and rule previews show one. The OpenAI client is created at startup,
input is truncated by characters, model output is escaped in the
preview, empty replies are errors, and summaries are cached in MongoDB
for 30 days behind a TTL index. Summary calls share a per-request budget
so the response is written before the server write timeout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant