Skip to content

New Feature: Food Search 2.0 for Loop! #2329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from

Conversation

taylorpatterson-T1D
Copy link

@taylorpatterson-T1D taylorpatterson-T1D commented Jul 20, 2025

Introducing a new AI-enabled food search capability for Loop. Loop has helped me become a better diabetic and I would love to give back to the community by contributing this new feature for Loop, which I believe will benefit all Loop users.

PROBLEM WE'RE SOLVING: Diabetics often lack nutrition knowledge when estimating carb intake. And we need that knowledge when we’re making dosing decisions, especially when eating out at restaurants - this knowledge is the single most important tool we have to improve our Time in Range and A1C. Loop's Food Search feature uses barcodes and AI analysis to provide accurate nutrition information and advanced diabetes management recommendations.

NEW FEATURE'S IMPACT: The Food Search system is a comprehensive food analysis and nutrition tracing solution integrated into Loop for improved diabetes management. It provides multiple search options including text, barcode scanning, and AI-powered image analysis that produces comprehensive nutrition data and dosing suggestions via diabetic notes. With Food Search, we can enter a meal bolus with MUCH greater accuracy which should improve Time in Range and A1C. The AI-analysis engine can even read menus (in multiple languages) and provide guidance for dosing.

Short video demo: https://youtu.be/t7JxvkGcMfU

Review the docs in “/Loop/Documentation/FoodSearch 2.0 Docs/” for comprehensive documentation for Loop's Food Search functionality, including AI-powered nutrition analysis and advanced diabetes management recommendations. API setup guides are provided so the user can enter their personal AI API keys to enable AI food analysis.

This new PR (Food-Search 2.0) fixes compatibility bugs from the initial commit and adds Advanced AI Analysis including FPU analysis, and Dynamic Dosing recommendations.

Requesting a review from the maintainers? @ps2, @marionbarker, @loudnate

Feature is hidden behind a Feature Flag in Loop > Settings > Enable Food Search:
Screenshot 2025-07-20 at 4 02 05 PM

New Search for Food section on the Add Carb Entry view:
Screenshot 2025-07-20 at 4 02 18 PM

Simple text search:
Screenshot 2025-07-20 at 4 02 30 PM

Barcode scan search for high accuracy of packaged foods:
Screenshot 2025-07-20 at 4 02 40 PM

AI-enabled food image analysis engine in action:
Screenshot 2025-07-20 at 4 02 52 PM

AI-Analysis results with comprehensive analysis details including an item by item breakdown of the meal:
Screenshot 2025-07-20 at 4 03 05 PM

Even more detail about how Portions & Servings were calculated and Diabetic Notes to advise during dosing:
Screenshot 2025-07-20 at 4 03 22 PM

Advanced AI Analysis Mode for those who want to geek out on FPU and Advanced Dosing Recommendations:
Screenshot 2025-07-20 at 4 03 35 PM

Food Search Setup screen. Pick the AI service you prefer, enter your own API keys:
Screenshot 2025-07-20 at 4 03 46 PM

A new AI-enabled food search capability for Loop. Loop has helped me become a better diabetic and I would love to give back to the community by contributing this new feature for Loop, which I believe will benefit all Loop users.

PROBLEM WE'RE SOLVING: Diabetics often lack nutrition knowledge when estimating carb intake. And we need that knowledge when we’re making dosing decisions - this knowledge is the single most important tool we have to improve our Time in Range and A1C. Loop's Food Search feature uses barcodes and AI analysis to provide accurate nutrition information and advanced diabetes management recommendations.

NEW FEATURE'S IMPACT: The Food Search system is a comprehensive food analysis and nutrition tracking solution integrated into Loop for improved diabetes management. It provides multiple search options including text, barcode scanning, voice, and AI-powered image analysis that produces comprehensive nutrition data and dosing suggestions via diabetic notes. This let's us enter a meal bolus with MUCH greater accuracy to improve Time in Range and A1C. The AI-enabled analysis engine can even read menus (in multiple languages) and provide guidance for dosing.

Short video demo: https://youtu.be/L0LD8AxNX0Q

