Skip to content

feat(ai-logic): add hybrid on-device inference sample#2773

Open
thatfiredev wants to merge 8 commits intomasterfrom
rpf/add-hybrid-sample
Open

feat(ai-logic): add hybrid on-device inference sample#2773
thatfiredev wants to merge 8 commits intomasterfrom
rpf/add-hybrid-sample

Conversation

@thatfiredev
Copy link
Copy Markdown
Member

@thatfiredev thatfiredev commented Mar 26, 2026

Note that this also:

  • bumps the Firebase BoM from 34.7.0 to 34.11.0
  • bumps the minSdk from 23 to 26 (minimum required for ondevice)

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a Hybrid Receipt Scanner feature that utilizes Firebase AI to extract expense data from receipts, preferring on-device inference. The changes include the addition of a new ViewModel for managing model downloads and scanning logic, a Compose-based UI for displaying expenses, and necessary dependency updates. Review feedback highlights the need to handle exceptions in the image picker rather than leaving the catch block empty, improving the robustness of the CSV parsing logic to handle store names containing commas, and removing an unnecessary non-null assertion where Kotlin smart-casting is already available.

@thatfiredev
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a Hybrid Receipt Scanner feature that utilizes Firebase AI's hybrid inference to extract expense data from receipts, prioritizing on-device processing. The implementation includes a new ViewModel for model management and receipt parsing, a dedicated UI screen, and necessary dependency updates. Feedback focuses on enhancing error handling for parsing failures and image loading issues, as well as improving localization by using standard currency formatting instead of hardcoded symbols.

@thatfiredev thatfiredev marked this pull request as ready for review March 27, 2026 16:32
viewModelScope.launch {
_uiState.update { it.copy(isScanning = true, errorMessage = null) }
try {
val prompt = content {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a comment saying something along the lines of "This sample code is just an example. You should not leave your prompt harcoded on the client. Read the Firebase AI Logic documentation to learn how to move your prompts to the server."?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have lots of prompts in this quickstart, I think if we do it here we'd have to do for all of them, which then becomes a burden to maintain.

Also: I think not every prompt needs to be on the server. Some of them don't contain anything sensitive and are ok to have on the client.

@@ -0,0 +1,206 @@
package com.google.firebase.quickstart.ai.ui
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a screenshot of the new screen to the PR description?

Copy link
Copy Markdown
Contributor

@marinacoelho marinacoelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great - just two minor requests.

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