Skip to content

增加MiniMax海螺模型生图功能 - #2591

Closed
feitianbubu wants to merge 4947 commits into
QuantumNous:mainfrom
feitianbubu:pr/6e9cdf62480ec6032bb440b36eb4873bd740bf9d
Closed

增加MiniMax海螺模型生图功能#2591
feitianbubu wants to merge 4947 commits into
QuantumNous:mainfrom
feitianbubu:pr/6e9cdf62480ec6032bb440b36eb4873bd740bf9d

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jan 6, 2026

Copy link
Copy Markdown
Member

官方文档: https://platform.minimaxi.com/docs/api-reference/image-generation-i2i
支持模型: image-01, image-01-live
支持格式: openai的图片生成和图片编辑接口
请求示例:

curl http://localhost:30001/v1/images/generations \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "image-01-live",
  "prompt": "可爱的中国小女孩在花园里玩耍"
}'
image

Summary by CodeRabbit

  • New Features
    • Added image generation and editing support to the relay channel
    • Introduced two new image models: "image-01" and "image-01-live"
    • Enhanced image request handling with styling, dimensions, and subject reference capabilities
    • Improved response processing for image operations with metadata tracking

✏️ Tip: You can customize this high-level summary in your review settings.

Calcium-Ion and others added 30 commits November 23, 2025 23:51
Previously thoughtSignature was only attached to messages with function
calls. This change extends the feature to also attach thoughtSignature
to the first text part of assistant/model messages when no tool_calls
are present, ensuring compatibility with Gemini thinking models in
regular conversation scenarios.
fix: cast size to int64 before comparing with MaxUint32
fix: root page does not have analytic code
…ini-integration-011nJGemhrPUdqwg3qDvmqVB

feat: enable thoughtSignature for non-function-call messages
…pro-image-preview-oai

OAI生图接口支持gemini 3 pro image preview
…ageConfig

fix: gemini image correct generationConfig
…ith i18n

- Add SSEViewer component for interactive SSE message inspection
  * Display SSE data stream with collapsible panels
  * Show parsed JSON with syntax highlighting
  * Display key information badges (content, tokens, finish reason)
  * Support copy individual or all SSE messages
  * Show error messages with detailed information

- Support Ctrl+V to paste images in chat input
  * Enable image paste in CustomInputRender component
  * Auto-detect and add pasted images to image list
  * Show toast notifications for paste results

- Add complete i18n support for 6 languages
  * Chinese (zh): Complete translations
  * English (en): Complete translations
  * Japanese (ja): Add 28 new translations
  * French (fr): Add 28 new translations
  * Russian (ru): Add 28 new translations
  * Vietnamese (vi): Add 32 new translations

- Update .gitignore to exclude data directory
…-i2v

Gemini Veo3.1[AI Studio]增加图生视频支持
Ensure image file is closed using defer after opening.
…edit

Gemini Image系列支持图像编辑
seefs001 and others added 26 commits January 3, 2026 09:36
…rim_suffix, ensure_prefix, ensure_suffix, trim_space, to_lower, to_upper, replace, and regex_replace
移除gorm:"default:false",避免每次 AutoMigrate时都执行ALTER TABLE `tokens` MODIFY COLUMN `cross_group_retry` boolean DEFAULT false
且bool默认false不影响原有功能
* feat: add support for Doubao /v1/responses
…curity-check

feat: check-in feature integrates Turnstile security check
…QuantumNous#2556)

* fix: fix model deployment style issues, lint problems, and i18n gaps.

* fix: adjust the key not to be displayed on the frontend, tested via the backend.

* fix: adjust the sidebar configuration logic to use the default configuration items if they are not defined.
fix: 修复 gemini 文件类型不支持 image/jpg
…figuration && the AWS calling side did not apply the relay timeout.
fix: fix the proxyURL is empty, not using the default HTTP client configuration && the AWS calling side did not apply the relay timeout.
fix: add tips for model management and channel testing
问题描述:
- 使用 auto 分组的令牌调用 /v1/videos 等 Task 接口时,虽然任务能成功创建,
  但使用日志不显示记录,且不会扣费

根本原因:
- Distribute 中间件在选择渠道后,会将实际选中的分组存储在 ContextKeyAutoGroup 中
- 但 RelayTaskSubmit 函数没有从 context 中读取这个值来更新 info.UsingGroup
- 导致 info.UsingGroup 始终是 "auto" 而不是实际选中的分组(如 "sora2逆")
- 当 auto 分组的倍率配置为 0 时,quota 计算结果为 0
- 日志记录条件 "if quota != 0" 不满足,导致日志不记录、不扣费

修复方案:
- 在 RelayTaskSubmit 函数中计算分组倍率之前,添加从 ContextKeyAutoGroup
  获取实际分组的逻辑
