[AI] Add ImageConfig support for generateContent#15923
[AI] Add ImageConfig support for generateContent#15923
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. |
Generated by 🚫 Danger |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for ImageConfig to generateContent, allowing users to specify aspect ratio and size for generated images. The implementation is solid, introducing a new ImageConfig type and refactoring existing Imagen-related types to reuse it, which is a great approach for consistency and maintainability. The changes are well-supported by new unit and integration tests. I have a few minor suggestions to improve documentation and code organization.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for ImageConfig in generateContent, allowing users to configure image generation properties like aspect ratio and image size. No vulnerabilities were found during the security review. The changes are well-structured, integrating a new ImageConfig type into GenerationConfig and refactoring existing Imagen types to reuse these components, which reduces code duplication. The changes are also well-tested with new unit and integration tests. Minor typos in the documentation could be addressed.
FirebaseAI/Sources/Types/Public/Imagen/ImagenGenerationConfig.swift
Outdated
Show resolved
Hide resolved
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.
Code Review
This pull request effectively adds support for ImageConfig to allow configuration of image generation properties. The changes are well-structured, including the introduction of a new ImageConfig type, its integration into GenerationConfig, and updates to internal types and tests. The refactoring to use typealias for ImagenAspectRatio and ImagenImageSize is a good improvement for code reuse. The changes are well-tested. I have one minor suggestion to improve documentation clarity.
Add support for configuring image aspect ratios and sizes when generating images using Nano Banana. Also adds support for 2K images with Imagen (previously only the default 1K was possible).
Successor to #15920
This pull request introduces a new ImageConfig struct to the FirebaseAI SDK, allowing developers to specify aspect ratio and image size when generating content with Gemini models.
Overall, the changes are well-structured, follow Swift naming conventions, and include comprehensive unit and integration tests. Below is a detailed review of the implementation.
Architecture & API Design
The PR effectively decouples image configuration from the general GenerationConfig by introducing a dedicated ImageConfig.
Type Safety: The use of typealias for ImagenAspectRatio and ImagenImageSize in ImagenAspectRatio.swift and ImagenImageSize.swift maintains backward compatibility while redirecting to the new unified ImageConfig definitions.
Expansion of Constants: Added support for a wide variety of aspect ratios (e.g., 2:3, 3:2, 4:5, 21:9) and new image sizes (512, 1K, 2K, 4K) in ImageConfig.swift.
Integration: The addition of imageConfig to GenerationConfig in GenerationConfig.swift is the correct approach to make these features accessible through the standard model initialization flow.
Implementation Details
Codable Support: The manual implementation of Encodable for AspectRatio and ImageSize using singleValueContainer ensures the raw string values (e.g., "16:9") are sent to the backend rather than the struct wrappers.
Availability: All new types are correctly marked with @available for iOS 15+, macOS 12+, etc., matching the rest of the SDK’s requirements.
Internal Mapping: The logic in ImagenModel.swift (line 140) correctly maps the new imageSize to the internal sampleImageSize parameter used by the Imagen API.
Testing & Documentation
Integration Tests: The new test generateImageConfig in GenerateContentIntegrationTests.swift provides a solid end-to-end check using actual model names like gemini-3.1-flash-image-preview.
Unit Tests: ImageGenerationParametersTests.swift has been updated to cover various combinations of parameters, ensuring that the encoding logic produces the expected JSON structure for the backend.
Documentation: The update to AGENTS.md and CHANGELOG.md ensures the team and users are aware of the new public API surface.