mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-12 10:53:12 -05:00
Feature/CRF++ and server side locales (#731)
* add universal toast plugin * add server side locales * integrate CRF++ into CI/CD Pipeline * docs(docs): 📝 add recipe parser docs * feat(backend): ✨ Continued work on ingredient parsers * add new model dest * feat(frontend): ✨ New ingredient parser page * formatting Co-authored-by: Hayden <hay-kot@pm.me>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from . import admin, app, auth, categories, groups, recipe, shopping_lists, tags, unit_and_foods, users
|
||||
from . import admin, app, auth, categories, groups, parser, recipe, shopping_lists, tags, unit_and_foods, users
|
||||
|
||||
router = APIRouter(prefix="/api")
|
||||
|
||||
@@ -9,6 +9,7 @@ router.include_router(auth.router)
|
||||
router.include_router(users.router)
|
||||
router.include_router(groups.router)
|
||||
router.include_router(recipe.router)
|
||||
router.include_router(parser.router)
|
||||
router.include_router(unit_and_foods.router)
|
||||
router.include_router(categories.router)
|
||||
router.include_router(tags.router)
|
||||
|
||||
6
mealie/routes/parser/__init__.py
Normal file
6
mealie/routes/parser/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from . import ingredient_parser
|
||||
|
||||
router = APIRouter()
|
||||
router.include_router(ingredient_parser.public_router, tags=["Recipe: Ingredient Parser"])
|
||||
31
mealie/routes/parser/ingredient_parser.py
Normal file
31
mealie/routes/parser/ingredient_parser.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel
|
||||
|
||||
from mealie.schema.recipe import RecipeIngredient
|
||||
from mealie.services.parser_services import IngredientParserService
|
||||
|
||||
public_router = APIRouter(prefix="/parser")
|
||||
|
||||
|
||||
class IngredientsRequest(BaseModel):
|
||||
ingredients: list[str]
|
||||
|
||||
|
||||
class IngredientRequest(BaseModel):
|
||||
ingredient: str
|
||||
|
||||
|
||||
@public_router.post("/ingredients", response_model=list[RecipeIngredient])
|
||||
def parse_ingredients(
|
||||
ingredients: IngredientsRequest,
|
||||
p_service: IngredientParserService = Depends(IngredientParserService.private),
|
||||
):
|
||||
return {"ingredients": p_service.parse_ingredients(ingredients.ingredients)}
|
||||
|
||||
|
||||
@public_router.post("/ingredient")
|
||||
def parse_ingredient(
|
||||
ingredient: IngredientRequest,
|
||||
p_service: IngredientParserService = Depends(IngredientParserService.private),
|
||||
):
|
||||
return {"ingredient": p_service.parse_ingredient(ingredient.ingredient)}
|
||||
@@ -1,13 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from mealie.routes.recipe import (
|
||||
all_recipe_routes,
|
||||
comments,
|
||||
image_and_assets,
|
||||
ingredient_parser,
|
||||
recipe_crud_routes,
|
||||
recipe_export,
|
||||
)
|
||||
from . import all_recipe_routes, comments, image_and_assets, recipe_crud_routes, recipe_export
|
||||
|
||||
prefix = "/recipes"
|
||||
|
||||
@@ -18,4 +11,3 @@ router.include_router(recipe_export.user_router, prefix=prefix, tags=["Recipe: E
|
||||
router.include_router(recipe_crud_routes.user_router, prefix=prefix, tags=["Recipe: CRUD"])
|
||||
router.include_router(image_and_assets.user_router, prefix=prefix, tags=["Recipe: Images and Assets"])
|
||||
router.include_router(comments.router, prefix=prefix, tags=["Recipe: Comments"])
|
||||
router.include_router(ingredient_parser.public_router, tags=["Recipe: Ingredient Parser"])
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
|
||||
from mealie.services.scraper.ingredient_nlp.processor import (
|
||||
convert_crf_models_to_ingredients,
|
||||
convert_list_to_crf_model,
|
||||
)
|
||||
|
||||
public_router = APIRouter()
|
||||
|
||||
|
||||
class IngredientRequest(BaseModel):
|
||||
ingredients: list[str]
|
||||
|
||||
|
||||
@public_router.post("/parse/ingredient")
|
||||
def parse_ingredients(ingredients: IngredientRequest):
|
||||
"""
|
||||
Parse an ingredient string.
|
||||
"""
|
||||
|
||||
crf_models = convert_list_to_crf_model(ingredients.ingredients)
|
||||
ingredients = convert_crf_models_to_ingredients(crf_models)
|
||||
|
||||
return {"ingredient": ingredients}
|
||||
Reference in New Issue
Block a user