Skip to content

新增阿里万相wan2.7系列视频模型支持 - #4078

Open
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/3313091f43f2b877b4de3b313767c7d304d6d289
Open

新增阿里万相wan2.7系列视频模型支持#4078
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/3313091f43f2b877b4de3b313767c7d304d6d289

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Apr 3, 2026

Copy link
Copy Markdown
Member

文档: https://www.alibabacloud.com/help/zh/model-studio/image-to-video-general-api-reference?spm=a2c63.p38356.help-menu-2400256.d_2_3_0.4a8759eeWDgo3l
支持模型: wan2.7-t2v, wan2.7-r2v, wan2.7-videoedit, wan2.7-i2v
调用接口: v1/videos

Summary by CodeRabbit

  • New Features
    • Added support for new video generation models (wan2.7 variants)
    • Enabled reference video URLs and voice input capabilities for video generation workflows
    • Introduced ratio and audio setting parameters for enhanced customization options
    • Improved billing metrics with detailed usage tracking including video duration and size information

@coderabbitai

coderabbitai Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Extended Alibaba video adaptor to support wan2.7 models by adding new type fields (AliVideoMedia, ReferenceVideoURLs, ReferenceVoice), new model identifiers, extended parameter support (Ratio, AudioSetting), and updated usage/metadata tracking with new dimensions.

Changes

Cohort / File(s) Summary
Model Constants
relay/channel/task/ali/constants.go
Added four new wan2.7 model identifiers: wan2.7-t2v, wan2.7-i2v, wan2.7-r2v, wan2.7-videoedit.
Adaptor Types & Logic
relay/channel/task/ali/adaptor.go
Added AliVideoMedia type and extended AliVideoInput, AliVideoParameters, AliUsage, and AliMetadata types with wan2.6/2.7 fields (ReferenceVideoURLs, Media, ReferenceVoice, Ratio, AudioSetting). Updated request conversion to omit ImgURL from input reference, removed asterisk validation for Size, and adjusted default resolution logic for wan2.7 models. Expanded ProcessAliOtherRatios with new ratio mappings for wan2.7 models.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion
  • creamlike1024

Poem

🐰 Whiskers twitch with glee,
wan2.7 models dance so free,
New fields sprouting left and right,
Video magic, ratio's bright!
Adapter grows with video's flight! 🎬✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main change: adding support for Alibaba Wanxiang wan2.7 series video models.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@relay/channel/task/ali/adaptor.go`:
- Around line 44-53: The AliVideoInput.Media field is defined but never
populated and Parameters.Resolution is omitted for wan2.7 models, causing
ProcessAliOtherRatios to see an invalid resolution ("P") and skip the resolution
multiplier; update convertToAliRequest to (1) populate AliVideoInput.Media
(using the AliVideoMedia struct) from normalized image inputs (map
TaskSubmitReq.Images / InputReference / req.Images for wan2.7-i2v into Media
entries) and (2) set Parameters.Resolution for wan2.7 models to a concrete value
(e.g., model default or derived from request metadata) using canonical tokens
like "720P"/"1080P" so ProcessAliOtherRatios can match keys correctly. Ensure
the mapping logic targets the convertToAliRequest code path and produces Media
entries and a non-empty Resolution string before billing estimation.
- Around line 321-323: The wan2.7 branch currently leaves req.Size and
req.Resolution empty and checks req.Model, causing ProcessAliOtherRatios to skip
adding a resolution multiplier and undercharging; update the branch to inspect
aliReq.Model (the mapped upstream model) and explicitly set req.Size and/or
req.Resolution defaults for wan2.7 variants (e.g., set Resolution to "1080P" for
"wan2.7-i2v" per Ali docs) before EstimateBilling/ProcessAliOtherRatios runs so
the resolution multiplier is applied correctly.
🪄 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: 8a9e4f18-bc5f-4b44-91e7-f23daf8332e7

📥 Commits

Reviewing files that changed from the base of the PR and between bb5b9ea and 3b649fd.

📒 Files selected for processing (2)
  • relay/channel/task/ali/adaptor.go
  • relay/channel/task/ali/constants.go

