Skip to content

Add detail="compact" and a food_id filter to get_food_log - #93

Merged
rwestergren merged 1 commit into
rwestergren:mainfrom
knauerhase:compact-log
Nov 23, 2026
Merged

rwestergren merged 1 commit into
rwestergren:mainfrom
knauerhase:compact-log

Conversation

@knauerhase

Copy link
Copy Markdown
Contributor

A busy diary day from get_food_log is about 170,000 characters, because every entry carries its food's whole nutrient profile. That is over the output limit of some clients, so the call fails. This adds an opt-in compact mode and a food_id filter.

What it does

  • get_food_log takes detail="compact". The default stays "full", so existing callers see no change.
  • Compact replaces each diary entry with a small object: entry_id, type, name, food_id, measure_id, grams, servings, time, order, diary_group ({group, name}, as in full mode), and kcal, protein_g, carbs_g, fat_g, sodium_mg. Values that can't be derived are null, and grams is passed through as is.
  • entry_id is the ID remove_food_entry takes for that entry, whatever its type (servingId, noteId, exerciseId or biometricId). Notes also carry their text. A compact log can therefore be used to find and remove any entry.
  • food_id narrows the diary list to one food, in either detail mode. It filters before foods are looked up, so only the kept entries are enriched.
  • energy_summary and nutrition_summary are unchanged and still describe the whole day. Both options apply to each day when days > 1.

Not changed: meal groups. Compact uses the diary_group label that label_diary_groups already adds, so it follows whatever the account layout is.

Tests: new tests/test_food_log_compact.py (full stays the default, compact fields, notes and non-food entry IDs, size reduction, food_id, invalid detail, multi-day). Ruff, ruff format --check and the full suite pass on top of current main.

🤖 Generated with Claude Code

A busy day in full detail is around 170,000 characters (every entry carries
its food's whole nutrient profile), which exceeds the output limit of some
clients and fails the call.

detail="compact" (default stays "full") replaces each diary entry with a
small object: entry_id, type, name, food_id, measure_id, grams, servings,
time, order, diary_group, and kcal/protein/carbs/fat/sodium. entry_id is the
ID remove_food_entry takes for any entry type (servingId, noteId,
exerciseId or biometricId), and notes also carry their text.
energy_summary and nutrition_summary are unchanged.

food_id narrows the entries to one food, in either detail mode. It filters
before the foods are looked up, so only the kept entries are enriched.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jorgebaptista

Copy link
Copy Markdown
Contributor

+1 from real use with ChatGPT. On a day with about eight entries, get_food_log returned about 70,000 characters in full mode and about 18,000 with detail="compact". Most of the remainder is the day's nutrient summary. I'm running it locally on top of v0.2.7.

@rwestergren
rwestergren merged commit b59e35b into rwestergren:main Nov 23, 2026
1 check passed
@knauerhase

Copy link
Copy Markdown
Contributor Author

Thanks for merging this, and so quickly.

@rwestergren

Copy link
Copy Markdown
Owner

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants