Coverage for opt/mealie/lib/python3.12/site-packages/mealie/schema/openai/recipe.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-25 15:48 +0000

1from textwrap import dedent 1a

2 

3from pydantic import Field 1a

4 

5from ._base import OpenAIBase 1a

6 

7 

8class OpenAIRecipeIngredient(OpenAIBase): 1a

9 title: str | None = Field( 1a

10 None, 

11 description=dedent( 

12 """ 

13 The title of the section of the recipe that the ingredient is found in. Recipes may not specify 

14 ingredient sections, in which case this should be left blank. 

15 Only the first item in the section should have this set, 

16 whereas subsuquent items should have their titles left blank (unless they start a new section). 

17 """ 

18 ), 

19 ) 

20 

21 text: str = Field( 1a

22 ..., 

23 description=dedent( 

24 """ 

25 The text of the ingredient. This should represent the entire ingredient, such as "1 cup of flour" or 

26 "2 cups of onions, chopped". If the ingredient is completely blank, skip it and do not add the ingredient, 

27 since this field is required. 

28 

29 If the ingredient has no text, but has a title, include the title on the 

30 next ingredient instead. 

31 """ 

32 ), 

33 ) 

34 

35 

36class OpenAIRecipeInstruction(OpenAIBase): 1a

37 title: str | None = Field( 1a

38 None, 

39 description=dedent( 

40 """ 

41 The title of the section of the recipe that the instruction is found in. Recipes may not specify 

42 instruction sections, in which case this should be left blank. 

43 Only the first instruction in the section should have this set, 

44 whereas subsuquent instructions should have their titles left blank (unless they start a new section). 

45 """ 

46 ), 

47 ) 

48 

49 text: str = Field( 1a

50 ..., 

51 description=dedent( 

52 """ 

53 The text of the instruction. This represents one step in the recipe, such as "Preheat the oven to 350", 

54 or "Sauté the onions for 20 minutes". Sometimes steps can be longer, such as "Bring a large pot of lightly 

55 salted water to a boil. Add ditalini pasta and cook for 8 minutes or until al dente; drain.". 

56 

57 Sometimes, but not always, recipes will include their number in front of the text, such as 

58 "1.", "2.", or "Step 1", "Step 2", or "First", "Second". In the case where they are directly numbered 

59 ("1.", "2.", "Step one", "Step 1", "Step two", "Step 2", etc.), you should not include the number in 

60 the text. However, if they use words ("First", "Second", etc.), then those should be included. 

61 

62 If the instruction is completely blank, skip it and do not add the instruction, since this field is 

63 required. If the ingredient has no text, but has a title, include the title on the next 

64 instruction instead. 

65 """ 

66 ), 

67 ) 

68 

69 

70class OpenAIRecipeNotes(OpenAIBase): 1a

71 title: str | None = Field( 1a

72 None, 

73 description=dedent( 

74 """ 

75 The title of the note. Notes may not specify a title, and just have a body of text. In this case, 

76 title should be left blank, and all content should go in the note text. If the note title is just 

77 "note" or "info", you should ignore it and leave the title blank. 

78 """ 

79 ), 

80 ) 

81 

82 text: str = Field( 1a

83 ..., 

84 description=dedent( 

85 """ 

86 The text of the note. This should represent the entire note, such as "This recipe is great for 

87 a summer picnic" or "This recipe is a family favorite". They may also include additional prep 

88 instructions such as "to make this recipe gluten free, use gluten free flour", or "you may prepare 

89 the dough the night before and refrigerate it until ready to bake". 

90 

91 If the note is completely blank, skip it and do not add the note, since this field is required. 

92 """ 

93 ), 

94 ) 

95 

96 

97class OpenAIRecipe(OpenAIBase): 1a

98 name: str = Field( 1a

99 ..., 

100 description=dedent( 

101 """ 

102 The name or title of the recipe. If you're unable to determine the name of the recipe, you should 

103 make your best guess based upon the ingredients and instructions provided. 

104 """ 

105 ), 

106 ) 

