fix: add OpenRouter image generation support & fix retry task directory#64
Open
voidborne-d wants to merge 1 commit intoHisMax:mainfrom
Open
fix: add OpenRouter image generation support & fix retry task directory#64voidborne-d wants to merge 1 commit intoHisMax:mainfrom
voidborne-d wants to merge 1 commit intoHisMax:mainfrom
Conversation
- Add modalities and image_config to Chat API request payload for OpenRouter compatibility - Parse OpenRouter's message.images[] array response format (base64 data URLs) - Handle multimodal content parts (list of image_url objects) - Set current_task_dir in retry_failed_images() to fix '任务目录未设置' error Tested with google/gemini-3.1-flash-image-preview via OpenRouter. Backward compatible with existing images/generations endpoint.
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.
Problem
1. OpenRouter API incompatibility (
image_api.py)When using OpenRouter as the image provider with
endpoint_type: chat, the Chat API generator:modalities: ["image", "text"]andimage_configin the request payload, so OpenRouter returns text-only responsesmessage.images[]array format, only looking for images inmessage.content2. Retry fails with "任务目录未设置" (
image.py)retry_failed_images()never setsself.current_task_dirbefore spawning worker threads. When workers call_generate_single_image()→_save_image(), the task directory isNone, causing all retries to fail even though image generation succeeds.Changes
backend/generators/image_api.pymodalities: ["image", "text"]andimage_config(withaspect_ratioandimage_size) to Chat API request payloadmessage.images[]array response format (base64 data URLs)contentas list ofimage_urlobjects)backend/services/image.pyself.current_task_dirat the start ofretry_failed_images(), consistent withgenerate_images()andretry_single_image()OpenRouter Config Example
Testing
google/gemini-3.1-flash-image-previewvia OpenRouterimages/generationsendpoint path still works (no regression)