Skip to content

feat: dynamic model selection for Gemini Flash, Pro, and Gemma#16

Open
SISIR-REDDY wants to merge 1 commit intoAOSSIE-Org:mainfrom
SISIR-REDDY:feat/dynamic-model-selection
Open

feat: dynamic model selection for Gemini Flash, Pro, and Gemma#16
SISIR-REDDY wants to merge 1 commit intoAOSSIE-Org:mainfrom
SISIR-REDDY:feat/dynamic-model-selection

Conversation

@SISIR-REDDY
Copy link

@SISIR-REDDY SISIR-REDDY commented Mar 14, 2026

Closes #8

Problem

ChatbotService had the Gemini model hardcoded as gemini-2.0-flash. Users with more complex medical notes had no way to use a more capable model, and there was no path to try Gemma's open-weight models.

Changes

lib/services/chatbot_service.dart

  • Added a GeminiModel enum with three entries:

    Value Model ID Use case
    flash (default) gemini-2.0-flash Fast responses, good for most tasks
    pro gemini-1.5-pro Higher accuracy for complex reasoning
    gemma gemma-3-27b-it Open-weight, efficient summarisation

    Each entry carries a modelId (used in the API URL), a displayName (shown in the UI), and a short description (shown as a subtitle in the picker).

  • ChatbotService now holds a selectedModel field (defaults to flash) that is used when building the API URL. It can be changed at any time between recordings.

  • Added hasValidApiKey guard and structured Gemini error extraction while staying independently reviewable from fix: prevent RenderFlex overflow on small screens and improve API key validation #13.

lib/main.dart

  • Added a PopupMenuButton (tune icon) to the right of the "DocPilot" title. Tapping it shows the three models with their descriptions. Selecting one updates _chatbotService.selectedModel via setState.
  • The status text during processing now reads "Processing with [Model Name]..." instead of the generic "Processing with Gemini...".

How it works

The model picker is in the app bar area so it is always accessible. The selected model persists for the lifetime of the app session and is used for all Gemini calls (summary and prescription) until changed.

Summary by CodeRabbit

  • New Features

    • Added model selection dropdown in the app header
    • Support for multiple AI models: Gemini 2.0 Flash, Gemini 1.5 Pro, and Gemma 3 27B
  • Improvements

    • Enhanced API key validation and error handling
    • Processing status messages now display the currently selected model
    • Added request timeout for improved reliability

Closes AOSSIE-Org#8

- Add GeminiModel enum with three options: Gemini 2.0 Flash (default),
  Gemini 1.5 Pro, and Gemma 3 27B; each carries a modelId, displayName,
  and a short description shown in the picker
- Update ChatbotService to hold a selectedModel field and build the API
  URL from it at call time; model can be changed at any point between
  recordings