- 使用安全的类型断言,避免潜在的 panic 风险

影响范围:
- 仅影响 Task Relay 流程(/v1/videos, /suno, /kling 等接口)
- 不影响使用具体分组令牌的调用
- 不影响其他 Relay 类型(chat/completions 等已有类似处理逻辑)
…task-logging

fix(task): 修复使用 auto 分组时 Task Relay 不记录日志和不扣费的问题
@coderabbitai

coderabbitai Bot commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds image generation and editing support to the Minimax relay channel. It introduces new DTOs for image operations, implements conversion functions from OpenAI format to Minimax format, adds image endpoint routing, and updates the adaptor with conditional image handling logic. Two new Minimax image models are registered.

Changes

Cohort / File(s) Summary
Core DTO and Type Support
dto/values.go, relay/channel/minimax/dto_image.go
Adds IntValue type with custom JSON marshalling for flexible numeric/string handling; introduces six new image DTO types (ImageGenerationRequest, ImageDataObject, ImageGenerationResponse, ImageSubjectReference, StyleObject, ImageGenerationMetadata) for structured image generation workflows.
Image Operations Implementation
relay/channel/minimax/image.go
New file with four image handling functions: oaiImageToHailuoImageRequest converts OpenAI-style requests to Minimax format, imageEditFromOai adds subject references from base64 images, imageHandler processes HTTP responses with error handling and usage tracking, responseToOpenAIImage formats responses back to OpenAI format.
Channel Configuration
relay/channel/minimax/constants.go
Extends ModelList with two new image models: "image-01" and "image-01-live".
Request/Response Routing
relay/channel/minimax/adaptor.go, relay/channel/minimax/relay-minimax.go
Updates adaptor to handle ImagesGenerations and ImagesEdits modes: routes to image conversion functions, adds Content-Type/Accept headers, delegates to imageHandler for responses. Adds endpoint routing for image operations in GetRequestURL. Changes import alias from constant to relayconstant throughout.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Adaptor
    participant ImageHandler
    participant Minimax API
    participant ResponseProcessor
    
    Client->>Adaptor: POST (Images request, RelayMode=ImagesGenerations/ImagesEdits)
    
    rect rgb(230, 245, 245)
        Note over Adaptor: ConvertImageRequest
        alt Edits Mode
            Adaptor->>Adaptor: imageEditFromOai() - extract form base64 images
        else GenerationMode
            Adaptor->>Adaptor: oaiImageToHailuoImageRequest() - convert OpenAI format
        end
        Adaptor->>Adaptor: SetupRequestHeader - add Content-Type, Accept
    end
    
    Adaptor->>Minimax API: POST /v1/image_generation (converted request)
    Minimax API-->>ImageHandler: HTTP response (status + body)
    
    rect rgb(240, 250, 240)
        Note over ImageHandler: imageHandler processing
        ImageHandler->>ImageHandler: Read & validate response body
        ImageHandler->>ImageHandler: Unmarshal to ImageGenerationResponse
        ImageHandler->>ResponseProcessor: responseToOpenAIImage()
        ResponseProcessor->>ResponseProcessor: Build ImageResponse with metadata
        ResponseProcessor->>ResponseProcessor: Map URLs and base64 variants
        alt Multiple images generated
            ResponseProcessor->>ImageHandler: Update usage pricing
        end
    end
    
    ImageHandler-->>Client: JSON (OpenAI-format ImageResponse)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024
  • seefs001
  • Calcium-Ion

Poem

🐰 A nimble hop through image dreams,
New DTOs and JSON streams,
From OpenAI's form to Minimax's call,
The adaptor routes them through it all!
With headers set and handlers tight,
Image magic, pure delight!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title is in Chinese and translates to 'Add MiniMax Hailuo model image generation capability', which directly matches the main objective of adding image-generation support for MiniMax models.
✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
dto/values.go (1)

10-26: Consider handling JSON null values explicitly.

The current implementation will fail if the JSON value is null - it will try to unmarshal as int (fail), then as string (succeed with empty string), then strconv.Atoi("") will return an error. If null is a valid input for optional fields like Seed, you may want to handle it gracefully.

