Skip to content

[AI] Add FirebaseAI.generativeModelSession(...)#15913

Merged
andrewheard merged 5 commits intoah/ai-generative-model-sessionfrom
ah/ai-generative-model-session-api
Mar 7, 2026
Merged

[AI] Add FirebaseAI.generativeModelSession(...)#15913
andrewheard merged 5 commits intoah/ai-generative-model-sessionfrom
ah/ai-generative-model-session-api

Conversation

@andrewheard
Copy link
Contributor

@andrewheard andrewheard commented Mar 6, 2026

This PR introduces a new factory method on the FirebaseAI class to create GenerativeModelSession instances, providing a cleaner and more unified API. It also updates the documentation to correctly reflect that GenerativeModelSession handles multi-turn interactions and retains history between requests. As part of this change, the public initializer for GenerativeModelSession has been made internal.

Motivation/Context

Previously, users had to manually instantiate a GenerativeModel and then pass it to the GenerativeModelSession initializer. By introducing FirebaseAI.generativeModelSession(model:instructions:), we streamline the API, making it easier and more intuitive to start a new generative session.

Additionally, the documentation for GenerativeModelSession inaccurately 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 the Chat class.

Note: Certain methods utilizing FoundationModels.GenerationSchema have been temporarily made internal until FirebaseAI.GenerationSchema's public API is ready.

Technical Details
  • Added generativeModelSession factory method: Added FirebaseAI.generativeModelSession(model:instructions:) to easily instantiate a new session directly from a FirebaseAI instance.
  • Restricted Initializer Visibility: Changed GenerativeModelSession.init(model:) from public to internal to encourage the use of the new factory method.
  • Documentation Updates: Revised GenerativeModelSession class-level documentation to emphasize its multi-turn, history-retaining capabilities instead of single-turn usage.
  • Schema Methods Visibility: Temporarily changed the access modifiers of respond(to:schema:...) and streamResponse(to:schema:...) from public to internal pending the stabilization of FirebaseAI.GenerationSchema.
  • Test Refactoring: Updated all integration tests in GenerativeModelSessionTests.swift to use the new FirebaseAI.generativeModelSession(model:) factory method instead of the deprecated initialization pattern.

#no-changelog

@gemini-code-assist
Copy link
Contributor

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

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

Copy link
Contributor

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

@andrewheard andrewheard marked this pull request as ready for review March 6, 2026 21:01
@andrewheard andrewheard requested a review from paulb777 March 6, 2026 21:01
@andrewheard andrewheard merged commit a52e042 into ah/ai-generative-model-session Mar 7, 2026
83 checks passed
@andrewheard andrewheard deleted the ah/ai-generative-model-session-api branch March 7, 2026 18:32
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.

2 participants