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
ff19082c
authored
Nov 26, 2025
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: gemini video veo3.1 add i2v
parent
08952ffd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
18 deletions
+51
-18
relay/channel/task/gemini/adaptor.go
+51
-18
No files found.
relay/channel/task/gemini/adaptor.go
View file @
ff19082c
...
@@ -24,13 +24,9 @@ import (
...
@@ -24,13 +24,9 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
// ============================
// VideoGenerationConfig represents the video generation configuration
// Request / Response structures
// ============================
// GeminiVideoGenerationConfig represents the video generation configuration
// Based on: https://ai.google.dev/gemini-api/docs/video
// Based on: https://ai.google.dev/gemini-api/docs/video
type
Gemini
VideoGenerationConfig
struct
{
type
VideoGenerationConfig
struct
{
AspectRatio
string
`json:"aspectRatio,omitempty"`
// "16:9" or "9:16"
AspectRatio
string
`json:"aspectRatio,omitempty"`
// "16:9" or "9:16"
DurationSeconds
float64
`json:"durationSeconds,omitempty"`
// 4, 6, or 8 (as number)
DurationSeconds
float64
`json:"durationSeconds,omitempty"`
// 4, 6, or 8 (as number)
NegativePrompt
string
`json:"negativePrompt,omitempty"`
// unwanted elements
NegativePrompt
string
`json:"negativePrompt,omitempty"`
// unwanted elements
...
@@ -38,15 +34,21 @@ type GeminiVideoGenerationConfig struct {
...
@@ -38,15 +34,21 @@ type GeminiVideoGenerationConfig struct {
Resolution
string
`json:"resolution,omitempty"`
// video resolution
Resolution
string
`json:"resolution,omitempty"`
// video resolution
}
}
// GeminiVideoRequest represents a single video generation instance
type
Image
struct
{
type
GeminiVideoRequest
struct
{
BytesBase64Encoded
string
`json:"bytesBase64Encoded,omitempty"`
Prompt
string
`json:"prompt"`
MimeType
string
`json:"mimeType,omitempty"`
}
type
VideoRequest
struct
{
Prompt
string
`json:"prompt"`
Image
*
Image
`json:"image,omitempty"`
LastFrame
*
Image
`json:"lastFrame,omitempty"`
}
}
//
Gemini
VideoPayload represents the complete video generation request payload
// VideoPayload represents the complete video generation request payload
type
Gemini
VideoPayload
struct
{
type
VideoPayload
struct
{
Instances
[]
Gemini
VideoRequest
`json:"instances"`
Instances
[]
VideoRequest
`json:"instances"`
Parameters
Gemini
VideoGenerationConfig
`json:"parameters,omitempty"`
Parameters
VideoGenerationConfig
`json:"parameters,omitempty"`
}
}
type
submitResponse
struct
{
type
submitResponse
struct
{
...
@@ -100,8 +102,7 @@ func (a *TaskAdaptor) Init(info *relaycommon.RelayInfo) {
...
@@ -100,8 +102,7 @@ func (a *TaskAdaptor) Init(info *relaycommon.RelayInfo) {
// ValidateRequestAndSetAction parses body, validates fields and sets default action.
// ValidateRequestAndSetAction parses body, validates fields and sets default action.
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
taskErr
*
dto
.
TaskError
)
{
func
(
a
*
TaskAdaptor
)
ValidateRequestAndSetAction
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
)
(
taskErr
*
dto
.
TaskError
)
{
// Use the standard validation method for TaskSubmitReq
return
relaycommon
.
ValidateBasicTaskRequest
(
c
,
info
,
constant
.
TaskActionGenerate
)
return
relaycommon
.
ValidateBasicTaskRequest
(
c
,
info
,
constant
.
TaskActionTextGenerate
)
}
}
// BuildRequestURL constructs the upstream URL.
// BuildRequestURL constructs the upstream URL.
...
@@ -137,13 +138,21 @@ func (a *TaskAdaptor) BuildRequestBody(c *gin.Context, info *relaycommon.RelayIn
...
@@ -137,13 +138,21 @@ func (a *TaskAdaptor) BuildRequestBody(c *gin.Context, info *relaycommon.RelayIn
}
}
// Create structured video generation request
// Create structured video generation request
body
:=
Gemini
VideoPayload
{
body
:=
VideoPayload
{
Instances
:
[]
Gemini
VideoRequest
{
Instances
:
[]
VideoRequest
{
{
Prompt
:
req
.
Prompt
},
{
Prompt
:
req
.
Prompt
},
},
},
Parameters
:
GeminiVideoGenerationConfig
{},
Parameters
:
VideoGenerationConfig
{},
}
if
len
(
req
.
Images
)
>
0
{
body
.
Instances
[
0
]
.
Image
=
a
.
convertImage
(
req
.
Images
[
0
])
}
if
len
(
req
.
Images
)
>
1
{
body
.
Instances
[
0
]
.
LastFrame
=
a
.
convertImage
(
req
.
Images
[
1
])
}
}
// Parse metadata for additional configuration
metadata
:=
req
.
Metadata
metadata
:=
req
.
Metadata
medaBytes
,
err
:=
json
.
Marshal
(
metadata
)
medaBytes
,
err
:=
json
.
Marshal
(
metadata
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -289,6 +298,30 @@ func (a *TaskAdaptor) ConvertToOpenAIVideo(task *model.Task) ([]byte, error) {
...
@@ -289,6 +298,30 @@ func (a *TaskAdaptor) ConvertToOpenAIVideo(task *model.Task) ([]byte, error) {
return
common
.
Marshal
(
video
)
return
common
.
Marshal
(
video
)
}
}
func
(
a
*
TaskAdaptor
)
convertImage
(
imageStr
string
)
*
Image
{
if
strings
.
TrimSpace
(
imageStr
)
==
""
{
return
nil
}
img
:=
&
Image
{
MimeType
:
"image/png"
,
BytesBase64Encoded
:
imageStr
,
}
if
strings
.
HasPrefix
(
imageStr
,
"data:image/"
)
{
parts
:=
strings
.
Split
(
imageStr
,
";base64,"
)
if
len
(
parts
)
==
2
{
img
.
MimeType
=
strings
.
TrimPrefix
(
parts
[
0
],
"data:"
)
img
.
BytesBase64Encoded
=
parts
[
1
]
}
}
else
if
strings
.
HasPrefix
(
imageStr
,
"http"
)
{
mimeType
,
data
,
err
:=
service
.
GetImageFromUrl
(
imageStr
)
if
err
==
nil
{
img
.
MimeType
=
mimeType
img
.
BytesBase64Encoded
=
data
}
}
return
img
}
// ============================
// ============================
// helpers
// helpers
// ============================
// ============================
...
...
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