feat(image generation): Add image generation support for models OpenAI and Google Gemini#1009
Open
usiegj00 wants to merge 1 commit intopatterns-ai-core:mainfrom
Open
feat(image generation): Add image generation support for models OpenAI and Google Gemini#1009usiegj00 wants to merge 1 commit intopatterns-ai-core:mainfrom
usiegj00 wants to merge 1 commit intopatterns-ai-core:mainfrom
Conversation
…tex AI - Add generate_image method to LLM::Base that raises NotImplementedError - Implement generate_image for OpenAI using DALL-E API - Implement generate_image for Google Gemini using generateContent endpoint - Implement generate_image for Google Vertex AI using Imagen model - Add image_urls helper to OpenAIResponse for URL responses - Add image_base64s helper to Google response classes for base64 data - Add comprehensive specs for all implementations - Add example demonstrating unified API across providers Fixes patterns-ai-core#924
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Image Generation Feature Implementation Summary
Overview
This PR adds first-class image generation support to langchainrb, addressing issue #924. The implementation follows existing patterns in the codebase while making image generation a provider-agnostic feature that works seamlessly across OpenAI, Google Gemini, and Google Vertex AI.
Key Design Decisions
1. Provider-Agnostic API
generate_imagemethod toLangchain::LLM::Basethat raisesNotImplementedErrorgenerate_image(prompt:, n: 1, ...)2. Model Configuration via Defaults
@defaultshashimage_generation_modelto DEFAULTS for each provider:"dall-e-3""gemini-2.0-flash-preview-image-generation""imagen-3.0-generate-002"3. Response Handling
image_urlsmethodimage_base64smethodImplementation Details
Files Modified
lib/langchain/llm/base.rb
generate_imagemethod that raisesNotImplementedErrorlib/langchain/llm/openai.rb
generate_imageusing OpenAI's Images APIimage_generation_modelto DEFAULTSlib/langchain/llm/google_gemini.rb
generate_imageusing Gemini's generateContent endpointimage_generation_modelto DEFAULTSlib/langchain/llm/google_vertexai.rb
generate_imageusing Vertex AI's Imagen modelimage_generation_modelto DEFAULTSResponse Classes
lib/langchain/llm/response/openai_response.rb
image_urlsmethod to extract URLs from image generation responseslib/langchain/llm/response/google_gemini_response.rb
image_base64smethod to extract base64 data frominlineData.datafieldlib/langchain/llm/response/google_vertex_ai_response.rb (new file)
image_base64smethodExamples and Tests
examples/generate_image.rb
Test Coverage
Usage Example
Benefits
generate_imagefollowing the same patternFuture Considerations
This implementation provides a solid foundation for image generation in langchainrb while maintaining backward compatibility and following established patterns in the codebase.