New Feature: Food Search 2.0 for Loop!
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:
New Search for Food section on the Add Carb Entry view:
Simple text search:
Barcode scan search for high accuracy of packaged foods:
AI-enabled food image analysis engine in action:
AI-Analysis results with comprehensive analysis details including an item by item breakdown of the meal:
Even more detail about how Portions & Servings were calculated and Diabetic Notes to advise during dosing:
Advanced AI Analysis Mode for those who want to geek out on FPU and Advanced Dosing Recommendations:
Food Search Setup screen. Pick the AI service you prefer, enter your own API keys:
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
- 542a304e revert unintended changes to .gitignore file
- 2cce0efc restore xcworkspace and xcshareddata files, this change not related to this PR
- 68a738db Restore auto-signing capability, remove unneeded Libre references
- c5d4eaed 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 542a304e.
This builds and appears to work. More testing will be needed.
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.
On 2025-08-27, push changes to update the ancillary branches in loopandlearn that support the ability to add this feature as a customization to Loop. These updates bring the feature up to the level of 2c6a78e2 in this PR.
- this branch of Loop in loopandlearn GitHub username can be built with LoopWorkspace
modify_for_pr2329updated to579d6cad
- this branch of Loop in loopandlearn GitHub username is limited to only changes needed to support this feature
prepare_for_customization_pr2329updated tod79db88e
I will be taking the last 2 commits one at a time.
As started earlier, I keep a parallel branch to handle building a customization from this PR.
- parallel branch is: https://github.com/loopandlearn/Loop/tree/modify_for_pr2329
- my local clone name for the branch in this PR is
taylor-try2-dev
First: it looks like your commit 5aeda3b, Bugfixes - Favorite Foods and math fix for Carb Entry, inadvertently removed updates from two prior commits.
Please look at these commits:
bfd1c9d8Fix width bug and rearrange Add Carb Entry view- https://github.com/taylorpatterson-T1D/Loop.Food-Search/commit/bfd1c9d8
97bb8d07Set search provider defaults to best ones at onboarding- https://github.com/taylorpatterson-T1D/Loop.Food-Search/commit/97bb8d07
I believe both of those changes were desired and they are included in the Customization patch at the current time.
I was able to restore them using cherry-pick in my parallel branch, modify_for_pr2329.
git cherry-pick bfd1c9d8
git cherry-pick 97bb8d07
The code built at this point (with just the first commit from your branch merged in).
But when I pulled in the next commit and merged it then the code no longer built.
The next commit, 5cbb5d3c, Multiple feature UI improvements, is not buildable when merged into my parallel branch, until I make one modification.
If I remove the thumbnail in this line: https://github.com/taylorpatterson-T1D/Loop.Food-Search/blob/5cbb5d3c/Loop/Views/FavoriteFoodsView.swift#L41, I am then able to build the code again.
The error is:
/Users/marion/Downloads/ManualClones/Loop_dev_updates/LoopWorkspace/Loop/Loop/Views/FavoriteFoodsView.swift:21:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
This is with Xcode 16.4 building on macOS 15.6.1 building onto an iOS 18.6.2 phone.
Before I started today, my parallel branch was at
- commit
579d6cad, Merge branch 'taylor-try2-dev' into modify_for_pr2329, link
After doing the merges from the PR branch, the cherry-pick to restore desired changes and removing the one parameter that prevented me from building, the branch is at:
- commit
f7ec949f, modify to enable building, link
This is buildable by people who use automatic signing (and do not have Taylor's apple developer ID).
I tried to build it. I got the error message: No such module loopkit
Gesendet: Freitag, 29. August 2025 um 23:24 Von: "Marion Barker" @.> An: LoopKit/Loop @.> CC: Subscribed @.***> Betreff: Re: [LoopKit/Loop] New Feature: Food Search 2.0 for Loop! (PR #2329)
marionbarker left a comment (LoopKit/Loop#2329) I will be taking the last 2 commits one at a time. As started earlier, I keep a parallel branch to handle building a customization from this PR.
parallel branch is: https://github.com/loopandlearn/Loop/tree/modify_for_pr2329 my local clone name for the branch in this PR is taylor-try2-dev
First: it looks like your commit 5aeda3b, Bugfixes - Favorite Foods and math fix for Carb Entry, inadvertently removed updates from two prior commits. Please look at these commits:
bfd1c9d8 Fix width bug and rearrange Add Carb Entry view
@.***
97bb8d07 Set search provider defaults to best ones at onboarding
@.***
I believe both of those changes were desired and they are included in the Customization patch at the current time. I was able to restore them using cherry-pick in my parallel branch, modify_for_pr2329. git cherry-pick bfd1c9d8 git cherry-pick 97bb8d07
The code built at this point (with just the first commit from your branch merged in). But when I pulled in the next commit and merged it then the code no longer built. The next commit, 5cbb5d3c, Multiple feature UI improvements, is not buildable when merged into my parallel branch, until I make one modification. If I remove the thumbnail in this line: https://github.com/taylorpatterson-T1D/Loop.Food-Search/blob/5cbb5d3c/Loop/Views/FavoriteFoodsView.swift#L41, I am then able to build the code again. The error is:
/Users/marion/Downloads/ManualClones/Loop_dev_updates/LoopWorkspace/Loop/Loop/Views/FavoriteFoodsView.swift:21:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
This is with Xcode 16.4 building on macOS 15.6.1 building onto an iOS 18.6.2 phone. Before I started today, this branch was at
commit 579d6cad, Merge branch 'taylor-try2-dev' into modify_for_pr2329, link
After doing the merges from the PR branch, the cherry-pick to restore desired changes and removing the one parameter that prevented me from building, the branch is at:
commit f7ec949f, modify to enable building, link
This is buildable by people who do not have Taylor's apple developer ID. —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>
@holger2de
please use these instructions to add this as a customization to Loop. This PR is not suitable to be added to Loop as is.
https://github.com/loopandlearn/lnl-scripts/pull/82#issuecomment-3070502141
Hi everyone, I'm trying to get this feature up and running so I can help out as an eager person with T1D ! 😄 I am currently building with the Browser instructions, which has been working, but using this patch or even the branch introduces many compilation errors for me. They range from variables being used that are not defined anywhere, to Swift 6 compiler issues. Has anyone else experience these issues using the Browser instructions ?
This PR will not build. There are modifications required to this and to LoopKit. There is a preliminary customization (for now).
https://www.loopandlearn.org/loop-features-in-development/#food-search
Hello, for about 3 weeks it has not worked with Gemini. I can only get it to work with Chatgpt. The error message is "Connection Interrupteur" Analyse failed
. Can you help me? Thank you
Google deprecated the Gemini 1.5 LLM and this customization feature was hard coded to use that version. So, until @taylorpatterson-T1D can refactor his code to make it more customizable on which LLM is used for each LLM provider this will remain broken.
@tanabay2705 I built using this customization last week and you can use the byo configuration for Gemini free. Here's the url: https://generativelanguage.googleapis.com/v1beta/openai/ Then put in your api key and a current version of the api
gemini-2.5-flash or gemini-2.5-pro
I hope this helps. I had the same issue.
EDIT: And, I just confirmed that this does indeed work,
EDIT: Okay, I see now, Gemini has a openai API compatible interface.
@tanabay2705 What your stating makes no sense. Gemini and OpenAI are two entirely different LLMs made by different companies. Why would you place openai in a google Gemini URL?