Coverage for apps / ai / migrations / 0004_update_serving_adjustment_prompt.py: 55%
22 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"""Update serving_adjustment prompt to include notes about cooking time/pan size."""
3from django.db import migrations
6def update_prompt(apps, schema_editor):
7 """Update the serving_adjustment prompt to include notes."""
8 AIPrompt = apps.get_model('ai', 'AIPrompt')
10 try:
11 prompt = AIPrompt.objects.get(prompt_type='serving_adjustment')
12 prompt.system_prompt = '''You are a precise culinary calculator specializing in recipe scaling.
13Given a list of ingredients and a serving adjustment, recalculate all quantities accurately.
15Always respond with valid JSON in this exact format:
16{
17 "ingredients": ["adjusted ingredient 1", "adjusted ingredient 2", ...],
18 "notes": ["note about cooking time adjustment", "note about pan size", ...]
19}
21Rules for ingredients:
22- Maintain proper ratios between ingredients
23- Convert to sensible units when quantities become too large or small
24- Round to practical measurements (e.g., 1/4 cup, not 0.247 cups)
25- Keep original ingredient names and preparation instructions
26- Include the scaled amount AND the original amount in parentheses (e.g., "400g flour (scaled from 200g)")
28Rules for notes:
29- Add notes about cooking time adjustments if scaling significantly (50% or more change)
30- Add notes about pan/pot size if quantities change significantly
31- Add notes about any technique changes needed for larger/smaller batches
32- Keep notes brief and actionable (1 sentence each)
33- Return an empty array if no adjustments are needed
35IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.'''
37 prompt.user_prompt_template = '''Current ingredients (for {original_servings} servings):
38{ingredients}
40Target servings: {new_servings}
42Scale all ingredients and provide any necessary cooking adjustment notes.'''
44 prompt.save()
45 except AIPrompt.DoesNotExist:
46 pass
49def revert_prompt(apps, schema_editor):
50 """Revert to the original prompt."""
51 AIPrompt = apps.get_model('ai', 'AIPrompt')
53 try:
54 prompt = AIPrompt.objects.get(prompt_type='serving_adjustment')
55 prompt.system_prompt = '''You are a precise culinary calculator specializing in recipe scaling.
56Given a list of ingredients and a serving adjustment, recalculate all quantities accurately.
58Always respond with valid JSON in this exact format:
59{
60 "ingredients": ["adjusted ingredient 1", "adjusted ingredient 2", ...]
61}
63Rules:
64- Maintain proper ratios between ingredients
65- Convert to sensible units when quantities become too large or small
66- Round to practical measurements (e.g., 1/4 cup, not 0.247 cups)
67- Keep original ingredient names and preparation instructions
69IMPORTANT: Respond with ONLY the JSON, no additional text, explanation, or commentary.'''
71 prompt.user_prompt_template = '''Current ingredients (for {original_servings} servings):
72{ingredients}
74Adjust all quantities for {new_servings} servings.'''
76 prompt.save()
77 except AIPrompt.DoesNotExist:
78 pass
81class Migration(migrations.Migration):
82 dependencies = [
83 ('ai', '0003_nutrition_estimate_prompt'),
84 ]
86 operations = [
87 migrations.RunPython(update_prompt, revert_prompt),
88 ]