[AI] Add GenerativeModelSession with structured output APIs - #15872
Conversation
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. |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…firebase-ios-sdk into ah/ai-generative-model-session # Conflicts: # FirebaseAI/Tests/TestApp/Tests/Integration/GenerativeModelSessionTests.swift
There was a problem hiding this comment.
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.
Generated by 🚫 Danger |
There was a problem hiding this comment.
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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
GenerativeModelSession classGenerativeModelSession with structured output APIs
Public Preview: Added
GenerativeModelSessionto 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
@Generableand@Guidemacros from the Foundation Models framework to automatically generate JSON Schemas for their Swift types.GenerativeModelSessionhandles JSON decoding internally so developers can focus on defining their Swift data models rather than parsing model outputs manually.