Comment on lines +44 to +53
Prompt string `json:"prompt,omitempty"` // 文本提示词
NegativePrompt string `json:"negative_prompt,omitempty"` // 反向提示词
ImgURL string `json:"img_url,omitempty"` // 首帧图像URL或Base64(图生视频,wan2.6及更早)
FirstFrameURL string `json:"first_frame_url,omitempty"` // 首帧图片URL(首尾帧生视频,wan2.6及更早)
LastFrameURL string `json:"last_frame_url,omitempty"` // 尾帧图片URL(首尾帧生视频,wan2.6及更早)
AudioURL string `json:"audio_url,omitempty"` // 音频URL(wan2.5/2.6)
Template string `json:"template,omitempty"` // 视频特效模板
ReferenceVideoURLs []string `json:"reference_video_urls,omitempty"` // 参考视频URL数组(wan2.6-r2v)
Media []AliVideoMedia `json:"media,omitempty"` // 媒体数组(wan2.7 i2v/r2v/videoedit 新格式)
ReferenceVoice string `json:"reference_voice,omitempty"` // 参考声音URL(wan2.7-r2v)

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Find the specific file and understand its structure
find . -path "*/relay/channel/task/ali/adaptor.go" -type f

Repository: QuantumNous/new-api

Length of output: 98


🏁 Script executed:

# Get the full content of the file to see convertToAliRequest implementation
wc -l relay/channel/task/ali/adaptor.go

Repository: QuantumNous/new-api

Length of output: 100


🏁 Script executed:

# Read the entire adaptor.go file to analyze convertToAliRequest
cat -n relay/channel/task/ali/adaptor.go

Repository: QuantumNous/new-api

Length of output: 21718


🏁 Script executed:

# Check the relay_utils.go for the normalization logic mentioned
find . -path "*/relay/common/relay_utils.go" -type f -exec wc -l {} \;

Repository: QuantumNous/new-api

Length of output: 96


🏁 Script executed:

# Read the specific lines in relay_utils.go (around 140-142)
sed -n '130,150p' relay/common/relay_utils.go

Repository: QuantumNous/new-api

Length of output: 570


🏁 Script executed:

# Check what happens in ProcessAliOtherRatios when Resolution is empty for wan2.7
sed -n '268,289p' relay/channel/task/ali/adaptor.go

Repository: QuantumNous/new-api

Length of output: 621


🏁 Script executed:

# Verify wan2.7 model detection and resolution handling
sed -n '321,343p' relay/channel/task/ali/adaptor.go

Repository: QuantumNous/new-api

Length of output: 948


🏁 Script executed:

# Check if there are any tests or examples showing how media should be provided
find . -name "*.go" -type f | xargs grep -l "AliVideoMedia\|Media.*wan2.7" | head -5

Repository: QuantumNous/new-api

Length of output: 98


🏁 Script executed:

# Check if there are any existing references to wan2.7-i2v media requirements in code/comments
rg "wan2.7-i2v|media.*required" relay/channel/task/ali/ -A 2 -B 2

Repository: QuantumNous/new-api

Length of output: 682


🏁 Script executed:

# Look for any task relay tests or examples
find . -path "*task*ali*" -name "*.go" -type f | xargs grep -l "test\|Test" | head -3

Repository: QuantumNous/new-api

Length of output: 45


🏁 Script executed:

# Check the standard image relay to see if it provides any context
find . -path "*relay/channel/ali*" -name "*.go" -type f | head -5

Repository: QuantumNous/new-api

Length of output: 215


🏁 Script executed:

# Check the standard image relay to see how it handles similar fields
cat -n relay/channel/ali/image.go | head -100

Repository: QuantumNous/new-api

Length of output: 3329


🏁 Script executed:

# Look for any documentation or API references in comments
rg "alibabacloud|alibaba.*api|input.media" relay/channel/task/ali/ -B 3 -A 3

Repository: QuantumNous/new-api

Length of output: 45


🏁 Script executed:

# Verify if empty string resolution causes ProcessAliOtherRatios to fail
# by checking what "P" resolution would match
sed -n '213,267p' relay/channel/task/ali/adaptor.go | grep -E "\"P\"|\".*P\""

Repository: QuantumNous/new-api

Length of output: 533


🏁 Script executed:

# Verify what happens when resolution becomes just "P" in ProcessAliOtherRatios
# Check if "P" exists as a key in aliRatios
sed -n '215,267p' relay/channel/task/ali/adaptor.go | grep -E '"\w*P"' | cut -d'"' -f2 | sort -u

Repository: QuantumNous/new-api

Length of output: 78


