Skip to content

[FirebaseAI] Add basic logic to the sample #1256

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

Merged
merged 2 commits into from
May 20, 2025
Merged

Conversation

a-maurice
Copy link
Collaborator

Description

Provide details of the change, and generalize the change in the PR title above.

Adds some basic logic to send and receive text via both backends as either single messages or an ongoing chat.


Testing

Describe how you've tested these changes.

Running locally


Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

Copy link

@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.

Hello @a-maurice, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello! Gemini here, providing a summary of this pull request. This PR, titled "[FirebaseAI] Add basic logic to the sample", introduces core functionality to the Firebase AI sample application's UI handler. The main goal is to demonstrate how to send and receive text messages using the Firebase AI SDK, supporting both single message interactions and ongoing chat sessions. It also adds the ability to switch between the Google AI and Vertex AI backends directly within the sample UI. Additionally, a minor refactor was performed in the automated test handler to clarify variable naming.

Highlights

  • Core AI Interaction Logic: Adds methods and UI elements to the sample application to allow users to send single text messages and initiate/manage chat sessions with a generative model.
  • Backend Selection: Introduces a UI control to select between the Google AI and Vertex AI backends for the generative model interactions.
  • UI Updates: Modifies the sample's UI handler (UIHandler.cs) to include input fields, buttons, and backend selection based on whether a chat session is active.
  • Automated Test Refactor: Renames the ModelName field to TestModelName in the automated test handler (UIHandlerAutomated.cs) for better clarity.

Changelog

  • firebaseai/testapp/Assets/Firebase/Sample/FirebaseAI/UIHandler.cs
    • Added using Firebase.AI; namespace import.
    • Removed unused PlaceholderFunction method.
    • Added fields for model name, backend selection, and chat session state.
    • Implemented GetModel method to instantiate GenerativeModel based on selected backend.
    • Added async methods SendSingleMessage, StartChatSession, CloseChatSession, and SendChatMessage for AI interaction.
    • Updated GUIDisplayControls to include UI elements for backend selection, text input, sending single messages, and managing chat sessions.
  • firebaseai/testapp/Assets/Firebase/Sample/FirebaseAI/UIHandlerAutomated.cs
    • Renamed the private readonly field ModelName to TestModelName.
    • Updated all usages of the renamed field (TestModelName) within the automated test methods (CreateGenerativeModel, TestModelOptions, TestMultipleCandidates, CreateGenerativeModelWithBasicFunctionCall, TestEnumSchemaResponse, TestAnyOfSchemaResponse, TestChatFunctionCalling, TestCountTokens).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Code flows like a stream,
AI answers a bright dream,
Chatting, line by line.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 foundational logic for sending and receiving text with Firebase AI, supporting both single messages and chat sessions across different backends. The implementation is a good starting point for the sample application.

I've identified a couple of areas for improvement, primarily concerning error handling in asynchronous operations and potential inefficiencies in model instantiation. Addressing these will enhance the robustness and performance of the sample.

Summary of Findings

  • Risk of Unhandled Exceptions with async void: The methods SendSingleMessage and SendChatMessage in UIHandler.cs use async void. This pattern can lead to unhandled exceptions causing application crashes, as exceptions from async void methods are difficult to catch. It's recommended to change their return type to async Task to enable proper error handling and improve application stability.
  • Potential Inefficiency in Model Instantiation: The GetModel() method in UIHandler.cs creates a new GenerativeModel instance on each call. This could be inefficient if the instantiation process is resource-intensive. Caching the GenerativeModel instance and reusing it when parameters haven't changed is advisable for better performance.

Merge Readiness

This pull request adds valuable core functionality to the Firebase AI sample. The code is generally clear and achieves its stated goals.

However, there are a couple of important considerations before merging:

  1. Error Handling in Async Methods: The use of async void in SendSingleMessage and SendChatMessage (identified as a high-severity issue) should be addressed by changing them to async Task. This is crucial for application stability.
  2. Model Instantiation Efficiency: The GetModel method could be optimized by caching the GenerativeModel instance to avoid repeated initializations.

I recommend addressing at least the async void issue before this PR is merged to ensure a more robust sample application. As I am not authorized to approve pull requests, please ensure that these points are considered and that the PR receives further review and approval from authorized team members.

@a-maurice a-maurice requested a review from cynthiajoan May 20, 2025 22:14
@a-maurice a-maurice merged commit 1a8b20f into main May 20, 2025
5 checks passed
@a-maurice a-maurice deleted the am-firebaseai_sample branch May 20, 2025 22:25
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