Coverage for apps / ai / migrations / 0003_nutrition_estimate_prompt.py: 80%
10 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"""Add nutrition_estimate prompt for remixed recipes."""
3from django.db import migrations
6def add_nutrition_prompt(apps, schema_editor):
7 """Create the nutrition_estimate prompt."""
8 AIPrompt = apps.get_model('ai', 'AIPrompt')
10 AIPrompt.objects.create(
11 prompt_type='nutrition_estimate',
12 name='Nutrition Estimate',
13 description='Estimate nutrition values for remixed recipes based on ingredient changes',
14 system_prompt='''You are a nutrition expert specializing in recipe analysis.
15Given original recipe nutrition data and ingredient changes, estimate the new nutrition values per serving.
17IMPORTANT: Respond with ONLY valid JSON, no additional text or explanation.
19Use this exact format:
20{
21 "calories": "X kcal",
22 "carbohydrateContent": "X g",
23 "proteinContent": "X g",
24 "fatContent": "X g",
25 "saturatedFatContent": "X g",
26 "unsaturatedFatContent": "X g",
27 "cholesterolContent": "X mg",
28 "sodiumContent": "X mg",
29 "fiberContent": "X g"
30}
32Guidelines:
33- Base estimates on the ingredient changes between original and modified recipe
34- Account for serving size differences when calculating per-serving values
35- Use your knowledge of common ingredient nutrition values
36- Round to reasonable precision (whole numbers for calories, 1 decimal for grams)
37- If an ingredient swap significantly changes a nutrient (e.g., vegan removes cholesterol), reflect that
38- Provide your best estimate even with incomplete information
39- Do NOT include any explanation or commentary, ONLY the JSON object''',
40 user_prompt_template='''Original Recipe Nutrition (per serving, {original_servings} servings total):
41{original_nutrition}
43Original Ingredients:
44{original_ingredients}
46Modified Recipe Ingredients ({new_servings} servings total):
47{new_ingredients}
49Modification Description: {modification}
51Estimate the nutrition values per serving for the modified recipe.''',
52 model='anthropic/claude-3.5-haiku',
53 )
56def remove_nutrition_prompt(apps, schema_editor):
57 """Remove the nutrition_estimate prompt."""
58 AIPrompt = apps.get_model('ai', 'AIPrompt')
59 AIPrompt.objects.filter(prompt_type='nutrition_estimate').delete()
62class Migration(migrations.Migration):
63 dependencies = [
64 ('ai', '0002_seed_prompts'),
65 ]
67 operations = [
68 migrations.RunPython(add_nutrition_prompt, remove_nutrition_prompt),
69 ]