🏁 Script executed:

# Check the actual behavior: trace through wan2.7-i2v with empty resolution
python3 << 'EOF'
# Simulate ProcessAliOtherRatios logic
aliRatios = {
    "wan2.7-i2v": {
        "720P": 1,
        "1080P": 1 / 0.6,
    }
}

# When resolution is empty
resolution = ""  # After strings.ToUpper("") 

# Then append "P"
if not resolution.endswith("P"):
    resolution = resolution + "P"

print(f"Resolution after processing: '{resolution}'")

# Try lookup
model = "wan2.7-i2v"
if model in aliRatios:
    if resolution in aliRatios[model]:
        print(f"Found ratio for {resolution}")
    else:
        print(f"NO ratio found. Available keys: {list(aliRatios[model].keys())}")
else:
    print("Model not found in aliRatios")
EOF

Repository: QuantumNous/new-api

Length of output: 145


🏁 Script executed:

# Check if there's any test or documentation about media field requirement
rg "media.*require|input.*media" relay/channel/task/ali/ --type go

Repository: QuantumNous/new-api

Length of output: 45


🏁 Script executed:

# Check if there are any comments or documentation about wan2.7 API requirements
rg "wan2.7.*i2v|input.*media.*required" relay/channel/task/ -B 2 -A 2

Repository: QuantumNous/new-api

Length of output: 1257


🏁 Script executed:

# Search for any examples of how media should be populated
rg "Media.*\[\]|media.*URL" relay/channel/task/ali/ -B 1 -A 1

Repository: QuantumNous/new-api

Length of output: 875


🏁 Script executed:

# Check if there's fallback logic or server-side defaults mentioned
rg "服务端默认|server.*default|fallback" relay/channel/task/ali/adaptor.go -B 2 -A 2

Repository: QuantumNous/new-api

Length of output: 299


Wire new media and resolution fields into request construction for wan2.7 models.

The AliVideoInput.Media field (line 52) is defined for wan2.7 but never populated from TaskSubmitReq.Image/Images/InputReference. Additionally, convertToAliRequest intentionally skips setting Parameters.Resolution for wan2.7 models (lines 321-323), which breaks the billing multiplier calculation in ProcessAliOtherRatios: an empty resolution becomes the string "P" (line 278), which fails to match valid keys like "720P" or "1080P", so the resolution ratio multiplier is never added to otherRatios.

