-
Notifications
You must be signed in to change notification settings - Fork 35
Add Gemini 3 Pro Image configuration support for Microsoft.Extensions.AI #89
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
Conversation
WalkthroughThis pull request extends image generation configuration capabilities by introducing new properties and constants. It adds three new constants for image sizing and output formatting to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (1)
345-369: Image config mapping looks good; consider nullable/range handling for CompressionQualityThe new mappings for
ImageSizeandMimeTypeare straightforward and correctly initializeImageConfig/ImageOutputOptionson demand. ForCompressionQuality, you currently read into a non-nullableinteven though the model property isint?:if (options.AdditionalProperties.TryGetValue(AdditionalPropertiesKeys.ImageOutputOptionsCompressionQuality, out int compressionQuality)) { config.ImageConfig ??= new ImageConfig(); config.ImageConfig.ImageOutputOptions ??= new ImageOutputOptions(); config.ImageConfig.ImageOutputOptions.CompressionQuality = compressionQuality; }To align with the optional nature of the field and avoid issues if the value is ever stored as nullable, you could switch to
int?and guard before assignment:- if (options.AdditionalProperties.TryGetValue(AdditionalPropertiesKeys.ImageOutputOptionsCompressionQuality, out int compressionQuality)) - { - config.ImageConfig ??= new ImageConfig(); - config.ImageConfig.ImageOutputOptions ??= new ImageOutputOptions(); - config.ImageConfig.ImageOutputOptions.CompressionQuality = compressionQuality; - } + if (options.AdditionalProperties.TryGetValue(AdditionalPropertiesKeys.ImageOutputOptionsCompressionQuality, out int? compressionQuality) + && compressionQuality is not null) + { + config.ImageConfig ??= new ImageConfig(); + config.ImageConfig.ImageOutputOptions ??= new ImageOutputOptions(); + config.ImageConfig.ImageOutputOptions.CompressionQuality = compressionQuality; + }If you want to be stricter, you could also validate that the value is within 0–100 before assigning it, to match the documented range.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/GenerativeAI.Microsoft/AdditionalPropertyKeys.cs(1 hunks)src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs(1 hunks)src/GenerativeAI/Constants/ImageConfigValues.cs(1 hunks)src/GenerativeAI/Types/ContentGeneration/Config/GenerationConfig.cs(5 hunks)src/GenerativeAI/Types/TypesSerializerContext.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (2)
src/GenerativeAI.Microsoft/AdditionalPropertyKeys.cs (1)
AdditionalPropertiesKeys(6-42)src/GenerativeAI/Types/ContentGeneration/Config/GenerationConfig.cs (2)
ImageConfig(339-369)ImageOutputOptions(377-397)
src/GenerativeAI/Types/TypesSerializerContext.cs (1)
src/GenerativeAI/Types/ContentGeneration/Config/GenerationConfig.cs (2)
ImageConfig(339-369)ImageOutputOptions(377-397)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build (9.0.x)
🔇 Additional comments (5)
src/GenerativeAI/Types/TypesSerializerContext.cs (1)
22-24: Adding ImageConfig/ImageOutputOptions to the serializer context is correctIncluding these DTOs in the source-generated context aligns with the new
GenerationConfig.ImageConfigsurface and ensures they serialize without reflection.src/GenerativeAI.Microsoft/AdditionalPropertyKeys.cs (1)
28-41: New image-related AdditionalProperties keys are consistent and well-documentedThe added keys for image size, MIME type, and compression quality align with the new
ImageConfig/ImageOutputOptionsproperties and the MicrosoftExtensions mapping; naming and docs are clear and consistent with existing keys.src/GenerativeAI/Types/ContentGeneration/Config/GenerationConfig.cs (2)
169-175: ThinkingConfig docs and usage remain coherent with MicrosoftExtensionsThe
ThinkingConfigproperty onGenerationConfigand theThinkingConfigclass (IncludeThoughts,ThinkingBudget) are documented consistently with how the Microsoft extensions populate them fromAdditionalProperties. No functional or shape issues here.Also applies to: 221-237
213-217: ImageConfig and ImageOutputOptions model the new image-generation options cleanlyThe new
ImageConfigproperty onGenerationConfigand theImageConfig/ImageOutputOptionsDTOs:
- Use the expected JSON property names (
imageConfig,aspectRatio,imageSize,imageOutputOptions,mimeType,compressionQuality).- Clearly document supported values and reference
ImageConfigValuesfor discoverable constants.- Keep all fields optional so existing callers are unaffected when not using image output.
This is a straightforward, backwards-compatible extension of the configuration surface.
Also applies to: 332-397
src/GenerativeAI/Constants/ImageConfigValues.cs (1)
1-59: ImageConfigValues constants are well-structured and aligned with the config modelCentralizing common aspect ratios, image sizes, and output MIME types here matches the new
ImageConfig/ImageOutputOptionsdocs and avoids scattering magic strings. The nested static classes make the API surface easy to discover while keeping it non-restrictive.
Enables configuration of image generation settings (resolution, output format) when using Gemini models with image output capabilities through the Microsoft.Extensions.AI integration.
Includes predefined constants in ImageConfigValues for common values while keeping the API flexible for custom inputs.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.