Skip to content

Suggest article selectors with OpenAI on request - #74

Open
paskal wants to merge 1 commit into
masterfrom
openai-auto-extraction
Open

paskal wants to merge 1 commit into
masterfrom
openai-auto-extraction

Conversation

@paskal

@paskal paskal commented Mar 29, 2026 •

Copy link
Copy Markdown
Member

Previously, this PR evaluated every extraction with OpenAI and saved the suggested selector as an enabled rule, which cost an API call on each request for domains without a rule and saved a selector without checking its result. This change replaces it with an explicit action on top of the OpenAI configuration from #92.

  • POST /api/content-parsed-wrong?url=... is protected by the same credentials as the rule management routes. Selectors are requested only from this endpoint, never during extraction or preview.
  • The model receives an outline of the page body (tags, ids, classes, text length, paragraph count and the start of the text) instead of the first characters of the raw HTML. It answers with a selector in JSON mode, using the model from --openai.model.
  • A selector is accepted only when it matches at least 200 characters of text, no more than 90% of the page text, and a text different from what is extracted now. A rejected selector goes back to the model with the reason, for up to three attempts. An API error ends the request without a retry.
  • An accepted selector is stored as a disabled rule through a new insert-only SaveIfAbsent, which leaves an existing rule of the domain untouched, enabled or not. In that case the suggestion is only returned. The response holds selector, saved and the page extracted with the selector, so it can be tried in the rule preview before it is enabled.
  • Fetching and the model calls share the 140-second per-request deadline used for summaries, which is 10 seconds under the server write timeout.

The README documents the endpoint. summaryID also ignores the hash writer's errors explicitly, which the current linter requires.

TestSuggestRule, TestPageOutline, TestServer_ContentParsedWrong and TestRulesSaveIfAbsent cover the checks, the saved rule, the existing-rule case, the request deadline and the credentials. Restoring each of these defects makes a test fail. A call with a real OpenAI key was not made.

@umputun
umputun deleted the branch master April 12, 2026 20:49
@umputun umputun closed this Apr 12, 2026
@paskal paskal reopened this May 13, 2026
@paskal
paskal force-pushed the openai-auto-extraction branch 2 times, most recently from ddc9c7b to 340218e Compare August 20, 2026 08:33
@paskal
paskal deleted the branch master August 20, 2026 08:33
@paskal paskal closed this Aug 20, 2026
@paskal paskal reopened this Aug 20, 2026
@paskal
paskal changed the base branch from modularise-retrieval to master August 20, 2026 08:33
@paskal
paskal force-pushed the openai-auto-extraction branch from 340218e to 4d707c6 Compare September 10, 2026 06:17
When a page is parsed wrong, an administrator can ask OpenAI for a CSS
selector of the article. The model sees an outline of the page body
instead of raw HTML, and a suggestion is accepted only after it is
applied to the page and matches a plausible amount of text that is
neither nearly the whole page nor what is extracted now. The selector is
stored as a disabled rule with an insert-only write, so an existing rule
of the domain is never replaced and nothing changes for readers until
the rule is enabled. OpenAI is never asked for a selector during normal
extraction. The request shares the per-request deadline used for
summaries.
@paskal
paskal force-pushed the openai-auto-extraction branch from 4d707c6 to 3dcd2de Compare October 18, 2026 12:15
@paskal paskal changed the title Auto-improve content extraction with OpenAI evaluation Suggest article selectors with OpenAI on request Oct 18, 2026
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.

2 participants