diff --git a/frontend/lang/messages/en-US.json b/frontend/lang/messages/en-US.json index 14135736e05d..967248ca9375 100644 --- a/frontend/lang/messages/en-US.json +++ b/frontend/lang/messages/en-US.json @@ -583,6 +583,8 @@ "report-deletion-failed": "Report deletion failed", "recipe-debugger": "Recipe Debugger", "recipe-debugger-description": "Grab the URL of the recipe you want to debug and paste it here. The URL will be scraped by the recipe scraper and the results will be displayed. If you don't see any data returned, the site you are trying to scrape is not supported by Mealie or its scraper library.", + "use-openai": "Use OpenAI", + "recipe-debugger-use-openai-description": "Use OpenAI to parse the results instead of relying on the scraper library. When creating a recipe via URL, this is done automatically if the scraper library fails, but you may test it manually here.", "debug": "Debug", "tree-view": "Tree View", "recipe-yield": "Recipe Yield", diff --git a/frontend/lib/api/user/recipes/recipe.ts b/frontend/lib/api/user/recipes/recipe.ts index c036bcf33cf4..f899d3b4bb57 100644 --- a/frontend/lib/api/user/recipes/recipe.ts +++ b/frontend/lib/api/user/recipes/recipe.ts @@ -128,8 +128,8 @@ export class RecipeAPI extends BaseCRUDAPI { return this.requests.post(routes.recipesRecipeSlugImage(slug), { url }); } - async testCreateOneUrl(url: string) { - return await this.requests.post(routes.recipesTestScrapeUrl, { url }); + async testCreateOneUrl(url: string, useOpenAI = false) { + return await this.requests.post(routes.recipesTestScrapeUrl, { url, useOpenAI }); } async createOneByUrl(url: string, includeTags: boolean) { diff --git a/frontend/pages/g/_groupSlug/r/create/debug.vue b/frontend/pages/g/_groupSlug/r/create/debug.vue index ff5c218cbfb0..77b43e8b38f5 100644 --- a/frontend/pages/g/_groupSlug/r/create/debug.vue +++ b/frontend/pages/g/_groupSlug/r/create/debug.vue @@ -18,7 +18,11 @@ :rules="[validators.url]" :hint="$t('new-recipe.url-form-hint')" persistent-hint - > + /> + + + {{ $t('recipe.recipe-debugger-use-openai-description') }} +
@@ -51,7 +55,7 @@ ' + "" + ) + except Exception: + self.logger.exception(f"OpenAI was unable to extract a recipe from {url}") + return "" + + class RecipeScraperOpenGraph(ABCScraperStrategy): async def get_html(self, url: str) -> str: - return await safe_scrape_html(url) + return self.raw_html or await safe_scrape_html(url) def get_recipe_fields(self, html) -> dict | None: """ diff --git a/tests/unit_tests/test_ingredient_parser.py b/tests/unit_tests/test_ingredient_parser.py index 598cec2451da..dcfe1ae0fa7c 100644 --- a/tests/unit_tests/test_ingredient_parser.py +++ b/tests/unit_tests/test_ingredient_parser.py @@ -9,6 +9,7 @@ from pydantic import UUID4 from mealie.db.db_setup import session_context from mealie.repos.repository_factory import AllRepositories +from mealie.schema.openai.recipe_ingredient import OpenAIIngredient, OpenAIIngredients from mealie.schema.recipe.recipe_ingredient import ( CreateIngredientFood, CreateIngredientFoodAlias, @@ -24,8 +25,10 @@ from mealie.schema.recipe.recipe_ingredient import ( from mealie.schema.user.user import GroupBase from mealie.services.openai import OpenAIService from mealie.services.parser_services import RegisteredParser, get_parser -from mealie.services.parser_services.crfpp.processor import CRFIngredient, convert_list_to_crf_model -from mealie.services.parser_services.openai.parser import OpenAIIngredient, OpenAIIngredients +from mealie.services.parser_services.crfpp.processor import ( + CRFIngredient, + convert_list_to_crf_model, +) from tests.utils.factories import random_int, random_string