107 

108 description: str | None = Field( 1a

109 ..., 

110 description=dedent( 

111 """ 

112 A long description of the recipe. This should be a string that describes the recipe in a few words 

113 or sentences. If the recipe doesn't have a description, you should return None. 

114 """ 

115 ), 

116 ) 

117 

118 recipe_yield: str | None = Field( 1a

119 None, 

120 description=dedent( 

121 """ 

122 The yield of the recipe. For instance, if the recipe makes 12 cookies, the yield is "12 cookies". 

123 If the recipe makes 2 servings, the yield is "2 servings". Typically yield consists of a number followed 

124 by the word "serving" or "servings", but it can be any string that describes the yield. If the yield 

125 isn't specified, you should return None. 

126 """ 

127 ), 

128 ) 

129 

130 total_time: str | None = Field( 1a

131 None, 

132 description=dedent( 

133 """ 

134 The total time it takes to make the recipe. This should be a string that describes a duration of time, 

135 such as "1 hour and 30 minutes", "90 minutes", or "1.5 hours". If the recipe has multiple times, choose 

136 the longest time. If the recipe doesn't specify a total time or duration, or it specifies a prep time or 

137 perform time but not a total time, you should return None. Do not duplicate times between total time, prep 

138 time and perform time. 

139 """ 

140 ), 

141 ) 

142 

143 prep_time: str | None = Field( 1a

144 None, 

145 description=dedent( 

146 """ 

147 The time it takes to prepare the recipe. This should be a string that describes a duration of time, 

148 such as "30 minutes", "1 hour", or "1.5 hours". If the recipe has a total time, the prep time should be 

149 less than the total time. If the recipe doesn't specify a prep time, you should return None. If the recipe 

150 supplies only one time, it should be the total time. Do not duplicate times between total time, prep 

151 time and coperformok time. 

152 """ 

153 ), 

154 ) 

155 

156 perform_time: str | None = Field( 1a

157 None, 

158 description=dedent( 

159 """ 

160 The time it takes to cook the recipe. This should be a string that describes a duration of time, 

161 such as "30 minutes", "1 hour", or "1.5 hours". If the recipe has a total time, the perform time should be 

162 less than the total time. If the recipe doesn't specify a perform time, you should return None. If the 

163 recipe specifies a cook time, active time, or other time besides total or prep, you should use that 

164 time as the perform time. If the recipe supplies only one time, it should be the total time, and not the 

165 perform time. Do not duplicate times between total time, prep time and perform time. 

166 """ 

167 ), 

168 ) 

169 

170 ingredients: list[OpenAIRecipeIngredient] = Field( 1a

171 [], 

172 description=dedent( 

173 """ 

174 A list of ingredients used in the recipe. Ingredients should be inserted in the order they appear in the 

175 recipe. If the recipe has no ingredients, you should return an empty list. 

176 

177 Often times, but not always, ingredients are separated by line breaks. Use these as a guide to 

178 separate ingredients. 

179 """ 

180 ), 

181 ) 

182 

183 instructions: list[OpenAIRecipeInstruction] = Field( 1a

184 [], 

185 description=dedent( 

186 """ 

187 A list of instructions for the recipe. Each instruction should represent one step in the recipe, 

188 and should be inserted in the order they appear in the recipe. If the recipe has no instructions, 

189 you should return an empty list. 

190 

191 Often times, but not always, instructions are separated by line breaks and/or separated by paragraphs. 

192 Use these as a guide to separate instructions. They also may be separated by numbers or words, such as 

193 "1.", "2.", "Step 1", "Step 2", "First", "Second", etc. 

194 """ 

195 ), 

196 ) 

197 

198 notes: list[OpenAIRecipeNotes] = Field( 1a

199 [], 

200 description=dedent( 

201 """ 

202 A list of notes found in the recipe. Notes should be inserted in the order they appear in the recipe. 

203 They may appear anywhere on the recipe, though they are typically found under the instructions. 

204 """ 

205 ), 

206 )