For wan2.7-i2v, map normalized inputs (req.Images from InputReference, per relay/common/relay_utils.go:140-142) into Media array elements. For resolution, either explicitly set it based on model defaults or ensure server-side defaults are accounted for in billing estimation. Currently, callers must handcraft metadata.media and metadata.resolution to work around these gaps.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@relay/channel/task/ali/adaptor.go` around lines 44 - 53, The
AliVideoInput.Media field is defined but never populated and
Parameters.Resolution is omitted for wan2.7 models, causing
ProcessAliOtherRatios to see an invalid resolution ("P") and skip the resolution
multiplier; update convertToAliRequest to (1) populate AliVideoInput.Media
(using the AliVideoMedia struct) from normalized image inputs (map
TaskSubmitReq.Images / InputReference / req.Images for wan2.7-i2v into Media
entries) and (2) set Parameters.Resolution for wan2.7 models to a concrete value
(e.g., model default or derived from request metadata) using canonical tokens
like "720P"/"1080P" so ProcessAliOtherRatios can match keys correctly. Ensure
the mapping logic targets the convertToAliRequest code path and produces Media
entries and a non-empty Resolution string before billing estimation.

Comment on lines +321 to +323
if strings.HasPrefix(req.Model, "wan2.7") {
// wan2.7 服务端有默认值(resolution=720P, ratio=16:9),不设则用服务端默认
} else if strings.Contains(req.Model, "t2v") { // image to video

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the file structure and locate the adaptor.go file
find . -name "adaptor.go" -path "*/task/ali/*" -type f

Repository: QuantumNous/new-api

Length of output: 98


🏁 Script executed:

# Read the adaptor.go file to see lines around 321-323
cat -n relay/channel/task/ali/adaptor.go | sed -n '315,330p'

Repository: QuantumNous/new-api

Length of output: 702


🏁 Script executed:

# Search for ProcessAliOtherRatios function to understand how it handles resolution
rg -A 10 "ProcessAliOtherRatios" --type go

Repository: QuantumNous/new-api

Length of output: 1301


🏁 Script executed:

# Search for wan2.7 references in the codebase
rg "wan2\.7" --type go

Repository: QuantumNous/new-api

Length of output: 2168


🏁 Script executed:

# Look for EstimateBilling function
rg -B 3 -A 15 "EstimateBilling" --type go | head -100

Repository: QuantumNous/new-api

Length of output: 5991


🏁 Script executed:

# Check if there's an upstreamModel mapping for wan2.7
rg -B 5 -A 5 "upstreamModel" relay/channel/task/ali/ --type go

Repository: QuantumNous/new-api

Length of output: 1617


🏁 Script executed:

# Get the full ProcessAliOtherRatios function
rg -B 3 -A 50 "func ProcessAliOtherRatios" relay/channel/task/ali/adaptor.go

Repository: QuantumNous/new-api

Length of output: 1033


🏁 Script executed:

# Check how the resolution is obtained in ProcessAliOtherRatios when dealing with empty values
cat -n relay/channel/task/ali/adaptor.go | sed -n '200,280p'

Repository: QuantumNous/new-api

Length of output: 2238


🏁 Script executed:

# Look for EstimateBilling in the ali adaptor
rg -B 5 -A 30 "func.*EstimateBilling" relay/channel/task/ali/adaptor.go

Repository: QuantumNous/new-api

Length of output: 1131


🏁 Script executed:

# Check if there are any model aliases or mappings for wan2.7 variants
rg -B 3 -A 3 "wan2\.7" setting/model_setting/

Repository: QuantumNous/new-api

Length of output: 407


🏁 Script executed:

# Check what happens when aliReq.Parameters.Resolution is empty in ProcessAliOtherRatios
cat -n relay/channel/task/ali/adaptor.go | sed -n '385,450p'

Repository: QuantumNous/new-api

Length of output: 2523


🏁 Script executed:

# Get the complete ProcessAliOtherRatios function
rg -A 100 "func ProcessAliOtherRatios" relay/channel/task/ali/adaptor.go | head -150

Repository: QuantumNous/new-api

Length of output: 2230


🏁 Script executed:

# Check if there's a default resolution or fallback handling when both Size and Resolution are empty
cat -n relay/channel/task/ali/adaptor.go | sed -n '268,320p'

Repository: QuantumNous/new-api

Length of output: 1797


🏁 Script executed:

# Look for model mappings - check if any models map to wan2.7-* variants
rg -r "wan2\.7" setting/ --type go | grep -i map

Repository: QuantumNous/new-api

Length of output: 146


🏁 Script executed:

# Check the full convertToAliRequest to see how req.Model vs upstreamModel is used
rg -B 5 -A 40 "func.*convertToAliRequest" relay/channel/task/ali/adaptor.go

Repository: QuantumNous/new-api

Length of output: 1325


🏁 Script executed:

# Check for model mappings - look for model aliasing configurations
find . -name "*.go" -type f -exec grep -l "IsModelMapped\|UpstreamModelName" {} \; | head -10

Repository: QuantumNous/new-api

Length of output: 2031


🏁 Script executed:

# Look at model_mapping or model settings to understand if wan2.7 variants can be aliased
find . -name "*.json" -o -name "*.go" | xargs grep -l "wan2\.7" | grep -E "(setting|mapping|alias)"

Repository: QuantumNous/new-api

Length of output: 94


🏁 Script executed:

# Check constants.go for model definitions
cat -n relay/channel/task/ali/constants.go | head -50

Repository: QuantumNous/new-api

Length of output: 606


🏁 Script executed:

# Check if there are any model mappings defined for wan2.7 models
rg "wan2\.7" setting/model_mapping/ --type go 2>/dev/null || echo "No mapping files found"

Repository: QuantumNous/new-api

Length of output: 85


🏁 Script executed:

# Look for how model mapping/aliases work
rg -B 3 -A 3 "IsModelMapped" relay/channel/task/ali/adaptor.go

Repository: QuantumNous/new-api

Length of output: 319


🏁 Script executed:

# Check the complete section around lines 319-330 to see all conditional branches
cat -n relay/channel/task/ali/adaptor.go | sed -n '319,350p'

Repository: QuantumNous/new-api

Length of output: 1354


🏁 Script executed:

# Search for any comments or documentation about wan2.7-i2v defaults
rg -B 3 -A 3 "wan2\.7-i2v" relay/channel/task/ali/ --type go

Repository: QuantumNous/new-api

Length of output: 891


🏁 Script executed:

# Check if there's any handling for i2v models specifically
rg "i2v" relay/channel/task/ali/adaptor.go --type go

Repository: QuantumNous/new-api

Length of output: 412


🏁 Script executed:

# Verify the issue: when Resolution is empty, what resolution value gets used in ProcessAliOtherRatios?
cat -n relay/channel/task/ali/adaptor.go | sed -n '268,290p'

Repository: QuantumNous/new-api

Length of output: 783


🌐 Web query:

wan2.7-i2v aliyun model studio image to video default resolution 1080P

💡 Result:

The wan2.7-i2v model is part of Alibaba's Wan 2.7 video generation family, an open-source image-to-video (I2V) model capable of generating 1080p HD videos. While official Alibaba Cloud Model Studio documentation primarily covers wan2.7-image models for image generation/editing (up to 4K), the video models like wan2.6-i2v explicitly support 1080P as the default resolution (options: 720P, 1080P; default: 1080P). Wan 2.7, as the successor, supports 1080P output per third-party hosts like Replicate (default: 1080p) and general descriptions of the series. No official Model Studio API docs for wan2.7-i2v were found (latest listed video models are wan2.6 series), but the pattern holds: default is 1080P.

Citations:


Set explicit resolution defaults for wan2.7 models before billing calculation.

The wan2.7 branch (line 321–322) intentionally leaves Size and Resolution empty, assuming server defaults. However, ProcessAliOtherRatios only applies a resolution multiplier if either Size or Resolution is set; when both are empty, resolution becomes an empty string that doesn't match any key in the pricing ratios map (which only has "720P" and "1080P"), so no resolution multiplier is added to EstimateBilling.

Per Ali API documentation, wan2.7-i2v defaults to 1080P, not 720P. Requests omitting req.Size will be undercharged because no 1080P multiplier (1 / 0.6 ≈ 1.67x) is applied.

Additionally, this branch should check aliReq.Model (the upstream model after mapping) instead of req.Model, so that mapped aliases like "qwen-image-*""wan2.7-i2v" correctly apply their resolution defaults.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@relay/channel/task/ali/adaptor.go` around lines 321 - 323, The wan2.7 branch
currently leaves req.Size and req.Resolution empty and checks req.Model, causing
ProcessAliOtherRatios to skip adding a resolution multiplier and undercharging;
update the branch to inspect aliReq.Model (the mapped upstream model) and
explicitly set req.Size and/or req.Resolution defaults for wan2.7 variants
(e.g., set Resolution to "1080P" for "wan2.7-i2v" per Ali docs) before
EstimateBilling/ProcessAliOtherRatios runs so the resolution multiplier is
applied correctly.

