Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
18b03600
authored
Nov 10, 2025
by
IcedTangerine
Committed by
GitHub
Nov 10, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2204 from feitianbubu/pr/vidu-q2-reference
修复viduq2不支持参考生视频的问题
parents
48f767f8
29c71927
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
20 deletions
+42
-20
relay/channel/task/vidu/adaptor.go
+31
-8
relay/common/relay_utils.go
+11
-12
No files found.
relay/channel/task/vidu/adaptor.go
View file @
18b03600
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
"strings"
"time"
"time"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/common"
...
@@ -82,10 +83,32 @@ func (a *TaskAdaptor) Init(info *relaycommon.RelayInfo) {
...
@@ -82,10 +83,32 @@ func (a *TaskAdaptor) Init(info *relaycommon.RelayInfo) {
}
}
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
*
dto
.
TaskError
{
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
*
dto
.
TaskError
{
return
relaycommon
.
ValidateBasicTaskRequest
(
c
,
info
,
constant
.
TaskActionGenerate
)
if
err
:=
relaycommon
.
ValidateBasicTaskRequest
(
c
,
info
,
constant
.
TaskActionGenerate
);
err
!=
nil
{
return
err
}
req
,
err
:=
relaycommon
.
GetTaskRequest
(
c
)
if
err
!=
nil
{
return
service
.
TaskErrorWrapper
(
err
,
"get_task_request_failed"
,
http
.
StatusBadRequest
)
}
action
:=
constant
.
TaskActionTextGenerate
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
}
}
func
(
a
*
TaskAdaptor
)
BuildRequestBody
(
c
*
gin
.
Context
,
_
*
relaycommon
.
RelayInfo
)
(
io
.
Reader
,
error
)
{
func
(
a
*
TaskAdaptor
)
BuildRequestBody
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
io
.
Reader
,
error
)
{
v
,
exists
:=
c
.
Get
(
"task_request"
)
v
,
exists
:=
c
.
Get
(
"task_request"
)
if
!
exists
{
if
!
exists
{
return
nil
,
fmt
.
Errorf
(
"request not found in context"
)
return
nil
,
fmt
.
Errorf
(
"request not found in context"
)
...
@@ -97,8 +120,11 @@ func (a *TaskAdaptor) BuildRequestBody(c *gin.Context, _ *relaycommon.RelayInfo)
...
@@ -97,8 +120,11 @@ func (a *TaskAdaptor) BuildRequestBody(c *gin.Context, _ *relaycommon.RelayInfo)
return
nil
,
err
return
nil
,
err
}
}
if
len
(
body
.
Images
)
==
0
{
if
info
.
Action
==
constant
.
TaskActionReferenceGenerate
{
c
.
Set
(
"action"
,
constant
.
TaskActionTextGenerate
)
if
strings
.
Contains
(
body
.
Model
,
"viduq2"
)
{
// 参考图生视频只能用 viduq2 模型, 不能带有pro或turbo后缀 https://platform.vidu.cn/docs/reference-to-video
body
.
Model
=
"viduq2"
}
}
}
data
,
err
:=
json
.
Marshal
(
body
)
data
,
err
:=
json
.
Marshal
(
body
)
...
@@ -131,9 +157,6 @@ func (a *TaskAdaptor) BuildRequestHeader(c *gin.Context, req *http.Request, info
...
@@ -131,9 +157,6 @@ func (a *TaskAdaptor) BuildRequestHeader(c *gin.Context, req *http.Request, info
}
}
func
(
a
*
TaskAdaptor
)
DoRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
requestBody
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
func
(
a
*
TaskAdaptor
)
DoRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
requestBody
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
if
action
:=
c
.
GetString
(
"action"
);
action
!=
""
{
info
.
Action
=
action
}
return
channel
.
DoTaskApiRequest
(
a
,
c
,
info
,
requestBody
)
return
channel
.
DoTaskApiRequest
(
a
,
c
,
info
,
requestBody
)
}
}
...
@@ -185,7 +208,7 @@ func (a *TaskAdaptor) FetchTask(baseUrl, key string, body map[string]any) (*http
...
@@ -185,7 +208,7 @@ func (a *TaskAdaptor) FetchTask(baseUrl, key string, body map[string]any) (*http
}
}
func
(
a
*
TaskAdaptor
)
GetModelList
()
[]
string
{
func
(
a
*
TaskAdaptor
)
GetModelList
()
[]
string
{
return
[]
string
{
"viduq1"
,
"vidu2.0"
,
"vidu1.5"
}
return
[]
string
{
"viduq
2"
,
"viduq
1"
,
"vidu2.0"
,
"vidu1.5"
}
}
}
func
(
a
*
TaskAdaptor
)
GetChannelName
()
string
{
func
(
a
*
TaskAdaptor
)
GetChannelName
()
string
{
...
...
relay/common/relay_utils.go
View file @
18b03600
...
@@ -59,6 +59,17 @@ func storeTaskRequest(c *gin.Context, info *RelayInfo, action string, requestObj
...
@@ -59,6 +59,17 @@ func storeTaskRequest(c *gin.Context, info *RelayInfo, action string, requestObj
info
.
Action
=
action
info
.
Action
=
action
c
.
Set
(
"task_request"
,
requestObj
)
c
.
Set
(
"task_request"
,
requestObj
)
}
}
func
GetTaskRequest
(
c
*
gin
.
Context
)
(
TaskSubmitReq
,
error
)
{
v
,
exists
:=
c
.
Get
(
"task_request"
)
if
!
exists
{
return
TaskSubmitReq
{},
fmt
.
Errorf
(
"request not found in context"
)
}
req
,
ok
:=
v
.
(
TaskSubmitReq
)
if
!
ok
{
return
TaskSubmitReq
{},
fmt
.
Errorf
(
"invalid task request type"
)
}
return
req
,
nil
}
func
validatePrompt
(
prompt
string
)
*
dto
.
TaskError
{
func
validatePrompt
(
prompt
string
)
*
dto
.
TaskError
{
if
strings
.
TrimSpace
(
prompt
)
==
""
{
if
strings
.
TrimSpace
(
prompt
)
==
""
{
...
@@ -212,18 +223,6 @@ func ValidateBasicTaskRequest(c *gin.Context, info *RelayInfo, action string) *d
...
@@ -212,18 +223,6 @@ func ValidateBasicTaskRequest(c *gin.Context, info *RelayInfo, action string) *d
req
.
Images
=
[]
string
{
req
.
Image
}
req
.
Images
=
[]
string
{
req
.
Image
}
}
}
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
}
}
}
storeTaskRequest
(
c
,
info
,
action
,
req
)
storeTaskRequest
(
c
,
info
,
action
,
req
)
return
nil
return
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment