Skip to content

Conversation

@feitianbubu
Copy link
Contributor

@feitianbubu feitianbubu commented Nov 12, 2025

图生视频和首尾帧生视频只能用 viduq2-turbo 或 viduq2-pro
参考图生视频和文生视频只能用 viduq2 , 不能带有pro或turbo后缀
https://platform.vidu.cn/docs/reference-to-video

Summary by CodeRabbit

  • Improvements
    • Enhanced model selection logic for video generation tasks. The system now automatically optimizes model assignments across multiple action types, including ensuring proper model variants are used for reference and text-based generation workflows. Automatic model upgrades are applied when beneficial for certain generation scenarios.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2025

Walkthrough

The 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

Cohort / File(s) Summary
Vidu Adaptor Model Selection
relay/channel/task/vidu/adaptor.go
Extended BuildRequestBody with action-based model adjustment: ReferenceGenerate and TextGenerate constrain model to "viduq2"; Generate and FirstTailGenerate upgrade "viduq2" to "viduq2-turbo". Import block reordered.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single file modification with straightforward conditional logic
  • Model name adjustments follow consistent pattern across action types
  • Import reordering has no functional impact

Possibly related PRs

  • #2204: Prior PR that introduced initial ReferenceGenerate model-selection handling in the same adaptor file; this PR extends that pattern to additional action types.

Suggested reviewers

  • creamlike1024

Poem

🐰✨ A turbo upgrade hops into view,
Viduq2 transforms through actions anew,
Each task gets its model just right,
The reference, the text, the generate's flight!
One adaptor, one hop, many variants true! 🚀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title in Chinese describes model compatibility for different video generation methods, which directly relates to the code changes that add model adaptation logic for different action types (ReferenceGenerate, TextGenerate, Generate, FirstTailGenerate).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between de93fa5 and 159d6c4.

📒 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)

Comment on lines +122 to 133
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"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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:

  1. ReferenceGenerate & TextGenerate: Must use viduq2 only (no pro/turbo suffix)

    • Current: Forces viduq2 variants to viduq2, but allows invalid models like viduq1 to pass through
  2. Generate & FirstTailGenerate: Must use viduq2-turbo or viduq2-pro only

    • Current: Upgrades bare viduq2 to viduq2-turbo, but allows invalid models to pass through

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.

Suggested change
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.

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.

1 participant