Record meals via photo or text, auto-recognize food items and calculate nutrition.
All diet records are stored in diet-log.jsonl (same directory as this skill file, one JSON object per line). Create the file if it doesn't exist.
Each record schema:
json
{
"id": "uuid",
"timestamp": "ISO-8601",
"meal_type": "breakfast|lunch|dinner|snack",
"items": [
{
"name": "食物名称",
"portion_g": 150,
"calories_kcal": 230,
"protein_g": 12,
"fat_g": 8,
"carb_g": 28,
"fiber_g": 2
}
],
"total_calories": 460,
"notes": ""
}
Stored in diet-preferences.json (same directory as this skill file). Create the file if it doesn't exist.
json
{
"photo_auto_log": null,
"dietary_restrictions": [],
"allergies": [],
"disliked_foods": [],
"favorite_foods": [],
"diet_goal": null,
"daily_calorie_target": null,
"meal_routine": null,
"notes": ""
}
Fields:
photo_auto_log: true = auto-log on photo upload, false = confirm first, null = not yet set.dietary_restrictions: e.g. ["素食", "清真", "无麸质", "低碳水"]allergies: e.g. ["花生", "海鲜", "乳糖不耐"]disliked_foods: foods user explicitly dislikesfavorite_foods: frequently eaten or preferred foodsdiet_goal: e.g. "减脂", "增肌", "维持体重", "均衡饮食"daily_calorie_target: e.g. 1800 (kcal), null if not setmeal_routine: e.g. "一日三餐", "16:8轻断食", "少食多餐"notes: any other dietary habits or notes from userPhoto auto-log preference: On the first food photo upload (or when photo_auto_log is null), recognize items as usual, then ask: "以后发食物照片时,要自动帮你记录饮食吗?还是每次先确认再记录?"
Dietary habits: Whenever user mentions dietary preferences, restrictions, allergies, goals, or habits in conversation, extract and save to the corresponding fields. Examples:
"花生" to allergiesdiet_goal to "减脂""香菜" to disliked_foodsdaily_calorie_target to 1500meal_routine to "16:8轻断食"Preferences are accumulated over time — update individual fields without overwriting unrelated ones. Read preferences before each interaction to provide personalized feedback (e.g. warn if a meal exceeds calorie target, flag allergens in recognized food).
diet-preferences.json to check photo_auto_logphoto_auto_log is null: present result, ask preference (see above), then logphoto_auto_log is true: calculate totals, log directly, respond with summaryphoto_auto_log is false: present recognized items — ask user to confirm or correct, then logdiet-log.jsonlWhen user asks "今天吃了什么" or "daily summary":
bash
python3 -c "
import json, datetime
today = datetime.date.today().isoformat()
with open('diet-log.jsonl') as f:
meals = [json.loads(l) for l in f if today in l]
total = sum(m['total_calories'] for m in meals)
print(f'Today: {len(meals)} meals, {total:.0f} kcal')
for m in meals:
items = ', '.join(i['name'] for i in m['items'])
print(f\" {m['meal_type']}: {m['total_calories']:.0f} kcal — {items}\")
"
Common foods for quick lookup (no API needed):
FoodkcalProteinFatCarb白米饭1162.60.325.9面条(煮)1103.50.522鸡胸肉133311.20鸡蛋(煮)14413101.1牛肉(瘦)125204.20.2三文鱼20820130豆腐738.13.71.5西兰花342.80.45番茄180.90.23.9苹果520.30.213.8香蕉891.10.322.8牛奶(全脂)613.23.34.8酸奶(原味)613.53.34.7全麦面包247133.441燕麦片379136.567
For unlisted foods, estimate based on similar items or ask the user for specifics.