@imlhb

imlhb commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

这个目前可以使用不呢?

@feitianbubu

Copy link
Copy Markdown
Member Author

需要作者合并

JacksonsY added a commit to JacksonsY/new-api that referenced this pull request Jul 19, 2026
移植上游 PR QuantumNous#4810。

- ModelList 补 wan2.7-r2v / wan2.7-videoedit 与 happyhorse 1.0/1.1
- 补齐新版请求字段:reference_video_urls、reference_voice、ratio、
  audio_setting、shot_type,以及 usage 的 size/ratio/输入输出时长
- 新增 multipart.go:把 image_url / video_url / audio_url 表单字段按
  模型映射进 input.media(r2v 与 videoedit 归 reference_image,
  videoedit 的视频归 video,其余归 reference_video)
- 校验入口从 ValidateMultipartDirect 统一为 ValidateBasicTaskRequest,
  后者同样执行 validateTaskDurationBounds 且原生支持 multipart,
  时长上界校验不丢失
- EstimateBilling 保留 min(Duration, MaxTaskDurationSeconds) 钳制

上游 PR QuantumNous#4078(万相 wan2.7)未单独移植:仓库已含 wan2.7-i2v/t2v,其余
内容(四个 wan2.7 模型、ratio/audio_setting、usage 扩展、分辨率倍率)
均为本 PR 的子集;其 AliUsage.Duration 改 float64 的方案也已由 QuantumNous#6174
的 IntValue 饱和解码更完整地覆盖。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
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