Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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=trueadds asummaryfield. It requires--openai.api-key, a configured server token and a validtokenquery parameter.--openai.api-key,--openai.model(defaultgpt-6-luna),--openai.summary-promptand--openai.max-content-length(characters).expires_atremoves old entries, and expired entries are never returned.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 ./...andgolangci-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=truereturns 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.