Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[AI] Extract Gemini-specific logic into GeminiModelSession#16109

Merged
andrewheard merged 7 commits into
mainfirebase/firebase-ios-sdk:mainfrom
ah/ai-gemini-model-sessionfirebase/firebase-ios-sdk:ah/ai-gemini-model-sessionCopy head branch name to clipboard
Apr 23, 2026
Merged

[AI] Extract Gemini-specific logic into GeminiModelSession#16109
andrewheard merged 7 commits into
mainfirebase/firebase-ios-sdk:mainfrom
ah/ai-gemini-model-sessionfirebase/firebase-ios-sdk:ah/ai-gemini-model-sessionCopy head branch name to clipboard

Conversation

@andrewheard

@andrewheard andrewheard commented Apr 22, 2026

Copy link
Copy Markdown
Contributor
  • Extracted the Gemini-specific parts of GenerativeModelSession into a new GeminiModelSession class, which conforms to a _ModelSession protocol.
  • Added GeminiModel and GeminiModelProvider types which conform to new protocols LanguageModel and LanguageModelProvider.

The existing GenerativeModelSession now acts on opaque LanguageModel and _ModelSession types in preparation for adding support for using SystemLanguageModel and LanguageModelSession from the Foundation Models framework, as well as a HybridModel type that supports a fallback model if the primary one is unavailable.

Public types that are not intended for external use have been prefixed with underscores to hide them from autocomplete and DocC generation.

#no-changelog

@gemini-code-assist

Copy link
Copy Markdown
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.

@danger-firebase-ios

Copy link
Copy Markdown
1 Warning
⚠️ New public headers were added, did you remember to add them to the umbrella header?

Generated by 🚫 Danger

Comment thread FirebaseAI/Tests/Unit/GenerativeModelSessionAPITests.swift Outdated
Comment thread FirebaseAI/Tests/Unit/GenerativeModelSessionAPITests.swift Outdated
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Pull Request Summary

This pull request refactors the Gemini-specific logic within the FirebaseAI SDK to improve modularity and support future model types. Key changes include:

  • Refactoring: Extracted Gemini-specific logic from GenerativeModelSession into a new GeminiModelSession class, which now conforms to an internal _ModelSession protocol.
  • New Protocols: Introduced LanguageModel and LanguageModelProvider protocols to abstract model interactions.
  • API Updates: Added GeminiModel and GeminiModelProvider types. The FirebaseAI class now includes a geminiModel(name:safetySettings:requestOptions:) method for creating GeminiModel instances.
  • Internal Encapsulation: Prefixed internal types with underscores to hide them from public autocomplete and documentation.
  • Compatibility: Maintained backward compatibility for generativeModelSession(model:tools:instructions:) by extending String to conform to LanguageModelProvider.

Code Review

I have reviewed the changes. The refactoring successfully decouples the Gemini-specific implementation from the session management, which is a positive step for maintainability and extensibility.

Observations

  1. Protocol-Oriented Design: The introduction of LanguageModel and _ModelSession protocols is well-implemented and provides a clean abstraction layer for future model support (e.g., Foundation Models).
  2. Session Management: The new SessionManager class within GenerativeModelSession correctly handles concurrent request management using UnfairLock, which is appropriate for this context.
  3. API Surface: The public API changes are minimal and well-documented. The use of underscores for internal types is consistent with the goal of hiding implementation details.
  4. Testing: The added unit tests in GenerativeModelSessionAPITests.swift and updates to GenerativeModelSessionTests.swift provide good coverage for the new architecture.

Minor Suggestions

  • Documentation: Ensure that the new protocols and internal types are clearly documented in the internal documentation, even if they are hidden from public DocC, to assist future maintainers.
  • TODOs: There are a few TODO comments regarding tracking session failures and history status. Ensure these are tracked in your issue tracker to avoid them being forgotten.

Overall, the changes are well-structured and align with the stated objectives.

@andrewheard
andrewheard marked this pull request as ready for review April 23, 2026 02:32
@andrewheard
andrewheard requested a review from a team as a code owner April 23, 2026 02:32
@andrewheard
andrewheard requested a review from paulb777 April 23, 2026 02:32
@andrewheard
andrewheard merged commit 90c1771 into main Apr 23, 2026
87 checks passed
@andrewheard
andrewheard deleted the ah/ai-gemini-model-session branch April 23, 2026 03:51
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.