-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
viduq2视频模型兼容不同生成方式的适配 #2216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
viduq2视频模型兼容不同生成方式的适配 #2216
Conversation
WalkthroughThe changes extend model selection logic in the Vidu adaptor's BuildRequestBody function to handle multiple action types. ReferenceGenerate and TextGenerate now force "viduq2" variants, while Generate and FirstTailGenerate upgrade "viduq2" to "viduq2-turbo". Import reordering is also applied. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
relay/channel/task/vidu/adaptor.go(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-26T09:59:00.337Z
Learnt from: Sh1n3zZ
Repo: QuantumNous/new-api PR: 1659
File: relay/relay_task.go:285-305
Timestamp: 2025-08-26T09:59:00.337Z
Learning: In controller/task_video.go, the redactVideoResponseBody function sanitizes video task responses by removing bytesBase64Encoded fields and truncating base64 strings to 256 characters to prevent large binary data from being stored in task.Data.
Applied to files:
relay/channel/task/vidu/adaptor.go
🧬 Code graph analysis (1)
relay/channel/task/vidu/adaptor.go (1)
constant/task.go (4)
TaskActionReferenceGenerate(17-17)TaskActionTextGenerate(15-15)TaskActionGenerate(14-14)TaskActionFirstTailGenerate(16-16)
| switch info.Action { | ||
| case constant.TaskActionReferenceGenerate, constant.TaskActionTextGenerate: | ||
| // 参考图生视频和文生视频只能用 viduq2 模型, 不能带有pro或turbo后缀 https://platform.vidu.cn/docs/reference-to-video | ||
| if strings.Contains(body.Model, "viduq2") { | ||
| // 参考图生视频只能用 viduq2 模型, 不能带有pro或turbo后缀 https://platform.vidu.cn/docs/reference-to-video | ||
| body.Model = "viduq2" | ||
| } | ||
| case constant.TaskActionGenerate, constant.TaskActionFirstTailGenerate: | ||
| // 图生视频和首尾帧生视频只能用 viduq2-turbo 或 viduq2-pro | ||
| if body.Model == "viduq2" { | ||
| body.Model = "viduq2-turbo" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation to reject invalid models for each action type.
The current logic partially adjusts models but doesn't validate that only permitted models are used for each action. According to the Vidu API requirements:
-
ReferenceGenerate & TextGenerate: Must use
viduq2only (no pro/turbo suffix)- Current: Forces viduq2 variants to
viduq2, but allows invalid models likeviduq1to pass through
- Current: Forces viduq2 variants to
-
Generate & FirstTailGenerate: Must use
viduq2-turboorviduq2-proonly- Current: Upgrades bare
viduq2toviduq2-turbo, but allows invalid models to pass through
- Current: Upgrades bare
If a user submits an incompatible model (e.g., viduq1 for Generate action), the request will fail at Vidu's API rather than being caught early with a clear error.
Consider this validation approach:
switch info.Action {
case constant.TaskActionReferenceGenerate, constant.TaskActionTextGenerate:
// 参考图生视频和文生视频只能用 viduq2 模型, 不能带有pro或turbo后缀 https://platform.vidu.cn/docs/reference-to-video
if strings.Contains(body.Model, "viduq2") {
body.Model = "viduq2"
+ } else {
+ return nil, fmt.Errorf("model %s is not supported for action %s, only viduq2 is allowed", body.Model, info.Action)
}
case constant.TaskActionGenerate, constant.TaskActionFirstTailGenerate:
// 图生视频和首尾帧生视频只能用 viduq2-turbo 或 viduq2-pro
if body.Model == "viduq2" {
body.Model = "viduq2-turbo"
+ } else if body.Model != "viduq2-turbo" && body.Model != "viduq2-pro" {
+ return nil, fmt.Errorf("model %s is not supported for action %s, only viduq2-turbo or viduq2-pro are allowed", body.Model, info.Action)
}
}📝 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.
| switch info.Action { | |
| case constant.TaskActionReferenceGenerate, constant.TaskActionTextGenerate: | |
| // 参考图生视频和文生视频只能用 viduq2 模型, 不能带有pro或turbo后缀 https://platform.vidu.cn/docs/reference-to-video | |
| if strings.Contains(body.Model, "viduq2") { | |
| // 参考图生视频只能用 viduq2 模型, 不能带有pro或turbo后缀 https://platform.vidu.cn/docs/reference-to-video | |
| body.Model = "viduq2" | |
| } | |
| case constant.TaskActionGenerate, constant.TaskActionFirstTailGenerate: | |
| // 图生视频和首尾帧生视频只能用 viduq2-turbo 或 viduq2-pro | |
| if body.Model == "viduq2" { | |
| body.Model = "viduq2-turbo" | |
| } | |
| } | |
| switch info.Action { | |
| case constant.TaskActionReferenceGenerate, constant.TaskActionTextGenerate: | |
| // 参考图生视频和文生视频只能用 viduq2 模型, 不能带有pro或turbo后缀 https://platform.vidu.cn/docs/reference-to-video | |
| if strings.Contains(body.Model, "viduq2") { | |
| body.Model = "viduq2" | |
| } else { | |
| return nil, fmt.Errorf("model %s is not supported for action %s, only viduq2 is allowed", body.Model, info.Action) | |
| } | |
| case constant.TaskActionGenerate, constant.TaskActionFirstTailGenerate: | |
| // 图生视频和首尾帧生视频只能用 viduq2-turbo 或 viduq2-pro | |
| if body.Model == "viduq2" { | |
| body.Model = "viduq2-turbo" | |
| } else if body.Model != "viduq2-turbo" && body.Model != "viduq2-pro" { | |
| return nil, fmt.Errorf("model %s is not supported for action %s, only viduq2-turbo or viduq2-pro are allowed", body.Model, info.Action) | |
| } | |
| } |
🤖 Prompt for AI Agents
In relay/channel/task/vidu/adaptor.go around lines 122 to 133, the code only
coerces some model values but does not validate allowed models per action; add
explicit validation so invalid models are rejected early: for
TaskActionReferenceGenerate and TaskActionTextGenerate accept only "viduq2"
(reject anything else with a descriptive error), and for TaskActionGenerate and
TaskActionFirstTailGenerate accept only "viduq2-turbo" or "viduq2-pro" (if
incoming is exactly "viduq2" you may coerce to "viduq2-turbo" but otherwise
reject unknown values); return a clear validation error before calling the Vidu
API when the model is not one of the permitted values.
图生视频和首尾帧生视频只能用 viduq2-turbo 或 viduq2-pro
参考图生视频和文生视频只能用 viduq2 , 不能带有pro或turbo后缀
https://platform.vidu.cn/docs/reference-to-video
Summary by CodeRabbit