Skip to content

Conversation

@bborn
Copy link
Contributor

@bborn bborn commented Jan 23, 2026

Summary

  • Add with_image_config(aspect_ratio:, image_size:) method to Chat class for Gemini's native image generation models
  • Supports aspectRatio values: "1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"
  • Supports imageSize values: "1K", "2K", "4K"

Usage

chat = RubyLLM.chat(model: "gemini-3-pro-image-preview")
  .with_temperature(1.0)
  .with_image_config(aspect_ratio: "16:9", image_size: "2K")

response = chat.ask("Generate a landscape photo of mountains")

Implementation

Uses the existing params deep merge mechanism—no changes to the provider interface required. Snake_case parameters (aspect_ratio) are converted to camelCase (aspectRatio) for the Gemini API.

Test plan

  • Unit tests for #with_image_config method chaining
  • Unit tests for effective_params merging behavior
  • Unit tests verifying payload structure with imageConfig
  • All existing tests pass (444 examples, 0 failures)
  • All pre-commit hooks pass (RuboCop, Flay, RSpec)

🤖 Generated with Claude Code

Add support for Gemini's imageConfig parameter in chat-based image
generation. This allows users to specify aspect_ratio and image_size
when using models like gemini-3-pro-image-preview.

Usage:
  chat = RubyLLM.chat(model: "gemini-3-pro-image-preview")
    .with_temperature(1.0)
    .with_image_config(aspect_ratio: "16:9", image_size: "2K")

The implementation uses the existing params deep merge mechanism,
requiring no changes to the provider interface. Snake_case parameters
are converted to camelCase for the API (aspect_ratio -> aspectRatio).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bborn bborn marked this pull request as draft January 23, 2026 04:19
@bborn bborn marked this pull request as ready for review January 25, 2026 19:07
@bborn bborn marked this pull request as draft January 25, 2026 19:28
@bborn bborn closed this Jan 25, 2026
@bborn
Copy link
Contributor Author

bborn commented Jan 25, 2026

chat.with_params(generationConfig: { imageConfig: { aspectRatio: "16:9", imageSize: "2K" } }) already works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant