feat: support Wan2.7 i2v media mapping#4984
Conversation
WalkthroughAdds Wan2.7-i2v image-to-video support to the Ali adaptor: new media schema, normalization that maps task images to media items (first/last frame, driving audio), validation requiring image sources, conversion integration, model registration, and tests plus upstream single-image compatibility. ChangesWan2.7-i2v Image-to-Video Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@relay/channel/task/ali/adaptor.go`:
- Around line 276-287: The helper firstTaskImage currently returns
InputReference before the newer direct-image fields; change its selection order
to prefer req.Image, then the first element of req.Images, and only fall back to
req.InputReference, so direct-image fields win; apply the same ordering change
to the other analogous helper used later (the one with the same logic around the
other task-image extraction) so both places derive img_url/first_frame from
Image/Images first.
In `@relay/common/relay_utils.go`:
- Around line 142-144: The code checks strings.TrimSpace(req.Image) but stores
the raw req.Image, allowing surrounding spaces to propagate; update the branch
that handles single-image compatibility so you store the trimmed value (e.g.,
use the trimmed string of req.Image when assigning to req.Images) — locate the
conditional around req.Images and req.Image in relay_utils.go and replace the
assignment to req.Images with the normalized/trimmed image string.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 32d16b1f-b3a9-456a-96a5-c57880d83d72
📒 Files selected for processing (5)
relay/channel/task/ali/adaptor.gorelay/channel/task/ali/adaptor_test.gorelay/channel/task/ali/constants.gorelay/common/relay_utils.gorelay/common/relay_utils_test.go
| } else if len(req.Images) == 0 && strings.TrimSpace(req.Image) != "" { | ||
| // 兼容单图上传 | ||
| req.Images = []string{req.Image} |
There was a problem hiding this comment.
Trim the normalized image value before storing it.
Line 142 checks strings.TrimSpace(req.Image), but Line 144 stores the raw value. If the input has surrounding spaces, an invalid URL string is propagated.
Suggested patch
} else if len(req.Images) == 0 && strings.TrimSpace(req.Image) != "" {
// 兼容单图上传
- req.Images = []string{req.Image}
+ req.Images = []string{strings.TrimSpace(req.Image)}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| } else if len(req.Images) == 0 && strings.TrimSpace(req.Image) != "" { | |
| // 兼容单图上传 | |
| req.Images = []string{req.Image} | |
| } else if len(req.Images) == 0 && strings.TrimSpace(req.Image) != "" { | |
| // 兼容单图上传 | |
| req.Images = []string{strings.TrimSpace(req.Image)} | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@relay/common/relay_utils.go` around lines 142 - 144, The code checks
strings.TrimSpace(req.Image) but stores the raw req.Image, allowing surrounding
spaces to propagate; update the branch that handles single-image compatibility
so you store the trimmed value (e.g., use the trimmed string of req.Image when
assigning to req.Images) — locate the conditional around req.Images and
req.Image in relay_utils.go and replace the assignment to req.Images with the
normalized/trimmed image string.
e1153ab to
e4cbbde
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
relay/channel/task/ali/adaptor_test.go (1)
18-121: ⚡ Quick winAdd one regression test for mixed-source precedence (
image/images+input_reference).Current cases are solid, but they don’t lock behavior when both legacy and direct image fields are sent together—the exact edge where source selection can drift.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relay/channel/task/ali/adaptor_test.go` around lines 18 - 121, Add a regression test named TestConvertToAliRequestMixedSourcePrecedence in adaptor_test.go that constructs a TaskAdaptor and a relaycommon.TaskSubmitReq for model "wan2.7-i2v" with both Image/Images set and Metadata containing an explicit input.media (or input_reference) entry; call adaptor.convertToAliRequest(testRelayInfo(), req) and assert no error, then assert that aliReq.Input.Media equals the metadata-provided media (not the Image/Images), aliReq.Input.ImgURL is empty, and the marshaled body contains "media" and does not contain "img_url" to lock precedence of explicit metadata over image/images.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@relay/channel/task/ali/adaptor_test.go`:
- Around line 18-121: Add a regression test named
TestConvertToAliRequestMixedSourcePrecedence in adaptor_test.go that constructs
a TaskAdaptor and a relaycommon.TaskSubmitReq for model "wan2.7-i2v" with both
Image/Images set and Metadata containing an explicit input.media (or
input_reference) entry; call adaptor.convertToAliRequest(testRelayInfo(), req)
and assert no error, then assert that aliReq.Input.Media equals the
metadata-provided media (not the Image/Images), aliReq.Input.ImgURL is empty,
and the marshaled body contains "media" and does not contain "img_url" to lock
precedence of explicit metadata over image/images.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 22828849-f2f5-4463-80b4-ed50c1ac891b
📒 Files selected for processing (5)
relay/channel/task/ali/adaptor.gorelay/channel/task/ali/adaptor_test.gorelay/channel/task/ali/constants.gorelay/common/relay_utils.gorelay/common/relay_utils_test.go
e4cbbde to
c19ecd8
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (2)
relay/common/relay_utils.go (1)
142-144:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winTrim the normalized single-image value before storing it.
Line 142 trims for validation, but Line 144 stores the raw string. This can propagate leading/trailing spaces into
req.Images.Suggested patch
- } else if len(req.Images) == 0 && strings.TrimSpace(req.Image) != "" { + } else if len(req.Images) == 0 && strings.TrimSpace(req.Image) != "" { // 兼容单图上传 - req.Images = []string{req.Image} + req.Images = []string{strings.TrimSpace(req.Image)} }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relay/common/relay_utils.go` around lines 142 - 144, The code validates with strings.TrimSpace(req.Image) but then stores the untrimmed value into req.Images, so update the branch that handles single-image compatibility to assign the trimmed value: compute trimmed := strings.TrimSpace(req.Image) (or reuse the trimmed value used for validation) and set req.Images = []string{trimmed} instead of using req.Image; ensure req.Image remains unchanged only if needed elsewhere or optionally overwrite req.Image with the trimmed value for consistency.relay/channel/task/ali/adaptor.go (1)
276-287:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPrefer
image/imagesoverinput_referenceinfirstTaskImage.This still picks
input_referencefirst, so when a request carries both the new direct-image fields and the legacy reference, Wan2.7 media derivation can send the wrong first frame. Because Line 348 reuses this helper, the legacyimg_urlpath inherits the same bug. Reorder the fallback toimage→images[0]→input_reference, and trim whitespace so blank values do not block later candidates.Suggested fix
func firstTaskImage(req relaycommon.TaskSubmitReq) string { - if req.InputReference != "" { - return req.InputReference - } - if req.Image != "" { + if strings.TrimSpace(req.Image) != "" { return req.Image } - if len(req.Images) > 0 { + if len(req.Images) > 0 && strings.TrimSpace(req.Images[0]) != "" { return req.Images[0] } + if strings.TrimSpace(req.InputReference) != "" { + return req.InputReference + } return "" }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relay/channel/task/ali/adaptor.go` around lines 276 - 287, The helper firstTaskImage currently prefers input_reference first and doesn't trim blanks; change its fallback order to prefer req.Image, then req.Images[0], then req.InputReference, and ensure you trim whitespace from each candidate so empty or whitespace-only values don't block later options; update the logic in function firstTaskImage (used elsewhere, e.g., the legacy img_url path) to check strings.TrimSpace(req.Image), iterate images checking strings.TrimSpace on each entry, and finally use strings.TrimSpace(req.InputReference) as the last resort.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@relay/channel/task/ali/adaptor.go`:
- Around line 276-287: The helper firstTaskImage currently prefers
input_reference first and doesn't trim blanks; change its fallback order to
prefer req.Image, then req.Images[0], then req.InputReference, and ensure you
trim whitespace from each candidate so empty or whitespace-only values don't
block later options; update the logic in function firstTaskImage (used
elsewhere, e.g., the legacy img_url path) to check strings.TrimSpace(req.Image),
iterate images checking strings.TrimSpace on each entry, and finally use
strings.TrimSpace(req.InputReference) as the last resort.
In `@relay/common/relay_utils.go`:
- Around line 142-144: The code validates with strings.TrimSpace(req.Image) but
then stores the untrimmed value into req.Images, so update the branch that
handles single-image compatibility to assign the trimmed value: compute trimmed
:= strings.TrimSpace(req.Image) (or reuse the trimmed value used for validation)
and set req.Images = []string{trimmed} instead of using req.Image; ensure
req.Image remains unchanged only if needed elsewhere or optionally overwrite
req.Image with the trimmed value for consistency.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 807d1228-441b-4f1f-a65a-7b8b46fda618
📒 Files selected for processing (5)
relay/channel/task/ali/adaptor.gorelay/channel/task/ali/adaptor_test.gorelay/channel/task/ali/constants.gorelay/common/relay_utils.gorelay/common/relay_utils_test.go
✅ Files skipped from review due to trivial changes (1)
- relay/channel/task/ali/constants.go
Important
📝 变更描述 / Description
本次为 Ali 视频生成渠道补充 Wan2.7 图生视频协议适配。
Wan2.7 I2V 使用的是新的
input.media入参格式,而当前 Ali adaptor 仍主要按旧版img_url/first_frame_url/last_frame_url字段组织请求。这个改动在wan2.7-i2v场景下将通用视频请求里的image、images、input_reference映射为 DashScope 所需的input.media:type: first_framefirst_frame+last_framemetadata.input.media会被保留img_url逻辑同时补充了
wan2.7-i2v、wan2.7-t2v到 Ali task model list,并让 direct video request 路径兼容单图image字段,避免图生视频请求没有被识别为带图任务。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work