- Add hasValidApiKey guard and structured error extraction (mirrors the
  approach in AOSSIE-Org#13) while keeping this PR independently reviewable
- Add a tune icon button in the header row of TranscriptionScreen that
  opens a PopupMenuButton listing all three models with their descriptions
- Status text updates to show the active model name during processing
@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

📝 Walkthrough

Walkthrough

The changes introduce dynamic model selection to the DocPilot application, enabling users to choose between three AI models (Gemini 2.0 Flash, Gemini 1.5 Pro, and Gemma 3 27B) through a UI dropdown. The backend API integration is updated to use the selected model and includes improved request/response handling with validation and error logging.

Changes

Cohort / File(s) Summary
Model Infrastructure
lib/services/chatbot_service.dart
Introduces GeminiModel enum with three model variants (flash, pro, gemma). Adds configurable selectedModel to ChatbotService with constructor parameter. Refactors API key handling to private _apiKey with hasValidApiKey getter. Updates request payload to nested JSON with generationConfig, implements 30-second timeout, and enhances response parsing with defensive checks and comprehensive error handling via developer.log.
UI Model Selection
lib/main.dart
Adds _buildModelPicker() method that renders a PopupMenuButton in the app header for model selection. Wires selection to update _chatbotService.selectedModel. Updates processing state message to display the currently selected model's displayName.

Sequence Diagram

sequenceDiagram
    participant User as User/UI
    participant App as main.dart
    participant Service as ChatbotService
    participant API as Gemini API

    User->>App: Selects model from dropdown
    App->>Service: Update selectedModel
    Service-->>App: selectedModel changed
    App-->>User: UI reflects new model selection
    
    User->>App: Sends chat message
    App->>Service: Call getGeminiResponse()
    Service->>Service: Validate hasValidApiKey
    Service->>API: POST with selectedModel.modelId<br/>generationConfig, contents
    API-->>Service: Response with candidates
    Service->>Service: Parse candidates[0].content.parts[0].text<br/>with defensive checks
    Service-->>App: Return formatted response text
    App-->>User: Display response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A model picker hops into view,
With Flash for speed and Pro for truth,
Gemma whispers efficient lore—
Now users choose what works best for,
Their clinical needs, forevermore! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: dynamic model selection for Gemini Flash, Pro, and Gemma' directly reflects the main change - adding dynamic model selection capability with three specific models.
Linked Issues check ✅ Passed The PR fully addresses issue #8 requirements: adds UI model picker (PopupMenuButton in app bar), implements GeminiModel enum with Flash/Pro/Gemma, enables dynamic API calls using selectedModel, and supports user choice between speed and accuracy.
Out of Scope Changes check ✅ Passed All changes align with issue #8 objectives - GeminiModel enum, ChatbotService modifications for model selection, app bar UI picker, and status text updates are all directly related to enabling dynamic model selection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
lib/main.dart (1)

437-446: Inconsistent status messaging—consider including the model name here as well.

Line 340 displays the selected model name ("Processing with Gemini 2.0 Flash..."), but this status indicator at line 443 still uses the generic "Generating content with Gemini..." text. For consistency, consider using the model's displayName here too.

♻️ Suggested fix
                       Text(
                         _isRecording
                             ? 'Recording in progress'
                             : _isTranscribing
                             ? 'Processing audio...'
                             : _isProcessing
-                            ? 'Generating content with Gemini...'
+                            ? 'Generating content with ${_chatbotService.selectedModel.displayName}...'
                             : _transcription.isEmpty
                             ? 'Press the microphone button to start'
                             : 'Ready to view results',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/main.dart` around lines 437 - 446, The status text branch that shows
'Generating content with Gemini...' uses a hardcoded label; update that branch
to include the currently selected model's displayName (same source used for line
340), e.g., replace the literal 'Generating content with Gemini...' with a
formatted string that inserts the model display name (referencing the state
variable/property that holds the selected model, and the existing flags
_isRecording, _isTranscribing, _isProcessing, _transcription to find the
branch). Ensure the replacement uses the same property (e.g.,
selectedModel.displayName or the existing variable used for "Processing with
Gemini 2.0 Flash...") so the status becomes 'Generating content with
{displayName}...' and stays consistent with the other status message.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/main.dart`:
- Around line 437-446: The status text branch that shows 'Generating content
with Gemini...' uses a hardcoded label; update that branch to include the
currently selected model's displayName (same source used for line 340), e.g.,
replace the literal 'Generating content with Gemini...' with a formatted string
that inserts the model display name (referencing the state variable/property
that holds the selected model, and the existing flags _isRecording,
_isTranscribing, _isProcessing, _transcription to find the branch). Ensure the
replacement uses the same property (e.g., selectedModel.displayName or the
existing variable used for "Processing with Gemini 2.0 Flash...") so the status
becomes 'Generating content with {displayName}...' and stays consistent with the
other status message.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 455ea401-5655-4c56-88ba-c9f0fd780aee

📥 Commits

Reviewing files that changed from the base of the PR and between ece30ed and a9f7e0f.

📒 Files selected for processing (2)
  • lib/main.dart
  • lib/services/chatbot_service.dart

@github-actions
Copy link

⚠️ This PR has merge conflicts.

Please resolve the merge conflicts before review.

Your PR will only be reviewed by a maintainer after all conflicts have been resolved.

📺 Watch this video to understand why conflicts occur and how to resolve them:
https://www.youtube.com/watch?v=Sqsz1-o7nXk

@dhruvi-16-me
Copy link

dhruvi-16-me commented Mar 23, 2026

Hey @SharkyBytes I went through this PR and it is duplicate of PR #9. It does not have a POW as well. I don't think it is needed so you can close it.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Enable Dynamic Model Selection (Gemini 3 & Gemma Support)

2 participants