Skip to content

Conversation

@awangwang
Copy link
Collaborator

@awangwang awangwang commented Nov 5, 2025

Proof-of-concept: on-device LLM generated nudges

♻️ Current situation & Problem

MHC is in need of an implementation of on-device execution of LLMs in order to generate personalized motivational notifications for users.

⚙️ Release Notes

  • Added LLMRunner and OnDeviceNudgeService to MyHeartCountsDelegate.swift.
  • An LLM download step is now in the onboarding flow. It can be toggled on/off using the downloadLLM feature flag in FeatureFlags.swift.
  • OnDeviceNudgeService.swift handles operations to retrieve user account data and then build up an LLM prompt customized using the user data. The prompt asks the LLM to create 7 motivational messages (nudges) intended to be sent to the user as a daily notification. It also allows for the retrieval of predefined nudges from PredefinedNudes.json based on the study design schedule and in cases where LLM generation fails.
    • OnDeviceNudgeService.swift mirrors the capabilities currently handled server-side by planNudges.ts
    • UserDataService.swift handles miscellaneous user data operations for OnDeviceNudgeService.swift.

📚 Documentation

For usage of OnDeviceNudgeService(), see LLMNudgesDemoView.swift.

✅ Testing

  • Swift tests of OnDeviceNudgeService.swift are in OnDeviceNudgeServiceTests.swift.
  • A demo view of straightforward on-device LLM execution is in LLMLocalDemoView.swift.
  • A demo view of on-device LLM generation of user nudges, with a prompt built from user account data is in LLMNudgesDemoView.swift.
    • These demo views can be accessed from DebugForm.swift.

Code of Conduct & Contributing Guidelines

By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

@awangwang
Copy link
Collaborator Author

@PSchmiedmayer @lukaskollmer I've gotten a demo/debug view of on-device LLM generation of nudges working! Would greatly appreciate a code review. Thanks for your time!

@awangwang
Copy link
Collaborator Author

It seems that the CodeQL tests are failing because Metal Toolchain is missing. Should it be added to the test harness?

@awangwang awangwang force-pushed the awangwang/on-device-LLMs-refactored branch from 2569ba7 to 967b775 Compare November 10, 2025 19:52
@awangwang
Copy link
Collaborator Author

@PSchmiedmayer @lukaskollmer would appreciate your help with a code review this week, especially if you think the PR is not ready to be pushed so I work on those changes! Thanks!

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

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants