Coverage for apps / ai / migrations / 0002_seed_prompts.py: 83%
12 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 00:40 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 00:40 +0000
1"""Seed the 10 default AI prompts."""
3from django.db import migrations
6def seed_prompts(apps, schema_editor):
7 """Create the default AI prompts."""
8 AIPrompt = apps.get_model('ai', 'AIPrompt')
10 prompts = [
11 {
12 'prompt_type': 'recipe_remix',
13 'name': 'Recipe Remix',
14 'description': 'Create variations of existing recipes based on user modifications',
15 'system_prompt': '''You are a creative chef specializing in recipe modifications.
16Given an original recipe and a requested modification, create a new recipe that incorporates the change while maintaining culinary coherence.
18Always respond with valid JSON in this exact format:
19{
20 "title": "New recipe title",
21 "description": "Brief description of the modified recipe",
22 "ingredients": ["ingredient 1", "ingredient 2", ...],
23 "instructions": ["step 1", "step 2", ...],
24 "prep_time": "X minutes",
25 "cook_time": "X minutes",
26 "total_time": "X minutes",
27 "yields": "X servings"
28}
30Maintain the spirit of the original recipe while implementing the requested changes.
31Adjust cooking times and techniques as needed for the modifications.
32Ensure all measurements are precise and instructions are clear.
34IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
35 'user_prompt_template': '''Original Recipe:
36Title: {title}
37Description: {description}
38Ingredients:
39{ingredients}
41Instructions:
42{instructions}
44Requested Modification: {modification}
46Create a modified version of this recipe incorporating the requested change.''',
47 'model': 'anthropic/claude-3.5-haiku',
48 },
49 {
50 'prompt_type': 'serving_adjustment',
51 'name': 'Serving Adjustment',
52 'description': 'Adjust ingredient quantities for different serving sizes',
53 'system_prompt': '''You are a precise culinary calculator specializing in recipe scaling.
54Given a list of ingredients and a serving adjustment, recalculate all quantities accurately.
56Always respond with valid JSON in this exact format:
57{
58 "ingredients": ["adjusted ingredient 1", "adjusted ingredient 2", ...]
59}
61Rules:
62- Maintain proper ratios between ingredients
63- Convert to sensible units when quantities become too large or small
64- Round to practical measurements (e.g., 1/4 cup, not 0.247 cups)
65- Keep original ingredient names and preparation instructions
67IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
68 'user_prompt_template': '''Current ingredients (for {original_servings} servings):
69{ingredients}
71Adjust all quantities for {new_servings} servings.''',
72 'model': 'anthropic/claude-3.5-haiku',
73 },
74 {
75 'prompt_type': 'tips_generation',
76 'name': 'Tips Generation',
77 'description': 'Generate helpful cooking tips for recipes',
78 'system_prompt': '''You are an experienced chef providing practical cooking tips.
79Given a recipe, provide 3-5 helpful tips that would improve the cooking experience or result.
81Always respond with valid JSON as an array of tip strings:
82["tip 1", "tip 2", "tip 3"]
84Tips should be:
85- Practical and actionable
86- Specific to the recipe or technique
87- Helpful for home cooks of varying skill levels
88- Brief but informative (1-2 sentences each)
90IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
91 'user_prompt_template': '''Recipe:
92Title: {title}
93Ingredients:
94{ingredients}
96Instructions:
97{instructions}
99Provide 3-5 helpful cooking tips for this recipe.''',
100 'model': 'anthropic/claude-3.5-haiku',
101 },
102 {
103 'prompt_type': 'discover_favorites',
104 'name': 'Discover from Favorites',
105 'description': 'Suggest recipes based on user favorites',
106 'system_prompt': '''You are a culinary recommendation engine.
107Based on a user's favorite recipes, suggest a new recipe they might enjoy.
109Always respond with valid JSON in this exact format:
110{
111 "search_query": "specific search query to find similar recipes",
112 "title": "Suggested Recipe Category",
113 "description": "Brief explanation of why this suggestion fits their taste"
114}
116The search_query should be a specific dish name or cuisine type that matches their preferences.
117Keep descriptions concise (1-2 sentences).
119IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
120 'user_prompt_template': '''User's favorite recipes:
121{favorites}
123Based on these favorites, suggest a new recipe they might enjoy.''',
124 'model': 'anthropic/claude-3.5-haiku',
125 },
126 {
127 'prompt_type': 'discover_seasonal',
128 'name': 'Discover Seasonal/Holiday',
129 'description': 'Suggest seasonal or holiday-appropriate recipes',
130 'system_prompt': '''You are a culinary calendar expert.
131Based on the current date and season, suggest an appropriate recipe.
133Always respond with valid JSON in this exact format:
134{
135 "search_query": "specific seasonal dish or recipe name",
136 "title": "Seasonal Suggestion Title",
137 "description": "Brief explanation of why this is perfect for the season"
138}
140Consider:
141- Current season and weather
142- Upcoming holidays within the next 2 weeks
143- Seasonal ingredient availability
144- Traditional dishes for the time of year
146IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
147 'user_prompt_template': '''Current date: {date}
148Current season: {season}
150Suggest a seasonal or holiday-appropriate recipe.''',
151 'model': 'anthropic/claude-3.5-haiku',
152 },
153 {
154 'prompt_type': 'discover_new',
155 'name': 'Discover Try Something New',
156 'description': 'Suggest adventurous recipes outside user comfort zone',
157 'system_prompt': '''You are a culinary adventure guide.
158Based on a user's cooking history, suggest something new and different they haven't tried.
160Always respond with valid JSON in this exact format:
161{
162 "search_query": "specific dish from a different cuisine or technique",
163 "title": "Adventure Suggestion Title",
164 "description": "Brief explanation of why this would be a fun culinary adventure"
165}
167Suggest dishes that:
168- Are from cuisines they haven't explored
169- Use techniques they might not have tried
170- Introduce new flavors while remaining accessible
171- Are achievable for a home cook
173IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
174 'user_prompt_template': '''User's recent recipes (cuisines and types):
175{history}
177Suggest something new and different for them to try.''',
178 'model': 'anthropic/claude-3.5-haiku',
179 },
180 {
181 'prompt_type': 'search_ranking',
182 'name': 'Search Result Ranking',
183 'description': 'Rank search results by relevance and quality',
184 'system_prompt': '''You are a recipe quality evaluator.
185Given a list of recipe search results, rank them by relevance and quality.
187Always respond with valid JSON as an array of indices (0-based) in ranked order:
188[2, 0, 4, 1, 3]
190Consider:
191- Relevance to the search query
192- Recipe completeness (has image, ratings, reviews)
193- Source reliability
194- Clarity of title and description
196IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
197 'user_prompt_template': '''Search query: {query}
199Search results:
200{results}
202Return the indices ranked from best to worst match.''',
203 'model': 'anthropic/claude-3.5-haiku',
204 },
205 {
206 'prompt_type': 'timer_naming',
207 'name': 'Timer Naming',
208 'description': 'Generate descriptive names for cooking timers',
209 'system_prompt': '''You are a helpful kitchen assistant.
210Given a cooking instruction with a time reference, create a short, descriptive timer label.
212Always respond with valid JSON in this exact format:
213{
214 "label": "Short timer name (2-4 words)"
215}
217The label should be:
218- Concise (2-4 words maximum)
219- Descriptive of what's being timed
220- Action-oriented (e.g., "Simmer sauce", "Rest meat")
222IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
223 'user_prompt_template': '''Instruction: {instruction}
224Duration: {duration}
226Create a short, descriptive label for this timer.''',
227 'model': 'anthropic/claude-3.5-haiku',
228 },
229 {
230 'prompt_type': 'remix_suggestions',
231 'name': 'Remix Suggestions',
232 'description': 'Generate contextual remix suggestions for recipes',
233 'system_prompt': '''You are a creative culinary advisor.
234Given a recipe, suggest 6 interesting modifications the user could make.
236Always respond with valid JSON as an array of exactly 6 suggestion strings:
237["suggestion 1", "suggestion 2", "suggestion 3", "suggestion 4", "suggestion 5", "suggestion 6"]
239Suggestions should be:
240- Varied (dietary, flavor, technique, ingredient swaps)
241- Practical and achievable
242- Interesting but not too extreme
243- Short phrases (3-6 words each)
245Examples: "Make it vegan", "Add more protein", "Use seasonal vegetables", "Make it spicy"
247IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
248 'user_prompt_template': '''Recipe:
249Title: {title}
250Cuisine: {cuisine}
251Category: {category}
252Ingredients:
253{ingredients}
255Suggest 6 interesting modifications for this recipe.''',
256 'model': 'anthropic/claude-3.5-haiku',
257 },
258 {
259 'prompt_type': 'selector_repair',
260 'name': 'CSS Selector Repair',
261 'description': 'Suggest fixes for broken CSS selectors on recipe sites',
262 'system_prompt': '''You are a web scraping expert specializing in recipe websites.
263Given a broken CSS selector and HTML sample, suggest fixed selectors.
265Always respond with valid JSON in this exact format:
266{
267 "suggestions": ["selector 1", "selector 2", "selector 3"],
268 "confidence": 0.85
269}
271The confidence should be a number between 0 and 1 indicating how confident you are in the suggestions.
273Consider:
274- Common recipe site HTML patterns
275- Schema.org recipe markup
276- Class and ID patterns
277- Fallback selectors that are more robust
279IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.''',
280 'user_prompt_template': '''Original selector: {selector}
281Target element: {target}
282Sample HTML:
283{html_sample}
285Suggest fixed CSS selectors for extracting the {target}.''',
286 'model': 'anthropic/claude-3.5-haiku',
287 },
288 ]
290 for prompt_data in prompts:
291 AIPrompt.objects.create(**prompt_data)
294def remove_prompts(apps, schema_editor):
295 """Remove all seeded prompts."""
296 AIPrompt = apps.get_model('ai', 'AIPrompt')
297 AIPrompt.objects.all().delete()
300class Migration(migrations.Migration):
301 dependencies = [
302 ('ai', '0001_initial'),
303 ]
305 operations = [
306 migrations.RunPython(seed_prompts, remove_prompts),
307 ]