-
Notifications
You must be signed in to change notification settings - Fork 1.7k
FirebaseGenerable #15527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
FirebaseGenerable #15527
Conversation
Generated by 🚫 Danger |
|
/gemini review |
There was a problem hiding this 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 powerful new feature, FirebaseGenerable, which simplifies generating structured Swift objects from the generative model. The use of a macro to automatically derive the schema is a great developer experience improvement. The overall implementation is solid, but I've identified a few critical issues that could lead to unexpected behavior or difficult debugging. My main concerns are:
- The
@FirebaseGenerablemacro does not correctly handle optional properties, leading to an incorrect schema. - The
generateObjectmethod silently discards existingGenerationConfigsettings like temperature, which will likely surprise users. - The schema derivation for nested types fails silently if a type is not
FirebaseGenerable, which can make debugging difficult.
I've also included a minor suggestion to improve the schema accuracy forFloattypes. Addressing these points will make this new feature more robust and predictable for developers.
FirebaseAILogicMacros/Sources/FirebaseAILogicMacro/FirebaseGenerableMacro.swift
Show resolved
Hide resolved
FirebaseAILogicMacros/Sources/FirebaseAILogicMacro/FirebaseGenerableMacro.swift
Outdated
Show resolved
Hide resolved
…erableMacro.swift Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this 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 the FirebaseGenerable protocol and a corresponding @FirebaseGenerable macro to simplify the generation of structured objects from the language model. A new generateObject convenience method is added to GenerativeModel for this purpose. The changes include new error types, package dependencies for the macro, and integration tests.
My review has identified a critical bug in the macro implementation that affects integer properties. I've also pointed out a couple of areas where the code could be made more robust against future changes to reduce maintenance overhead, and a suggestion to improve test coverage for the new macro.
FirebaseAILogicMacros/Sources/FirebaseAILogicMacro/FirebaseGenerableMacro.swift
Outdated
Show resolved
Hide resolved
FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift
Show resolved
Hide resolved
FirebaseAILogicMacros/Tests/FirebaseAILogicMacroTests/FirebaseAILogicMacroTests.swift
Show resolved
Hide resolved
|
/gemini review |
|
/gemini summary |
There was a problem hiding this 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 significant and valuable feature: the ability to generate strongly-typed objects from model prompts using a new FirebaseGenerable protocol and a corresponding @FirebaseGenerable macro. The implementation is well-thought-out, adding a new generateObject convenience method, supporting infrastructure like a copying initializer for GenerationConfig, and providing comprehensive integration tests. My review includes a critical fix for the macro implementation to correctly handle multiple property bindings and filter computed properties, along with a few minor suggestions to improve code style and test robustness. Overall, this is a great addition.
FirebaseAILogicMacros/Sources/FirebaseAILogicMacro/FirebaseGenerableMacro.swift
Outdated
Show resolved
Hide resolved
FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift
Outdated
Show resolved
Hide resolved
FirebaseAILogicMacros/Sources/FirebaseAILogicMacro/FirebaseGenerableMacro.swift
Outdated
Show resolved
Hide resolved
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is a well-structured pull request that introduces a powerful new feature for generating structured objects. The use of a Swift macro to automate schema generation is a great approach that will significantly simplify the developer experience. The code is clear, and the addition of comprehensive integration tests is much appreciated. I have a few suggestions to further improve the code.
FirebaseAILogicMacros/Tests/FirebaseAILogicMacroTests/FirebaseAILogicMacroTests.swift
Show resolved
Hide resolved
FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift
Outdated
Show resolved
Hide resolved
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is an excellent pull request that introduces a significant and powerful feature: the ability to generate structured Swift objects directly from the model. The implementation is very well done, with a clean, user-friendly API (generateObject and @FirebaseGenerable), robust macro implementation, and thorough testing.
The design choices are solid, such as creating a temporary model instance with an overridden configuration to avoid side effects. The new error types and comprehensive integration tests, especially the one verifying configuration inheritance, contribute to a high-quality addition to the SDK.
I have one minor suggestion to improve the macro's robustness, but overall, this is a fantastic contribution.
wip
Add
func generateObject<T: FirebaseGenerable>(as type: T.Type, from prompt: String) async throws -> TThe new tests pass locally
Summary of Changes
This pull request significantly enhances the Firebase AI SDK by introducing the capability to generate structured Swift objects directly from generative model responses. It achieves this through a new
FirebaseGenerableprotocol and a Swift macro that automatically creates a schema forDecodabletypes. This feature streamlines the development workflow for applications requiring structured data output from AI models, reducing boilerplate and improving type safety.Highlights
generateObjectfunction inGenerativeModelthat allows generating structured Swift objects directly from the model's response, automating schema generation and JSON decoding.FirebaseGenerableprotocol and an associated Swift macro (@FirebaseGenerable) to automatically derive aSchemaforDecodabletypes, simplifying the process of defining the expected output structure for the model.GenerationConfigto allow for proper inheritance of existing settings when creating a new configuration for object generation, ensuring that parameters like temperature and token limits are respected.FirebaseGenerabletypes, ensuring that the model understands which fields can be null.GenerateObjectError) to provide clearer feedback when object generation fails due to issues like missing response text or JSON decoding problems.