Skip to content

feat: 添加SiliconFlow图像生成接口自动转换支持 - #2036

Merged
seefs001 merged 2 commits into
QuantumNous:mainfrom
etnAtker:siliconflow-images-generations
Oct 14, 2025
Merged

feat: 添加SiliconFlow图像生成接口自动转换支持#2036
seefs001 merged 2 commits into
QuantumNous:mainfrom
etnAtker:siliconflow-images-generations

Conversation

@etnAtker

@etnAtker etnAtker commented Oct 13, 2025

Copy link
Copy Markdown
Contributor
  1. 将对SiliconFlow渠道的RelayModeImagesGenerations请求,转发至v1/images/generations端点。
  2. SiliconFlow图像生成接口额外参数适配。

Summary by CodeRabbit

  • New Features

    • Added image generation support via the SiliconFlow channel with options for model selection, prompt/negative prompt, image size, batch size, seed, inference steps, and guidance settings.
    • Enabled compatibility with the images/generations API route to streamline image creation workflows.
  • Chores

    • Improved request parsing with sensible fallbacks for size and batch settings and enhanced response handling to preserve stream vs non-stream behavior.

1. 将对SiliconFlow渠道的RelayModeImagesGenerations请求,转发至v1/images/generations端点。
2. SiliconFlow图像生成接口额外参数适配。
@coderabbitai

coderabbitai Bot commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new SFImageRequest DTO and updates the SiliconFlow adaptor to parse image-generation Extra payloads into SFImageRequest (with fallbacks for image_size and batch_size), map RelayModeImagesGenerations to /v1/images/generations, and include that mode in response handling.

Changes

Cohort / File(s) Summary
SiliconFlow adaptor logic
relay/channel/siliconflow/adaptor.go
Added import. ConvertImageRequest now parses request.Extra into SFImageRequest (falling back to empty on parse failure), preserves Model and Prompt, and sets ImageSize (fallback to request.Size) and BatchSize (fallback to request.N). GetRequestURL now maps RelayModeImagesGenerations/v1/images/generations. DoResponse extended to include RelayModeImagesGenerations in its handling flow.
DTOs
relay/channel/siliconflow/dto.go
Added exported struct SFImageRequest with fields: Model, Prompt, NegativePrompt, ImageSize, BatchSize, Seed, NumInferenceSteps, GuidanceScale, Cfg, Image, Image2, Image3 (JSON tags, many omitempty).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client
    participant Adaptor as SiliconFlowAdaptor
    participant API as SiliconFlow API

    Note over Client,Adaptor: Client issues image generation request (may include Extra)

    Client->>Adaptor: ConvertImageRequest(request)
    Adaptor->>Adaptor: try unmarshal request.Extra → SFImageRequest
    alt unmarshal fails
        Adaptor->>Adaptor: use empty SFImageRequest
    end
    Adaptor->>Adaptor: set Model, Prompt
    Adaptor->>Adaptor: set ImageSize (sf.ImageSize or request.Size)
    Adaptor->>Adaptor: set BatchSize (sf.BatchSize or request.N)
    Adaptor-->>Client: SFImageRequest payload

    Note over Client,Adaptor: Resolve endpoint
    Client->>Adaptor: GetRequestURL(RelayModeImagesGenerations)
    Adaptor-->>Client: /v1/images/generations

    Client->>API: POST /v1/images/generations with SFImageRequest
    API-->>Client: response (stream or non-stream)
    Client->>Adaptor: DoResponse(mode, response)
    alt mode == RelayModeImagesGenerations
        Adaptor->>Adaptor: fallthrough to existing image response handling (stream/non-stream)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble prompts in moonlit rows,
Extra bytes become image bows.
Sizes set and batches queued,
Silicon carrots neatly strewed.
Hop—/v1/images blooms in sight,
Pixels wink in rabbit light. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly specifies that this pull request adds support for automatic conversion of the SiliconFlow image generation interface, which directly reflects the changes in request parsing, endpoint mapping, and DTO additions. It is concise, descriptive, and uses the conventional commit style to highlight the feature addition. Any teammate scanning the PR list would understand that the primary purpose is to enable SiliconFlow image generation conversions. There are no unrelated terms or overly generic wording that obscure the main change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3172c95 and fdbc31e.

📒 Files selected for processing (1)
  • relay/channel/siliconflow/adaptor.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • relay/channel/siliconflow/adaptor.go

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: 2

🧹 Nitpick comments (1)
relay/channel/siliconflow/dto.go (1)

29-31: Consider documenting the Image fields.

The field names Image, Image2, and Image3 are unconventional for image-to-image generation. Typically, you'd see names like InitImage, MaskImage, or an array of images. While this might match SiliconFlow's actual API design, consider adding documentation comments to clarify what each field represents and when they should be used.

Example:

	Image  string `json:"image,omitempty"`   // Base image for image-to-image generation
	Image2 string `json:"image2,omitempty"`  // Secondary reference image
	Image3 string `json:"image3,omitempty"`  // Tertiary reference image
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fc9152 and 3172c95.

📒 Files selected for processing (2)
  • relay/channel/siliconflow/adaptor.go (3 hunks)
  • relay/channel/siliconflow/dto.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
relay/channel/siliconflow/adaptor.go (3)
common/json.go (2)
  • Marshal (20-22)
  • Unmarshal (8-10)
relay/channel/siliconflow/dto.go (1)
  • SFImageRequest (19-32)
relay/constant/relay_mode.go (1)
  • RelayModeImagesGenerations (14-14)
🔇 Additional comments (2)
relay/channel/siliconflow/dto.go (1)

27-28: Keep both GuidanceScale and Cfg fields—they map to distinct SiliconFlow API parameters (guidance_scale for prompt adherence and cfg for classifier-free guidance).

relay/channel/siliconflow/adaptor.go (1)

47-48: Confirm intentional overwriting of Model and Prompt
Unmarshaling request.Extra into SFImageRequest may populate Model/Prompt, but lines 47–48 then unconditionally overwrite them with request.Model/request.Prompt, discarding any values from Extra. Confirm this is intended.

Comment thread relay/channel/siliconflow/adaptor.go Outdated
Comment thread relay/channel/siliconflow/adaptor.go
1. 解析ImageRequest的Extra时,处理err
2. DoResponse方法添加RelayModeImagesGenerations(fallthrough)
@seefs001
seefs001 merged commit fa21599 into QuantumNous:main Oct 14, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…generations

feat: 添加SiliconFlow图像生成接口自动转换支持
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.

2 participants