Coverage for opt/mealie/lib/python3.12/site-packages/mealie/schema/openai/recipe_ingredient.py: 93%
14 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 17:29 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 17:29 +0000
1from textwrap import dedent 1a
2from typing import Any 1a
4from pydantic import Field, field_validator 1a
6from ._base import OpenAIBase 1a
9class OpenAIIngredient(OpenAIBase): 1a
10 quantity: float | None = Field( 1a
11 0,
12 description=dedent(
13 """
14 The numerical representation of how much of this ingredient. For instance, if you receive
15 "3 1/2 grams of minced garlic", the quantity is "3 1/2". Quantity may be represented as a whole number
16 (integer), a float or decimal, or a fraction. You should output quantity in only whole numbers or
17 floats, converting fractions into floats. Floats longer than 10 decimal places should be
18 rounded to 10 decimal places.
19 """
20 ),
21 )
22 unit: str | None = Field( 1a
23 None,
24 description=dedent(
25 """
26 The unit of measurement for this ingredient. For instance, if you receive
27 "2 lbs chicken breast", the unit is "lbs" (short for "pounds").
28 """
29 ),
30 )
31 food: str | None = Field( 1a
32 None,
33 description=dedent(
34 """
35 The actual physical ingredient used in the recipe. For instance, if you receive
36 "3 cups of onions, chopped", the food is "onions".
37 """
38 ),
39 )
40 note: str | None = Field( 1a
41 None,
42 description=dedent(
43 """
44 The rest of the text that represents more detail on how to prepare the ingredient.
45 Anything that is not one of the above should be the note. For instance, if you receive
46 "one can of butter beans, drained" the note would be "drained". If you receive
47 "3 cloves of garlic peeled and finely chopped", the note would be "peeled and finely chopped".
48 """
49 ),
50 )
52 @field_validator("quantity", mode="before") 1a
53 def coerce_none_float(cls, v: Any) -> Any: 1a
54 return v or 0
57class OpenAIIngredients(OpenAIBase): 1a
58 ingredients: list[OpenAIIngredient] = [] 1a