修复viduq2不支持参考生视频的问题 - #2204
Conversation
WalkthroughThe changes refactor task request validation and action determination in the Vidu task adaptor by introducing a shared utility function to extract task requests from context. Action logic now derives FirstTailGenerate or ReferenceGenerate based on image count and model selection, with explicit viduq2 support added to the model list. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
relay/channel/task/vidu/adaptor.go(4 hunks)relay/common/relay_utils.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
relay/common/relay_utils.go (1)
relay/common/relay_info.go (1)
TaskSubmitReq(488-499)
relay/channel/task/vidu/adaptor.go (5)
relay/common/relay_utils.go (3)
ValidateBasicTaskRequest(204-228)GetTaskRequest(62-72)HasImage(21-23)constant/task.go (4)
TaskActionGenerate(14-14)TaskActionTextGenerate(15-15)TaskActionFirstTailGenerate(16-16)TaskActionReferenceGenerate(17-17)service/error.go (1)
TaskErrorWrapper(140-157)constant/channel.go (1)
ChannelTypeVidu(52-52)relay/channel/adapter.go (1)
TaskAdaptor(34-53)
| if meatAction, ok := req.Metadata["action"]; ok { | ||
| action, _ = meatAction.(string) | ||
| } else if req.HasImage() { | ||
| action = constant.TaskActionGenerate | ||
| if info.ChannelType == constant.ChannelTypeVidu { | ||
| // vidu 增加 首尾帧生视频和参考图生视频 | ||
| if len(req.Images) == 2 { | ||
| action = constant.TaskActionFirstTailGenerate | ||
| } else if len(req.Images) > 2 { | ||
| action = constant.TaskActionReferenceGenerate | ||
| } | ||
| } | ||
| } | ||
| info.Action = action | ||
| return nil |
There was a problem hiding this comment.
Avoid blank metadata action overriding the fallback
Line 95 assigns action, _ = meatAction.(string), so whenever a request includes an action field that is empty or not a string (typical for HTML forms sending action=), the type assertion zeroes out the variable. Because the branch short-circuits the else if req.HasImage() fallback, info.Action becomes "", BuildRequestURL falls through to /text2video, and image-based requests fail. Previously we always defaulted to generate, so this regresses basic flows. Please only overwrite the default when the metadata value is a non-empty string, and keep the image-derived fallback otherwise.
- action := constant.TaskActionTextGenerate
- if meatAction, ok := req.Metadata["action"]; ok {
- action, _ = meatAction.(string)
- } else if req.HasImage() {
+ action := constant.TaskActionTextGenerate
+ if meatAction, ok := req.Metadata["action"]; ok {
+ if s, ok := meatAction.(string); ok && s != "" {
+ action = s
+ }
+ }
+ if action == constant.TaskActionTextGenerate && req.HasImage() {
action = constant.TaskActionGenerate
if info.ChannelType == constant.ChannelTypeVidu {
// vidu 增加 首尾帧生视频和参考图生视频
if len(req.Images) == 2 {📝 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.
| if meatAction, ok := req.Metadata["action"]; ok { | |
| action, _ = meatAction.(string) | |
| } else if req.HasImage() { | |
| action = constant.TaskActionGenerate | |
| if info.ChannelType == constant.ChannelTypeVidu { | |
| // vidu 增加 首尾帧生视频和参考图生视频 | |
| if len(req.Images) == 2 { | |
| action = constant.TaskActionFirstTailGenerate | |
| } else if len(req.Images) > 2 { | |
| action = constant.TaskActionReferenceGenerate | |
| } | |
| } | |
| } | |
| info.Action = action | |
| return nil | |
| action := constant.TaskActionTextGenerate | |
| if meatAction, ok := req.Metadata["action"]; ok { | |
| if s, ok := meatAction.(string); ok && s != "" { | |
| action = s | |
| } | |
| } | |
| if action == constant.TaskActionTextGenerate && req.HasImage() { | |
| action = constant.TaskActionGenerate | |
| if info.ChannelType == constant.ChannelTypeVidu { | |
| // vidu 增加 首尾帧生视频和参考图生视频 | |
| if len(req.Images) == 2 { | |
| action = constant.TaskActionFirstTailGenerate | |
| } else if len(req.Images) > 2 { | |
| action = constant.TaskActionReferenceGenerate | |
| } | |
| } | |
| } | |
| info.Action = action | |
| return nil |
🤖 Prompt for AI Agents
In relay/channel/task/vidu/adaptor.go around lines 94 to 108, the code
unconditionally assigns action from req.Metadata["action"] even when it's a
non-string or an empty string, which overrides the image-derived fallback;
change the logic so you only set action when the metadata key exists AND the
value is a non-empty string (i.e., type-assert to string, check len>0),
otherwise fall through to the req.HasImage() branch (preserving the previous
default of generate and the special vidu image-length handling) and then assign
info.Action.
…ence 修复viduq2不支持参考生视频的问题
feat: 完善了 OpenAI的GPT模型在 Claude Code 上的工具兼容性和缓存命中率
请求示例:
Summary by CodeRabbit
Release Notes
New Features
Refactor