-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feature: AI-Enabled Food Search #2325
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
base: dev
Are you sure you want to change the base?
Conversation
Could I please get a review from the maintainers? @ps2, @marionbarker, @loudnate This is my submission for 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 lack consistent nutrition knowledge when estimating carb intake. And we need that knowledge right in the moment, when we’re making dosing decisions - this knowledge is the single most important tool we have to improve our Time in Range and A1C. 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 and improve Time in Range and A1C. The AI-enabled analysis engine can even read menu items from an image captured, and provide guidance in multiple languages!!! Video Demo: https://youtu.be/L0LD8AxNX0Q Review the docs in “//LoopWorkspace/Loop/Documentation/FoodSearch Docs” for details. API setup guides are provided so the user can enter their your own AI API keys for AI image analysis. New Search for Food section on the Add Carb Entry view: Barcode scan search for high accuracy: 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 and Servings were calculated and diabetic specific notes to advise during dosing: New Setup screen. Pick the AI service you prefer, enter your own API keys: |
☐ Added network quality detection ☐ Implement safer timeout handling ☐ Add fast mode fallback logic 1. On Good WiFi: Fast parallel processing (unchanged performance) 2. On Restaurant WiFi: Sequential processing prevents freezing 3. On Cellular: Conservative mode with longer timeouts 4. On Poor Networks: Automatic fallback to safer processing
Improved AI prompt to include glycemic index analysis and strengthen diabetic notes section. Removed excessive DEBUG logging for better overall performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first of several comments. It includes 2 specific lines that need to be removed from Loop.xcodeproj/project.pbxproj
. The 2 lines contain Taylor's Developer ID. They break the automatic signing configuration for Loop and are not required - they can be deleted.
In addition to those 2 lines in Loop.xcodeproj/project.pbxproj
, I do not know why the LibreTransmitter information was touched. I think that is a mistake. (It might not harm anything, but we prefer not to make changes unless they are necessary.)
More general comments: This was pretty slick. The bar code reader was the one I played with the most. The general food search seemed to spend a long time loading, but maybe my network was having an issue. I will do more testing and report back. Regarding this addition, I'm not sure of the best way to incorporate it. I'm sure it is user specific whether they want this level of detail or if they go with a few Favorite Food listings and use a SWAG for the carbs to enter (which is my approach). We might want to move the position of the food search/service lower on the screen into its own FOOD SEARCH area (like FAVORITE FOODS). You might want to upload the images in your comment as png files - they are distorted and hard to read on my phone and distorted and impossible to read on my computer browser. The following graphic was made as a composite from my test phone (an SE 2nd gen) - the display is taller than will fit on the phone with the keyboard deployed. |
@marionbarker - Thank you for your kind help and suggestion. I have repaired the Taylor-specific issues and reverted the version uptick. If we make this functionality a new Customization option from the main Loop build script then the user is saying that they want to prioritize the value delivered by making food search results their new priority (versus anything they may have used in the past). So keeping the functionality at the top of the Add Carb Entry view seems appropriate. If they don't like the functionality then it can be removed returning Add Carb Entry to its default. If they make the choice to add Food Search, then my POV is that it should remain at the top of the Add Carb Entry section and not be moved below (near Favorite Foods) where it may go overlooked and therefore unused. Your thoughts? |
Also reverted object version to 54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did another review and there are still some changes that need to be removed.
Please note: this only builds with Mac-Xcode. I am unable to build with GitHub Actions (at this time). I tested both the version in PR 2325, commit feb6f26, and the version with the items removed as described below.
For GitHub errors, please see: https://github.com/docs-test/LoopWorkspace/actions/runs/16239378975
Modification Summary
I removed these items and tested that Loop with food search still builds correctly with Mac (macOS 15.5) and Xcode (16.3):
- I removed all references to LibreTransmitter from
Loop.xcodeproj/project.pbxproj
- I removed
Loop.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
- I removed the entire folder
Loop/Loop.xcodeproj
(the Loop.xcodeproj folder should only be at the top level, this was duplicated at a lower level)
I pushed my version to the loopandlearn github account so I could link some of the changes in the details below and to support testing the build with GitHub actions.
Modification Details
Before making these changes
- Be sure to clean build folder and close the workspace in Xcode
- Only open Xcode workspace again after changes are made
Item 1:
see this commit: loopandlearn@f2874d2
Item 2:
command line to take this action:
% git rm Loop.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
rm 'Loop.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved'
see this commit: loopandlearn@aa67ab8
Item 3:
command line to take this action:
% git rm -r Loop/Loop.xcodeproj
rm 'Loop/Loop.xcodeproj/project.pbxproj'
rm 'Loop/Loop.xcodeproj/project.xcworkspace/contents.xcworkspacedata'
rm 'Loop/Loop.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist'
rm 'Loop/Loop.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings'
rm 'Loop/Loop.xcodeproj/xcshareddata/xcschemes/DoseMathTests.xcscheme'
rm 'Loop/Loop.xcodeproj/xcshareddata/xcschemes/Loop Intent Extension.xcscheme'
rm 'Loop/Loop.xcodeproj/xcshareddata/xcschemes/Loop Status Extension.xcscheme'
rm 'Loop/Loop.xcodeproj/xcshareddata/xcschemes/Loop.xcscheme'
rm 'Loop/Loop.xcodeproj/xcshareddata/xcschemes/LoopTests.xcscheme'
rm 'Loop/Loop.xcodeproj/xcshareddata/xcschemes/SmallStatusWidgetExtension.xcscheme'
rm 'Loop/Loop.xcodeproj/xcshareddata/xcschemes/WatchApp.xcscheme'
see this commit: loopandlearn@b40a220
Regarding not being able to build with GitHub actions. The modification in this link fixed the error. Required change:
Other change:
Error reported using Xcode: Product->Archive was:
|
@marionbarker On the subject of the project files stuff, I was unable to build by following your directions of removing those sub contents. It wouldn't see the Loop project as valid without them, unless I'm doing something wrong. |
Move the Food Search behind a feature flag found in Settings Improved AI prompt to prevent overdose recommendations Streamlined Diabetic Notes, Portion Details and other UX improvements
Food Search Feature Flag Implementation Done!
I also improved the AI prompt and context to add Glycemic Index inputs, and refined how the food is presented in the UI to make it easier to read. @marionbarker , @ps2 ![]() ![]() ![]() |
General comments about this commit: 2adc9a3: I have not finished my detailed review and testing yet, but wanted to get this general comment out. I already mentioned the changes to You did not implement some of my earlier suggestions because you "were unable to build" - we can talk about those on zulipchat via DM if you prefer. The other general comment is that it is better to do atomic commits that change one thing at a time. Please consider this for future commits - I'm not asking you to change this one. I see 3 "changes" in this one commit:
|
SummaryThe modifications I previously requested are still required before this can be considered.
Once you make the required modifications, I will test again and then we can see if @ps2 will approve it. Be sure the modifications are made with Xcode closed. Then when you open Xcode again, do a clean build folder, close the workspace and then open it again. If you do not take those steps, you will get build failures. ModificationsI started with a fresh branch ( You can see the commits I applied to your version: The successful Browser Build is: Modification DetailsOne of the things you did not add was the extra parameters required to enable Browser Build (or Product -> Archive) in The missing arguments I did manually (instead of cherry-pick) because of the case you chose for imageURL. It turns out that imageFrontUrl must be spelled with Url in title case, so it took me 2 tries to get that modification correct. Details about case Initially, you had some instances of
|
|
…Settings.xcsettings
@marionbarker |
I chose imageURL as the standard for consistency because URL is an acronym and therefore more likely to be more future proof if others contribute to the feature. This was tested as working on my end so it should now be resolved with my last commit. |
Please do not be discouraged. But please read carefully. commit you need to revertYou labeled this commit as "Delete redundant Loop.xcodeproj directory" But in fact you deleted the one directory that was correct, i.e., you deleted the I tried fixing just that commit with this command:
And in my clone it now builds fine. atomic commitsWhen I said use atomic commits - I meant all changes in a single commit should solve a problem. It might be a lot of files. Doing this is not required but it is a good idea because then reviewers can look at the changes made per commit. It makes it easier to review. test build before pushPlease do not push any commits until you have a working build. Then push them to GitHub at one time. When you pushed following every commit of deleting single files (all for one purpose) yesterday, that sent a separate email to every one who watches the Loop repository. You deleted (one file at a time) items found in the missing argumentsYou have not fixed the missing arguments that will prevent this from working for a browser build. Test this yourself by taking these actions in Xcode:
The build will fail. Click on the Report Navigator icon Showing Recent Messages |
Initial commit