Repository navigation
feat(ali): add Happy Horse 1.0 video model support - #4507
wanghualoong wants to merge 3 commits into
Conversation
Add support for Alibaba Cloud Bailian Happy Horse 1.0 video generation models in the ali channel adaptor. Happy Horse uses a different request format (media array) compared to existing Wanxiang models (flat fields). Changes: - Add 4 Happy Horse model IDs to ModelList: t2v, i2v, r2v, video-edit - Add AliMediaItem struct for media array format - Add Media field to AliVideoInput for Happy Horse requests - Add Ratio and AudioSetting fields to AliVideoParameters - Change Watermark from bool to *bool to fix omitempty dropping false (Happy Horse API defaults watermark to true, so false must be sent) - Add convertToHappyHorseRequest method with mode-specific media mapping: - t2v: text-to-video (prompt only) - i2v: first frame image to video (media type: first_frame) - r2v: reference images to video (media type: reference_image, 1-9) - video-edit: video editing (media type: video + reference_image) - Auto-detect Happy Horse models by "happyhorse-1.0" prefix in convertToAliRequest and route to the new method The Watermark *bool change also fixes a latent bug for Wanxiang models where watermark:false was silently dropped by Go's omitempty tag. Co-Authored-By: Claude Opus 4.6 <[email protected]>
WalkthroughAdds Happy Horse video-model support to the Ali channel: new model identifiers, new media-based request types and parameters (media array, ratio, audio_setting, pointer watermark), a new conversion path Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Adaptor as TaskAdaptor
participant Ali as Ali API
Client->>Adaptor: Submit Task (model: happyhorse-1.0-*)
Adaptor->>Adaptor: convertToAliRequest -> detect happyhorse model
Adaptor->>Adaptor: convertToHappyHorseRequest(build Input.Media, set Parameters, validate counts)
Adaptor->>Ali: Send AliVideoRequest (Input.Media, Parameters)
Ali-->>Adaptor: Response
Adaptor-->>Client: Return result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 5
🤖 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 377-390: The payload builder currently appends media without
validating cardinality, causing invalid requests; add explicit pre-checks for
isI2V, isR2V and isEdit before populating aliReq.Input.Media: for isI2V ensure
len(req.Images)==1 and return a clear error if not; for isR2V ensure 1 <=
len(req.Images) <= 9 and return an error if outside that range; for isEdit
ensure len(req.Videos)>=1 (use the first video) and 0 <= len(req.Images) <= 5,
returning errors for violations; implement these checks immediately before the
existing aliReq.Input.Media assignments (referencing isI2V, isR2V, isEdit,
req.Images, req.Videos and aliReq.Input.Media) so the function fails fast with
descriptive messages instead of sending incomplete media arrays.
- Around line 384-385: The code references req.Videos which doesn't exist on
relaycommon.TaskSubmitReq; add a Videos []string field to the TaskSubmitReq
struct and ensure request parsing/population (where TaskSubmitReq is decoded)
fills it from the incoming payload, then update usage in adaptor.go (the block
that appends to aliReq.Input.Media) to safely check len(req.Videos)>0 before
accessing req.Videos[0]; keep the field name exactly Videos and update any
JSON/tag mapping in the request parser so the new field is populated at decode
time.
- Around line 271-273: The routing check currently uses req.Model to detect
Happy Horse mode which fails when model mapping changes it; update the condition
to check upstreamModel instead of req.Model so calls like return
a.convertToHappyHorseRequest(info, upstreamModel, req) use the real provider ID;
make the identical change for the other Happy Horse detection branch (the other
conditional that triggers
convertToHappyHorseResponse/convertToHappyHorseRequest) so all Happy Horse mode
gates use upstreamModel rather than req.Model.
- Around line 56-61: The struct fields Ratio and AudioSetting in adaptor.go are
declared as non-pointer strings but are optional; change their types to *string
(and ensure assignments create string pointers) so omitempty preserves explicit
absence; update any places that construct or copy this DTO (e.g., wherever Ratio
and AudioSetting are set or forwarded) to assign pointer values (using helpers
or &value) and adjust any consumers to handle nil vs non-nil.
- Around line 401-406: The happy-path branch in the non-edit case currently only
checks req.Duration and falls back to 5s, dropping any valid req.Seconds; update
the logic in the block that sets aliReq.Parameters.Duration (inside the if
!isEdit branch) so it first uses req.Duration if >0, otherwise uses req.Seconds
if >0, and only then defaults to 5; modify the assignment around
aliReq.Parameters.Duration to reflect this precedence (referencing isEdit,
req.Duration, req.Seconds, and aliReq.Parameters.Duration).
🪄 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: 5dce1809-decd-4c3d-89b5-95da35cb73c8
📒 Files selected for processing (2)
relay/channel/task/ali/adaptor.gorelay/channel/task/ali/constants.go
| if len(req.Videos) > 0 { | ||
| aliReq.Input.Media = append(aliReq.Input.Media, AliMediaItem{Type: "video", URL: req.Videos[0]}) |
There was a problem hiding this comment.
Compile blocker: TaskSubmitReq has no Videos field.
req.Videos is undefined for relaycommon.TaskSubmitReq, so this package does not compile. Add a Videos []string field (and request parsing support) before using it here.
🧰 Tools
🪛 golangci-lint (2.11.4)
[error] 384-384: : # github.com/QuantumNous/new-api/relay/channel/task/ali
relay/channel/task/ali/adaptor.go:384:14: req.Videos undefined (type "github.com/QuantumNous/new-api/relay/common".TaskSubmitReq has no field or method Videos)
relay/channel/task/ali/adaptor.go:385:89: req.Videos undefined (type "github.com/QuantumNous/new-api/relay/common".TaskSubmitReq has no field or method Videos)
(typecheck)
🤖 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 384 - 385, The code
references req.Videos which doesn't exist on relaycommon.TaskSubmitReq; add a
Videos []string field to the TaskSubmitReq struct and ensure request
parsing/population (where TaskSubmitReq is decoded) fills it from the incoming
payload, then update usage in adaptor.go (the block that appends to
aliReq.Input.Media) to safely check len(req.Videos)>0 before accessing
req.Videos[0]; keep the field name exactly Videos and update any JSON/tag
mapping in the request parser so the new field is populated at decode time.
- Add Videos field to TaskSubmitReq (fixes compile error) - Use upstreamModel instead of req.Model for Happy Horse detection (supports model mapping) - Change Ratio/AudioSetting to *string pointer types for consistent omitempty semantics - Add media cardinality validation: i2v requires 1 image, r2v 1-9, video-edit requires 1 video and at most 5 images - Handle req.Seconds fallback in duration parsing Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
relay/common/relay_info.go (1)
670-682:⚠️ Potential issue | 🟠 Major
Videosis not wired through the task parsing path yet.Adding the field here is only half the change.
validateMultipartTaskRequest()inrelay/common/relay_utils.go:81-118never copiesformData["videos"],isKnownTaskField()inrelay/common/relay_utils.go:184-196still treatsvideosas unknown, andValidateMultipartDirect()inrelay/common/relay_utils.go:121-182derivesactionfromreq.HasImage(), which ignoresVideos. A Happy Horsevideo-editrequest with one video and no reference images can therefore arrive withreq.Videosempty or be classified as a text-only task.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@relay/common/relay_info.go` around lines 670 - 682, TaskSubmitReq.Videos was added but the multipart parsing and validation paths don't handle it; update validateMultipartTaskRequest() to copy formData["videos"] into the TaskSubmitReq, add "videos" to the known fields checked by isKnownTaskField(), and change ValidateMultipartDirect() so action derivation (currently using req.HasImage()) also treats videos—either add a req.HasMedia()/HasVideo() helper or extend HasImage() to consider req.Videos so video-edit tasks with only videos are classified and populated correctly.
♻️ Duplicate comments (1)
relay/channel/task/ali/adaptor.go (1)
389-396:⚠️ Potential issue | 🟠 MajorReject multiple videos for
happyhorse-1.0-video-edit.This path still accepts
len(req.Videos) > 1and silently discardsreq.Videos[1:]by only forwarding the first entry. The contract in this PR is exactly 1 video, so malformed requests should fail fast instead of using the wrong source asset.♻️ Proposed fix
} else if isEdit { - if len(req.Videos) < 1 { - return nil, fmt.Errorf("happyhorse video-edit requires exactly 1 video") + if len(req.Videos) != 1 { + return nil, fmt.Errorf("happyhorse video-edit requires exactly 1 video, got %d", len(req.Videos)) } if len(req.Images) > 5 { return nil, fmt.Errorf("happyhorse video-edit supports at most 5 reference images, got %d", len(req.Images)) } aliReq.Input.Media = append(aliReq.Input.Media, AliMediaItem{Type: "video", URL: req.Videos[0]})🤖 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 389 - 396, The edit branch for happyhorse-1.0-video-edit currently only checks for len(req.Videos) < 1 but then quietly drops extra videos; update the isEdit handling so it enforces exactly one video by returning an error when len(req.Videos) != 1 (use the same error style/format as other checks), leaving the existing aliReq.Input.Media append of req.Videos[0] unchanged; make the check adjacent to the isEdit branch (referencing isEdit, req.Videos, and aliReq.Input.Media) so malformed requests fail fast instead of silently discarding additional videos.
🤖 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 55-64: The PromptExtend field in AliVideoParameters must be
changed from bool to *bool so explicit false is preserved when marshaling;
update the struct definition to use PromptExtend *bool and ensure any code that
constructs or merges AliVideoParameters (e.g., where instances are
created/merged) initializes a default true value using lo.ToPtr(true) unless
explicitly overridden by the client so the field is non-nil by default and
client-set false is sent upstream.
---
Outside diff comments:
In `@relay/common/relay_info.go`:
- Around line 670-682: TaskSubmitReq.Videos was added but the multipart parsing
and validation paths don't handle it; update validateMultipartTaskRequest() to
copy formData["videos"] into the TaskSubmitReq, add "videos" to the known fields
checked by isKnownTaskField(), and change ValidateMultipartDirect() so action
derivation (currently using req.HasImage()) also treats videos—either add a
req.HasMedia()/HasVideo() helper or extend HasImage() to consider req.Videos so
video-edit tasks with only videos are classified and populated correctly.
---
Duplicate comments:
In `@relay/channel/task/ali/adaptor.go`:
- Around line 389-396: The edit branch for happyhorse-1.0-video-edit currently
only checks for len(req.Videos) < 1 but then quietly drops extra videos; update
the isEdit handling so it enforces exactly one video by returning an error when
len(req.Videos) != 1 (use the same error style/format as other checks), leaving
the existing aliReq.Input.Media append of req.Videos[0] unchanged; make the
check adjacent to the isEdit branch (referencing isEdit, req.Videos, and
aliReq.Input.Media) so malformed requests fail fast instead of silently
discarding additional videos.
🪄 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: c7abb4b8-2d5e-4fee-bbe5-03b8bdc810f3
📒 Files selected for processing (2)
relay/channel/task/ali/adaptor.gorelay/common/relay_info.go
| type AliVideoParameters struct { | ||
| Resolution string `json:"resolution,omitempty"` // 分辨率: 480P/720P/1080P(图生视频、首尾帧生视频) | ||
| Size string `json:"size,omitempty"` // 尺寸: 如 "832*480"(文生视频) | ||
| Duration int `json:"duration,omitempty"` // 时长: 3-10秒 | ||
| PromptExtend bool `json:"prompt_extend,omitempty"` // 是否开启prompt智能改写 | ||
| Watermark bool `json:"watermark,omitempty"` // 是否添加水印 | ||
| Audio *bool `json:"audio,omitempty"` // 是否添加音频(wan2.5) | ||
| Seed int `json:"seed,omitempty"` // 随机数种子 | ||
| Resolution string `json:"resolution,omitempty"` // 分辨率: 480P/720P/1080P(图生视频、首尾帧生视频) | ||
| Size string `json:"size,omitempty"` // 尺寸: 如 "832*480"(文生视频) | ||
| Duration int `json:"duration,omitempty"` // 时长: 3-10秒 | ||
| Ratio *string `json:"ratio,omitempty"` // 宽高比: Happy Horse t2v/r2v | ||
| AudioSetting *string `json:"audio_setting,omitempty"` // 声音控制: Happy Horse video-edit (auto/origin) | ||
| PromptExtend bool `json:"prompt_extend,omitempty"` // 是否开启prompt智能改写 | ||
| Watermark *bool `json:"watermark,omitempty"` // 是否添加水印 | ||
| Audio *bool `json:"audio,omitempty"` // 是否添加音频(wan2.5) | ||
| Seed int `json:"seed,omitempty"` // 随机数种子 |
There was a problem hiding this comment.
prompt_extend=false will still be dropped upstream.
Watermark was switched to *bool to preserve explicit false, but PromptExtend still has the same bool,omitempty problem. If a client sends prompt_extend: false, the metadata merge can set it locally, but the final marshal will omit the field and Ali never sees the override. Please make PromptExtend a *bool and initialize the default with lo.ToPtr(true).
♻️ Proposed fix
type AliVideoParameters struct {
Resolution string `json:"resolution,omitempty"` // 分辨率: 480P/720P/1080P(图生视频、首尾帧生视频)
Size string `json:"size,omitempty"` // 尺寸: 如 "832*480"(文生视频)
Duration int `json:"duration,omitempty"` // 时长: 3-10秒
Ratio *string `json:"ratio,omitempty"` // 宽高比: Happy Horse t2v/r2v
AudioSetting *string `json:"audio_setting,omitempty"` // 声音控制: Happy Horse video-edit (auto/origin)
- PromptExtend bool `json:"prompt_extend,omitempty"` // 是否开启prompt智能改写
+ PromptExtend *bool `json:"prompt_extend,omitempty"` // 是否开启prompt智能改写
Watermark *bool `json:"watermark,omitempty"` // 是否添加水印
Audio *bool `json:"audio,omitempty"` // 是否添加音频(wan2.5)
Seed int `json:"seed,omitempty"` // 随机数种子
}
@@
Parameters: &AliVideoParameters{
- PromptExtend: true, // 默认开启智能改写
+ PromptExtend: lo.ToPtr(true), // 默认开启智能改写
Watermark: lo.ToPtr(false),
},As per coding guidelines relay/**/*.go: “Optional scalar fields MUST use pointer types with omitempty ... field explicitly set to zero/false => non-nil pointer => sent upstream.”
🤖 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 55 - 64, The PromptExtend
field in AliVideoParameters must be changed from bool to *bool so explicit false
is preserved when marshaling; update the struct definition to use PromptExtend
*bool and ensure any code that constructs or merges AliVideoParameters (e.g.,
where instances are created/merged) initializes a default true value using
lo.ToPtr(true) unless explicitly overridden by the client so the field is
non-nil by default and client-set false is sent upstream.
Change len(req.Videos) < 1 to != 1 so requests with more than one video fail fast instead of silently discarding extras. The multipart parsing concern (Videos not wired in relay_utils.go) is not applicable: the ali adaptor uses ValidateMultipartDirect which calls UnmarshalBodyReusable (JSON deserialization), so Videos is populated via struct tags. The multipart form path is only used by other adaptors. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
relay/channel/task/ali/adaptor.go (1)
64-64: Consider using*intforSeedto preserve explicit zero.
Seed intwithomitemptywill dropseed=0during marshaling. While edge-case,0can be a valid seed value for reproducibility. Using*intwould preserve the client's explicit intent.♻️ Suggested change
- Seed int `json:"seed,omitempty"` // 随机数种子 + Seed *int `json:"seed,omitempty"` // 随机数种子As per coding guidelines
relay/**/*.go: "Optional scalar fields MUST use pointer types withomitempty."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@relay/channel/task/ali/adaptor.go` at line 64, The Seed field is defined as a non-pointer int with `omitempty`, which drops an explicit zero value; change the struct field type from `int` to `*int` (i.e., Seed *int `json:"seed,omitempty"`) to preserve explicit zero, then update all call sites that construct or read Seed (e.g., places that set Seed should take the address of an int variable or use helper pointer creation, and places that read Seed should nil-check before dereferencing) so serialization and runtime behavior remain correct.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@relay/channel/task/ali/adaptor.go`:
- Line 64: The Seed field is defined as a non-pointer int with `omitempty`,
which drops an explicit zero value; change the struct field type from `int` to
`*int` (i.e., Seed *int `json:"seed,omitempty"`) to preserve explicit zero, then
update all call sites that construct or read Seed (e.g., places that set Seed
should take the address of an int variable or use helper pointer creation, and
places that read Seed should nil-check before dereferencing) so serialization
and runtime behavior remain correct.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 078ebb51-484e-4438-a6e5-998bd4ac2ebc
📒 Files selected for processing (1)
relay/channel/task/ali/adaptor.go
51fdfc5 to
2b6f1df
Compare
Summary
Add support for Alibaba Cloud Bailian Happy Horse 1.0 video generation models in the
alichannel adaptor.Happy Horse 1.0 is a video generation model on Alibaba Cloud Bailian (DashScope API) that shares the same DashScope endpoint as Wanxiang models (
/api/v1/services/aigc/video-generation/video-synthesis), but uses a different request format — amediaarray instead of flat fields (img_url,first_frame_url, etc.).Changes
Model registration: Add 4 Happy Horse model IDs to
ModelList:happyhorse-1.0-t2v— text-to-videohappyhorse-1.0-i2v— first frame image-to-videohappyhorse-1.0-r2v— reference images-to-video (1-9 images, usecharacter1/character2in prompt)happyhorse-1.0-video-edit— video editing (1 video + 0-5 reference images)Request format: Add
AliMediaItemstruct andMediafield for themediaarray format:{"input": {"media": [{"type": "first_frame", "url": "..."}, {"type": "reference_image", "url": "..."}]}}New parameters: Add
Ratio(aspect ratio for t2v/r2v) andAudioSetting(audio control for video-edit:auto/origin) toAliVideoParametersWatermark fix: Change
Watermarkfromboolto*boolpointer type. Happy Horse API defaults watermark totrue, but Go'somitemptytag silently dropsfalsevalues, causing watermarks to always appear. Using*boolensuresfalseis serialized. This also fixes a latent bug for Wanxiang models.Auto-detection:
convertToAliRequestdetects Happy Horse models by"happyhorse-1.0"prefix and routes toconvertToHappyHorseRequestFiles changed
relay/channel/task/ali/constants.goModelListrelay/channel/task/ali/adaptor.goAliMediaItem,Mediafield,Ratio/AudioSettingparams,*boolWatermark,convertToHappyHorseRequestmethodHappy Horse parameter differences vs Wanxiang
References
🤖 Generated with Claude Code
Summary by CodeRabbit