Skip to content

Add AI fallback for multi-recipe detection#74

Merged
windoze95 merged 2 commits intomainfrom
fix/multi-recipe-ai-detection
Apr 5, 2026
Merged

Add AI fallback for multi-recipe detection#74
windoze95 merged 2 commits intomainfrom
fix/multi-recipe-ai-detection

Conversation

@windoze95
Copy link
Copy Markdown
Owner

Summary

Fixes multi-recipe pages always showing a single recipe.

Root cause: Detection relied entirely on JSON-LD Recipe blocks, but most listicle pages ("Top 10 Pasta Recipes") don't embed separate JSON-LD per recipe — they use plain HTML cards. So detection always returned <=1 recipes and fell through to single-recipe extraction.

Fix: When JSON-LD finds <=1 recipes, use Claude (via CookingQA) to scan the page and list all distinct recipe titles. If multiple found, create cards and start background extraction.

  • detectMultipleRecipesFromHTML(): AI-based detection with truncated HTML (80KB)
  • ResolveFromHTML(): tries JSON-LD first, then AI fallback
  • PreviewFromURLWithMultiCheck: delegates all detection to ResolveFromHTML

Test plan

  • go build && go vet && go test ./internal/... pass
  • Click a multi-recipe search result (e.g. "top 10 pasta recipes") — returns is_multi: true with individual cards
  • Click a single-recipe result — normal preview, no AI detection call

🤖 Generated with Claude Code

Root cause: most multi-recipe listicle pages don't embed separate
JSON-LD Recipe blocks per recipe. They typically have 0-1 JSON-LD
blocks (article-level or for a featured recipe), with the rest as
plain HTML. The detection relied entirely on JSON-LD, so it always
fell through to single-recipe extraction.

Fix: when JSON-LD finds <=1 recipes, use Claude (via CookingQA)
to scan the page HTML and list all distinct recipe titles. If multiple
found, create cards and start background extraction for each.

- detectMultipleRecipesFromHTML(): AI-based detection with truncated
  HTML (80KB), returns card list or nil
- ResolveFromHTML() now tries JSON-LD first, then AI fallback
- PreviewFromURLWithMultiCheck simplified: delegates all detection
  (JSON-LD + AI) to ResolveFromHTML instead of checking JSON-LD
  separately

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e307e7233b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/service/multi_recipe.go Outdated
Prevents untrusted page HTML from producing unbounded card lists
via prompt injection or malformed CookingQA responses. Also drops
lines longer than 200 chars (not recipe titles).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@windoze95 windoze95 merged commit 4cc441e into main Apr 5, 2026
1 check passed
@windoze95 windoze95 deleted the fix/multi-recipe-ai-detection branch April 5, 2026 05:49
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