-
Notifications
You must be signed in to change notification settings - Fork 47
[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
Conversation
There was a problem hiding this 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 toTestModelName
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 instantiateGenerativeModel
based on selected backend. - Added async methods
SendSingleMessage
,StartChatSession
,CloseChatSession
, andSendChatMessage
for AI interaction. - Updated
GUIDisplayControls
to include UI elements for backend selection, text input, sending single messages, and managing chat sessions.
- Added
- firebaseai/testapp/Assets/Firebase/Sample/FirebaseAI/UIHandlerAutomated.cs
- Renamed the private readonly field
ModelName
toTestModelName
. - Updated all usages of the renamed field (
TestModelName
) within the automated test methods (CreateGenerativeModel
,TestModelOptions
,TestMultipleCandidates
,CreateGenerativeModelWithBasicFunctionCall
,TestEnumSchemaResponse
,TestAnyOfSchemaResponse
,TestChatFunctionCalling
,TestCountTokens
).
- Renamed the private readonly field
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
-
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. ↩
There was a problem hiding this 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 methodsSendSingleMessage
andSendChatMessage
inUIHandler.cs
useasync void
. This pattern can lead to unhandled exceptions causing application crashes, as exceptions fromasync void
methods are difficult to catch. It's recommended to change their return type toasync Task
to enable proper error handling and improve application stability. - Potential Inefficiency in Model Instantiation: The
GetModel()
method inUIHandler.cs
creates a newGenerativeModel
instance on each call. This could be inefficient if the instantiation process is resource-intensive. Caching theGenerativeModel
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:
- Error Handling in Async Methods: The use of
async void
inSendSingleMessage
andSendChatMessage
(identified as a high-severity issue) should be addressed by changing them toasync Task
. This is crucial for application stability. - Model Instantiation Efficiency: The
GetModel
method could be optimized by caching theGenerativeModel
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.
Description
Adds some basic logic to send and receive text via both backends as either single messages or an ongoing chat.
Testing
Running locally
Type of Change
Place an
x
the applicable box: