Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions relay/channel/task/vidu/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (
"time"

"github.com/QuantumNous/new-api/common"
"github.com/gin-gonic/gin"

"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/relay/channel"
relaycommon "github.com/QuantumNous/new-api/relay/common"
"github.com/QuantumNous/new-api/service"
"github.com/gin-gonic/gin"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -120,11 +119,17 @@ func (a *TaskAdaptor) BuildRequestBody(c *gin.Context, info *relaycommon.RelayIn
return nil, err
}

if info.Action == constant.TaskActionReferenceGenerate {
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"
}
}
Comment on lines +122 to 133
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.


data, err := json.Marshal(body)
Expand Down