feat: Add brute strategy to ingredient processor (#744)

* fix UI column width

* words

* update parser to support diff strats

* add new model url

* make button more visible

* fix nutrition error

* feat(backend):  add 'brute' strategy for parsing ingredients

* satisfy linter

* update UI for creation page

* feat(backend):  log 422 errors in detail when not in PRODUCTION

* add strategy selector

Co-authored-by: Hayden <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-10-16 16:06:13 -08:00
committed by GitHub
parent 60908e5a88
commit 3b920babe3
25 changed files with 961 additions and 131 deletions

View File

@@ -1,3 +1,4 @@
import enum
from typing import Optional, Union
from fastapi_camelcase import CamelModel
@@ -30,10 +31,40 @@ class IngredientUnit(CreateIngredientUnit):
class RecipeIngredient(CamelModel):
title: Optional[str]
note: Optional[str]
unit: Optional[Union[CreateIngredientUnit, IngredientUnit]]
food: Optional[Union[CreateIngredientFood, IngredientFood]]
unit: Optional[Union[IngredientUnit, CreateIngredientUnit]]
food: Optional[Union[IngredientFood, CreateIngredientFood]]
disable_amount: bool = True
quantity: float = 1
class Config:
orm_mode = True
class IngredientConfidence(CamelModel):
average: float = None
comment: float = None
name: float = None
unit: float = None
quantity: float = None
food: float = None
class ParsedIngredient(CamelModel):
input: Optional[str]
confidence: IngredientConfidence = IngredientConfidence()
ingredient: RecipeIngredient
class RegisteredParser(str, enum.Enum):
nlp = "nlp"
brute = "brute"
class IngredientsRequest(CamelModel):
parser: RegisteredParser = RegisteredParser.nlp
ingredients: list[str]
class IngredientRequest(CamelModel):
parser: RegisteredParser = RegisteredParser.nlp
ingredient: str