feat: 添加SiliconFlow图像生成接口自动转换支持 - #2036
Conversation
1. 将对SiliconFlow渠道的RelayModeImagesGenerations请求,转发至v1/images/generations端点。 2. SiliconFlow图像生成接口额外参数适配。
WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. Comment |
There was a problem hiding this comment.
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, andImage3are unconventional for image-to-image generation. Typically, you'd see names likeInitImage,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
📒 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 bothGuidanceScaleandCfgfields—they map to distinct SiliconFlow API parameters (guidance_scalefor prompt adherence andcfgfor classifier-free guidance).relay/channel/siliconflow/adaptor.go (1)
47-48: Confirm intentional overwriting of Model and Prompt
Unmarshalingrequest.ExtraintoSFImageRequestmay populateModel/Prompt, but lines 47–48 then unconditionally overwrite them withrequest.Model/request.Prompt, discarding any values fromExtra. Confirm this is intended.
1. 解析ImageRequest的Extra时,处理err 2. DoResponse方法添加RelayModeImagesGenerations(fallthrough)
…generations feat: 添加SiliconFlow图像生成接口自动转换支持
Summary by CodeRabbit
New Features
Chores