mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 09:48:39 +00:00
feat: gemini veo req to struct
This commit is contained in:
@@ -19,15 +19,32 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/setting/model_setting"
|
"github.com/QuantumNous/new-api/setting/model_setting"
|
||||||
"github.com/QuantumNous/new-api/setting/system_setting"
|
"github.com/QuantumNous/new-api/setting/system_setting"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ============================
|
// ============================
|
||||||
// Request / Response structures
|
// Request / Response structures
|
||||||
// ============================
|
// ============================
|
||||||
|
|
||||||
type requestPayload struct {
|
// GeminiVideoGenerationConfig represents the video generation configuration
|
||||||
Instances []map[string]any `json:"instances"`
|
// Based on: https://ai.google.dev/gemini-api/docs/video
|
||||||
Parameters map[string]any `json:"parameters,omitempty"`
|
type GeminiVideoGenerationConfig struct {
|
||||||
|
AspectRatio string `json:"aspectRatio,omitempty"` // "16:9" or "9:16"
|
||||||
|
DurationSeconds float64 `json:"durationSeconds,omitempty"` // 4, 6, or 8 (as number)
|
||||||
|
NegativePrompt string `json:"negativePrompt,omitempty"` // unwanted elements
|
||||||
|
PersonGeneration string `json:"personGeneration,omitempty"` // "allow_all" for text-to-video, "allow_adult" for image-to-video
|
||||||
|
Resolution string `json:"resolution,omitempty"` // video resolution
|
||||||
|
}
|
||||||
|
|
||||||
|
// GeminiVideoRequest represents a single video generation instance
|
||||||
|
type GeminiVideoRequest struct {
|
||||||
|
Prompt string `json:"prompt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GeminiVideoPayload represents the complete video generation request payload
|
||||||
|
type GeminiVideoPayload struct {
|
||||||
|
Instances []GeminiVideoRequest `json:"instances"`
|
||||||
|
Parameters GeminiVideoGenerationConfig `json:"parameters,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type submitResponse struct {
|
type submitResponse struct {
|
||||||
@@ -114,38 +131,22 @@ func (a *TaskAdaptor) BuildRequestBody(c *gin.Context, info *relaycommon.RelayIn
|
|||||||
}
|
}
|
||||||
req := v.(relaycommon.TaskSubmitReq)
|
req := v.(relaycommon.TaskSubmitReq)
|
||||||
|
|
||||||
body := requestPayload{
|
// Create structured video generation request
|
||||||
Instances: []map[string]any{{"prompt": req.Prompt}},
|
body := GeminiVideoPayload{
|
||||||
Parameters: map[string]any{},
|
Instances: []GeminiVideoRequest{
|
||||||
|
{Prompt: req.Prompt},
|
||||||
|
},
|
||||||
|
Parameters: GeminiVideoGenerationConfig{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Veo-specific parameters from metadata
|
metadata := req.Metadata
|
||||||
if req.Metadata != nil {
|
medaBytes, err := json.Marshal(metadata)
|
||||||
if v, ok := req.Metadata["aspectRatio"]; ok {
|
if err != nil {
|
||||||
body.Parameters["aspectRatio"] = v
|
return nil, errors.Wrap(err, "metadata marshal metadata failed")
|
||||||
} else {
|
}
|
||||||
body.Parameters["aspectRatio"] = "16:9" // default
|
err = json.Unmarshal(medaBytes, &body.Parameters)
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "unmarshal metadata failed")
|
||||||
if v, ok := req.Metadata["negativePrompt"]; ok {
|
|
||||||
body.Parameters["negativePrompt"] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := req.Metadata["durationSeconds"]; ok {
|
|
||||||
body.Parameters["durationSeconds"] = v
|
|
||||||
} else {
|
|
||||||
body.Parameters["durationSeconds"] = "8" // default
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := req.Metadata["resolution"]; ok {
|
|
||||||
body.Parameters["resolution"] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := req.Metadata["personGeneration"]; ok {
|
|
||||||
body.Parameters["personGeneration"] = v
|
|
||||||
} else {
|
|
||||||
body.Parameters["personGeneration"] = "allow_adult" // default
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(body)
|
data, err := json.Marshal(body)
|
||||||
|
|||||||
Reference in New Issue
Block a user