Skip to content

[AI] Add GenerativeModelSession with structured output APIs - #15872

Merged
andrewheard merged 24 commits into
mainfrom
ah/ai-generative-model-session
Mar 10, 2026
Merged

[AI] Add GenerativeModelSession with structured output APIs#15872
andrewheard merged 24 commits into
mainfrom
ah/ai-generative-model-session

Conversation

@andrewheard

@andrewheard andrewheard commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Public Preview: Added GenerativeModelSession to the Firebase AI Logic SDK to provide simplified APIs for generating native Swift types using Gemini's structured output capabilities.

Enables developers to use the @Generable and @Guide macros from the Foundation Models framework to automatically generate JSON Schemas for their Swift types. GenerativeModelSession handles JSON decoding internally so developers can focus on defining their Swift data models rather than parsing model outputs manually.

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

Comment thread FirebaseAI/Sources/GenerationConfig.swift
@paulb777 paulb777 mentioned this pull request Feb 21, 2026
Comment thread FirebaseAI/Sources/GenerativeModelSession.swift Outdated
Comment thread FirebaseAI/Sources/GenerativeModelSession.swift Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 the GenerativeModelSession class, a new high-level API for single-turn interactions with generative models, especially for generating typed objects. The changes include refactoring GenerativeModel and Chat to support overriding GenerationConfig, adding a merge utility to GenerationConfig, and introducing an internal extension to handle schema transformations. The new class is well-tested with integration tests.

My main feedback points are related to a potential performance issue in stream parsing and a question about the specified OS availability versions, which seem to be set far in the future. Overall, this is a solid addition that simplifies interaction with the model for specific use cases.

Comment thread FirebaseAI/Sources/GenerativeModelSession.swift Outdated
Comment thread FirebaseAI/Sources/GenerativeModelSession.swift Outdated
@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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 the GenerativeModelSession class, providing a simplified API for structured data generation with Gemini models. The changes include significant additions like the session class itself, wrapper types for Foundation Models compatibility, and comprehensive integration tests. Existing classes like Chat, GenerativeModel, and GenerationConfig have been refactored to support per-request configuration overrides, which is essential for the new session's functionality. Overall, the implementation is robust and well-designed, with a clean public API and thorough test coverage. I have one minor suggestion to fix a typo in a comment.

Note: Security Review did not run due to the size of the PR.

Comment thread FirebaseAI/Sources/GenerationConfig.swift Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@andrewheard andrewheard added this to the 12.11.0 - M178 milestone Mar 9, 2026
@andrewheard andrewheard changed the title [AI] Add GenerativeModelSession class [AI] Add GenerativeModelSession with structured output APIs Mar 9, 2026
@andrewheard
andrewheard marked this pull request as ready for review March 9, 2026 21:58
@andrewheard
andrewheard requested a review from a team as a code owner March 9, 2026 21:58
@andrewheard
andrewheard requested a review from paulb777 March 9, 2026 21:59
Comment thread FirebaseAI/Sources/Types/Public/StructuredOutput/GenerationID.swift
Comment thread FirebaseAI/Sources/GenerativeModel.swift
@andrewheard
andrewheard merged commit 4565e79 into main Mar 10, 2026
139 of 141 checks passed
@andrewheard
andrewheard deleted the ah/ai-generative-model-session branch March 10, 2026 04: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