Skip to content

[AI] Add ImageConfig support for generateContent - #15923

Merged
daymxn merged 31 commits into
mainfrom
pb-image-config
Apr 28, 2026
Merged

[AI] Add ImageConfig support for generateContent#15923
daymxn merged 31 commits into
mainfrom
pb-image-config

Conversation

@paulb777

@paulb777 paulb777 commented Mar 10, 2026

Copy link
Copy Markdown
Member

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 #15371 and #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.

@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

danger-firebase-ios Bot commented Mar 10, 2026

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

Generated by 🚫 Danger

@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

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

Comment thread FirebaseAI/Sources/Types/Public/AGENTS.md Outdated
Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/Imagen/AGENTS.md Outdated
@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

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

Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/Imagen/ImagenGenerationConfig.swift
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

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

Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift Outdated
@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

@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 ImageConfig to support configuring image aspect ratios and sizes, which is a valuable addition. The changes are well-implemented across the configuration, internal types, and are accompanied by thorough tests. I have a few minor suggestions to improve code clarity and consistency, mainly concerning API availability annotations, copyright year typos, and some comments in the test files.

Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift
Comment thread FirebaseAI/Sources/Types/Public/Imagen/ImagenImageSize.swift
Comment thread FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift Outdated
Comment thread FirebaseAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift Outdated
Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift
@paulb777

paulb777 commented Apr 6, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 ImageConfig struct to support configuring aspect ratio and image size during image generation, integrating it into the existing GenerationConfig. The changes include updates to the public API, documentation, and the addition of integration tests to verify image generation with various configurations. However, the implementation of ImageConfig.AspectRatio and ImageConfig.ImageSize is currently incomplete as they lack the required initializers to handle the internal Kind enum, which will result in compilation failures.

Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift
Comment thread FirebaseAI/Sources/Types/Public/ImageConfig.swift
@paulb777

paulb777 commented Apr 6, 2026

Copy link
Copy Markdown
Member Author

/gemini summarize

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request enhances the FirebaseAI SDK by providing granular control over image generation parameters. By decoupling image configuration from general generation settings, the changes improve API usability and type safety while enabling support for higher-resolution outputs and diverse aspect ratios. The implementation maintains backward compatibility and follows established SDK patterns, supported by robust testing.

Highlights

  • New ImageConfig API: Introduced a dedicated ImageConfig struct to the FirebaseAI SDK, enabling developers to specify aspect ratios and image sizes for content generation.
  • Expanded Model Capabilities: Added support for 2K image generation with Imagen models and a wider range of aspect ratios, including 2:3, 3:2, 4:5, and 21:9.
  • Integration and Testing: Integrated ImageConfig into GenerationConfig and added comprehensive unit and integration tests to ensure correct JSON encoding and backend compatibility.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Activity
  • Initial PR submission and automated linting/Danger checks.
  • Multiple rounds of automated code review feedback regarding documentation, naming conventions, and structural improvements.
  • Discussion regarding the use of @available attributes and the design of the AspectRatio API.
  • Clarification provided by the author regarding the compilation of AspectRatio and ImageSize initializers via protocol extensions.
  • Final review and summary generation.

@daymxn daymxn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just from a quick cursory pass through, LGTM with some minor changes. Also worth looking at some of Gemini's suggestions.

Comment thread FirebaseAI/Sources/GenerationConfig.swift Outdated
Comment thread FirebaseAI/CHANGELOG.md Outdated
Comment thread FirebaseAI/Sources/GenerationConfig.swift Outdated
@paulb777
paulb777 marked this pull request as ready for review April 24, 2026 16:44
@paulb777
paulb777 requested a review from a team as a code owner April 24, 2026 16:44
@paulb777

Copy link
Copy Markdown
Member Author

Integration test failures look like flakes

@paulb777
paulb777 requested a review from daymxn April 24, 2026 18:46
@daymxn
daymxn requested a review from andrewheard April 27, 2026 20:11
@daymxn
daymxn merged commit 7c3c8b5 into main Apr 28, 2026
130 of 133 checks passed
@daymxn
daymxn deleted the pb-image-config branch April 28, 2026 19:04
leojaygoogle pushed a commit that referenced this pull request Jun 29, 2026
Co-authored-by: Andrew Heard <andrewheard@google.com>
Co-authored-by: Daymon <daymxn@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

3 participants