Review the docs in “/Loop/Documentation/FoodSearch 2.0 Docs/” for comprehensive documentation for Loop's Food Search functionality, including AI-powered nutrition analysis and advanced diabetes management recommendations. API setup guides are provided so the user can enter their personal AI API keys to enable AI food analysis.

This new PR (Food-Search 2.0) fixes compatibility bugs from the initial commit and adds Advanced AI Analysis including FPU analysis, and Dynamic Dosing recommendations.

Requesting a review from the maintainers? @ps2, @marionbarker, @loudnate

<I will post new screenshots here after submitting this PR>
To prevent breaking Live Activities customizations
Added xcodeproj/project.pbxproj to .gitignore
fixed build errors caused by AbsorptionTimePickerRow function
- Red X delete buttons in Food Details so users can adjust what food items they plan to eat and not eat
- Automatic nutriments total & absorption time recalculations when items are deleted
included accidentally so I'm removing it. should remain unchanged.
This change moves a change from /LoopKitUI senior directory down into the /LoopWorkSpace/Loop directory to keep everything under /Loop.
  - Easy discovery: Users see the brain icon toggle when Food Search is disabled
  - Instant enablement: Toggle works immediately to show full Food Search UI
  - Consistent disabling: Settings changes (via gear icon) instantly update the UI
  - Responsive both ways: Works whether toggled from carb entry or settings
Split AI food analysis prompt into Standard and Advanced mode to increase performance when in Standard Mode.
  - Standard Mode: ~2,500 words (basic analysis only)
  - Advanced Mode: ~6,000+ words (includes FPU calculations, deeper food absorption details, exercise guidance, etc.)
  - Token Reduction: ~60% fewer tokens for Standard mode users

  What this means for users:
  - Standard mode users get faster AI analysis with streamlined prompts
  - Advanced mode users get comprehensive analysis when they need FPU calculations
  - The system automatically chooses the right prompt based on the Advanced Dosing setting
…om AI analysis

Multi-Circle Nutriment Bug - Both food deletion and serving adjustments now work accurately and predictably.
1. Better Analysis Quality - GPT-5 provides improved accuracy for complex health related food analysis
2. Future-Proofed - Ready for GPT-5 when users have access
3. Cost-Effective Options - Users can choose between quality (GPT-5) and speed (GPT-4o-mini)
Preferred food search providers for best performance are set to:
Text/Voice Search: USDA FoodData Central
Barcode Search: OpenFoodFacts
AI Image Analysis: OpenAI (ChatGPT API)
@marionbarker
Copy link
Contributor

marionbarker commented Aug 11, 2025

Code Review

I made some modifications to Taylor's code, starting at 477ca57, as documented in this branch:

See https://github.com/loopandlearn/Loop/commits/modify_for_pr2329

  • 542a304 revert unintended changes to .gitignore file
  • 2cce0ef restore xcworkspace and xcshareddata files, this change not related to this PR
  • 68a738d Restore auto-signing capability, remove unneeded Libre references
  • c5d4eae Restore Main.storyboard from dev

Additional changes will be required, but the functionality can be tested.

  • The additions (new files) use print statements instead of the log.default or log.debug
  • I think the strings may require modifications before they can be localized, but I'll look into this.

More changes are found in a different branch that is focused on the minimum changes to support adding this as a customization: https://github.com/loopandlearn/Loop/commits/prepare_for_customization_pr2329

  • Because automated tests for Loop are broken with the files added to LoopTests
    • I removed the LoopTests added in the PR (82dc481c)
    • I removed those file references in pbjproj file and commented out 2 test functions from LoopTests/ViewModels/BolusEntryViewModelTests.swift (ac3f87d6)
      • testCarbEntryDateAndAbsorptionTimeString
      • testCarbEntryDateAndAbsorptionTimeString2
    • With those changes, Tests can now be run

Test

Test with commit 542a304.

This builds and appears to work. More testing will be needed.

@marionbarker
Copy link
Contributor

Update with new commits

When Taylor updates his branch, then I need to also update my two branches:

In a local copy of Taylor's branch:

git pull
git switch modify_for_pr2329
git merge <local-name-for-taylor's-branch>
git switch prepare_for_customization_pr2329
git merge modify_for_pr2329

This keeps the 3 version in alignment.

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.

2 participants