[AI] Add FirebaseAI.generativeModelSession(...)#15913
[AI] Add FirebaseAI.generativeModelSession(...)#15913andrewheard merged 5 commits intoah/ai-generative-model-sessionfrom
FirebaseAI.generativeModelSession(...)#15913Conversation
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
There was a problem hiding this comment.
Code Review
This pull request introduces a convenient factory method FirebaseAI.generativeModelSession(...) for creating GenerativeModelSession instances, which improves the API's usability. The changes also include making the GenerativeModelSession initializer internal, updating documentation to accurately reflect its multi-turn capabilities, and refactoring tests to use the new factory method. My review includes a suggestion to improve parameter naming consistency in the new factory method, a correction for a documentation fragment, and several minor formatting suggestions in the test files to improve readability.
This PR introduces a new factory method on the
FirebaseAIclass to createGenerativeModelSessioninstances, providing a cleaner and more unified API. It also updates the documentation to correctly reflect thatGenerativeModelSessionhandles multi-turn interactions and retains history between requests. As part of this change, the public initializer forGenerativeModelSessionhas been made internal.Motivation/Context
Previously, users had to manually instantiate a
GenerativeModeland then pass it to theGenerativeModelSessioninitializer. By introducingFirebaseAI.generativeModelSession(model:instructions:), we streamline the API, making it easier and more intuitive to start a new generative session.Additionally, the documentation for
GenerativeModelSessioninaccurately described it as being ideal for single-turn requests. This PR corrects the documentation to clarify that it actually retains history and handles multi-turn interactions similar to theChatclass.Note: Certain methods utilizing
FoundationModels.GenerationSchemahave been temporarily made internal untilFirebaseAI.GenerationSchema's public API is ready.Technical Details
generativeModelSessionfactory method: AddedFirebaseAI.generativeModelSession(model:instructions:)to easily instantiate a new session directly from aFirebaseAIinstance.GenerativeModelSession.init(model:)frompublictointernalto encourage the use of the new factory method.GenerativeModelSessionclass-level documentation to emphasize its multi-turn, history-retaining capabilities instead of single-turn usage.respond(to:schema:...)andstreamResponse(to:schema:...)frompublictointernalpending the stabilization ofFirebaseAI.GenerationSchema.GenerativeModelSessionTests.swiftto use the newFirebaseAI.generativeModelSession(model:)factory method instead of the deprecated initialization pattern.#no-changelog