🔎 Proposed fix to handle null values
 func (i *IntValue) UnmarshalJSON(b []byte) error {
+	if string(b) == "null" {
+		return nil
+	}
 	var n int
 	if err := json.Unmarshal(b, &n); err == nil {
 		*i = IntValue(n)
 		return nil
 	}
relay/channel/minimax/image.go (3)

25-28: Silently ignoring marshal/unmarshal errors may hide issues.

The Extra field processing ignores both json.Marshal and json.Unmarshal errors. While this is likely intentional for optional fields, consider logging a warning if unmarshalling fails, as it could indicate malformed input.


114-114: Debug logging may include large base64 payloads.

Logging the full originBody at debug level could result in very large log entries when base64-encoded images are included. Consider truncating or summarizing the response for debug purposes.


51-56: Consider accepting subject reference type from request parameters for flexibility.

The Type field is hardcoded to "character". While this matches the standard use case documented in the MiniMax API, accepting the type from request parameters (if available) would allow for potential future extensibility and make the implementation more flexible.

relay/channel/minimax/dto_image.go (1)

8-21: Consider using pointer types for optional numeric fields.

Width, Height, and N are non-pointer dto.IntValue types. With omitempty, Go's JSON encoder only omits the field if the value is the zero value. However, since IntValue is an int, the zero value 0 will be omitted. If 0 is a valid value the user might want to send, this could cause issues.

For fields where 0 might be meaningful or where explicit omission is important, consider using *dto.IntValue (like Seed).

🔎 Proposed change for consistency
-	Width            dto.IntValue            `json:"width,omitempty"`
-	Height           dto.IntValue            `json:"height,omitempty"`
+	Width            *dto.IntValue           `json:"width,omitempty"`
+	Height           *dto.IntValue           `json:"height,omitempty"`
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 022fbce and c99ac24.

📒 Files selected for processing (6)
  • dto/values.go
  • relay/channel/minimax/adaptor.go
  • relay/channel/minimax/constants.go
  • relay/channel/minimax/dto_image.go
  • relay/channel/minimax/image.go
  • relay/channel/minimax/relay-minimax.go
🧰 Additional context used
🧬 Code graph analysis (5)
relay/channel/minimax/relay-minimax.go (1)
relay/constant/relay_mode.go (2)
  • RelayModeImagesGenerations (14-14)
  • RelayModeImagesEdits (15-15)
relay/channel/minimax/adaptor.go (2)
relay/constant/relay_mode.go (3)
  • RelayModeAudioSpeech (35-35)
  • RelayModeImagesEdits (15-15)
  • RelayModeImagesGenerations (14-14)
types/set.go (1)
  • Set (3-5)
relay/channel/minimax/dto_image.go (2)
dto/values.go (1)
  • IntValue (8-8)
relay/channel/task/hailuo/models.go (2)
  • SubjectReference (3-6)
  • BaseResp (27-30)
dto/values.go (1)
common/json.go (2)
  • Unmarshal (9-11)
  • Marshal (21-23)
relay/channel/minimax/image.go (4)
relay/channel/minimax/dto_image.go (4)
  • ImageGenerationRequest (8-21)
  • StyleObject (28-31)
  • ImageSubjectReference (23-26)
  • ImageGenerationResponse (33-38)
relay/channel/task/hailuo/models.go (2)
  • SubjectReference (3-6)
  • BaseResp (27-30)
relay/channel/task/hailuo/constants.go (1)
  • StatusSuccess (25-25)
dto/openai_image.go (1)
  • ImageData (174-178)
🔇 Additional comments (9)
relay/channel/minimax/constants.go (1)

17-18: LGTM!

The new image model entries follow the existing naming convention and align with the PR objectives for MiniMax image generation support.

relay/channel/minimax/relay-minimax.go (1)

22-23: LGTM!

The new image generation and edit modes correctly route to the /v1/image_generation endpoint, following the existing switch-case pattern for other relay modes.

relay/channel/minimax/adaptor.go (3)

77-82: LGTM!

The branching logic correctly differentiates between image edit and generation modes, routing to the appropriate handler functions.


94-97: LGTM!

Setting explicit Content-Type and Accept headers for image modes ensures proper JSON communication with the MiniMax API.


124-135: LGTM!

The response routing correctly handles audio, image generation, and image edit modes, with a fallback to the OpenAI adaptor for other cases.

relay/channel/minimax/image.go (2)

60-65: Verify graceful close behavior after ReadAll.

CloseResponseBodyGracefully is called after io.ReadAll. Since ReadAll consumes the entire body, the close should work correctly, but ensure that CloseResponseBodyGracefully handles already-consumed bodies gracefully.


101-112: No duplicate entries are possible with MiniMax's API design.

The MiniMax image generation API uses the response_format parameter to control the response format, which can be either "url" or "base64"—not both. When response_format: "url" is used, only ImageUrls is populated; when response_format: "base64" is used, only ImageBase64 is populated. The two formats are mutually exclusive at the API level, so the code cannot produce duplicate entries. The defensive iteration over both fields is safe and reasonable for robustness, but a single field will always be empty in any given response.

Likely an incorrect or invalid review comment.

relay/channel/minimax/dto_image.go (2)

23-26: LGTM!

The ImageSubjectReference struct correctly models the subject reference with type and image file fields matching the MiniMax API requirements.


33-43: LGTM!

The response structures properly model the MiniMax API response, reusing BaseResp for consistent error handling and separating image data into URLs and base64 formats.

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.