Skip to content

Add thinking mode view - #2848

Open
VinayGuthal wants to merge 2 commits into
masterfrom
thinking_mode
Open

VinayGuthal wants to merge 2 commits into
masterfrom
thinking_mode

Conversation

@VinayGuthal

Copy link
Copy Markdown
Contributor

Add thinking mode view to test thinking mode.

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

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.

Code Review

This pull request introduces a new "Hybrid Thinking Mode" sample feature to test the enableThinking configuration and response.thoughtSummary across On-Device, Hybrid, and Cloud inference modes. It adds ThinkingModeViewModel, ThinkingModeScreen, and associated navigation and UI state classes, alongside updating Firebase AI dependency versions. Feedback on the changes suggests optimizing streaming response accumulation by using StringBuilder instead of string concatenation to reduce memory allocations, and preventing redundant model status checks in the UI when clicking an already selected model option chip.

VinayGuthal added a commit to firebase/firebase-android-sdk that referenced this pull request Oct 14, 2026
Adds support for thinking mode (`enableThinking`) when generating
content using on-device and hybrid inference modes.

### Summary of Changes
- **`firebase-ai-ondevice-interop`**:
  - Added `enableThinking: Boolean?` to `GenerateContentRequest`.
- Added `thoughtProcess: List<Candidate>` to `GenerateContentResponse`.
  - Added `isThinkingModeAvailable(): Boolean` to `GenerativeModel`.
  - Updated `api.txt`.
- **`firebase-ai-ondevice`**:
- Implemented `GenerativeModelImpl.isThinkingModeAvailable()` delegating
to ML Kit's `GenerativeModel.isThinkingModeAvailable()`.
- Updated `Converters.kt` to pass `enableThinking` to the ML Kit request
and map `thoughtProcess` candidates to the interop
`GenerateContentResponse`.
- **`firebase-ai`**:
- Added `enableThinking: Boolean? = null` to `OnDeviceConfig` and
updated `api.txt`.
- Updated `OnDeviceGenerativeModelProvider` to check
`onDeviceModel.isThinkingModeAvailable()` when `enableThinking == true`
(throwing `FirebaseAIOnDeviceNotAvailableException` so
`PREFER_ON_DEVICE` falls back to cloud when unsupported) and forward
`enableThinking` to the on-device request.
- Updated `Candidate` and `OnDeviceGenerativeModelProvider` response
mapping to convert interop `thoughtProcess` candidates into `TextPart`
entries with `isThought = true` (populating
`GenerateContentResponse.thoughtSummary` for both unary and streaming
responses).
- **Tests & Changelogs**: Added unit tests in `ConvertersTest`,
`GenerativeModelImplTest`, and `OnDeviceGenerativeModelProviderTests`,
and updated `CHANGELOG.md` across all three modules.


Tested at firebase/quickstart-android#2848

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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