加回 nano-banana-2 与 nano-banana-pro 并存
This commit is contained in:
@@ -13,14 +13,15 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// GenerateImage runs the Runway "Nano Banana Pro" (workflow_gemini_image /
|
||||
// gemini-3-pro-image-preview) text/image-to-image pipeline: upload each
|
||||
// reference image (DATASET + DATASET_PREVIEW → dataset) to obtain its
|
||||
// {assetId, url}, create a gemini image task and poll it to completion, then
|
||||
// download the rendered PNG. teamID is the workspace id; if empty it's derived
|
||||
// from the token. imageSize is the "1K"/"2K"/"4K" tier (Pro honors 2K/4K).
|
||||
// refs may be empty (pure text-to-image).
|
||||
func (c *Client) GenerateImage(ctx context.Context, token, teamID, prompt, imageSize string, refs [][]byte) ([]byte, map[string]any, error) {
|
||||
// GenerateImage runs a Runway gemini image text/image-to-image pipeline:
|
||||
// upload each reference image (DATASET + DATASET_PREVIEW → dataset) to obtain
|
||||
// its {assetId, url}, create a gemini image task and poll it to completion,
|
||||
// then download the rendered PNG. modelID selects the variant: "nano-banana-2"
|
||||
// → gemini_3_1_flash_image / gemini-3.1-flash-image-preview (with aspect_ratio),
|
||||
// anything else → workflow_gemini_image / gemini-3-pro-image-preview. imageSize
|
||||
// is the "1K"/"2K"/"4K" tier. teamID is the workspace id; if empty it's derived
|
||||
// from the token. refs may be empty (pure text-to-image).
|
||||
func (c *Client) GenerateImage(ctx context.Context, token, teamID, modelID, prompt, aspectRatio, imageSize string, refs [][]byte) ([]byte, map[string]any, error) {
|
||||
token = strings.TrimSpace(strings.TrimPrefix(token, "Bearer "))
|
||||
if token == "" {
|
||||
return nil, nil, ErrAuth
|
||||
@@ -63,7 +64,7 @@ func (c *Client) GenerateImage(ctx context.Context, token, teamID, prompt, image
|
||||
})
|
||||
}
|
||||
|
||||
taskID, err := c.createImageTask(ctx, submitClient, token, teamID, prompt, imageSize, refImages)
|
||||
taskID, err := c.createImageTask(ctx, submitClient, token, teamID, modelID, prompt, aspectRatio, imageSize, refImages)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -108,9 +109,10 @@ func (c *Client) uploadReference(ctx context.Context, client tlsclient.HttpClien
|
||||
return assetID, refURL, nil
|
||||
}
|
||||
|
||||
// createImageTask creates a workflow_gemini_image (Nano Banana Pro) task and
|
||||
// returns its id.
|
||||
func (c *Client) createImageTask(ctx context.Context, client tlsclient.HttpClient, token, teamID, prompt, imageSize string, refImages []map[string]any) (string, error) {
|
||||
// createImageTask creates a gemini image task (workflow_gemini_image for Pro,
|
||||
// gemini_3_1_flash_image for Nano Banana 2) and returns its id.
|
||||
func (c *Client) createImageTask(ctx context.Context, client tlsclient.HttpClient, token, teamID, modelID, prompt, aspectRatio, imageSize string, refImages []map[string]any) (string, error) {
|
||||
taskType := "workflow_gemini_image"
|
||||
opts := map[string]any{
|
||||
"name": "Nano Banana Pro - " + prompt,
|
||||
"text_prompt": prompt,
|
||||
@@ -120,11 +122,20 @@ func (c *Client) createImageTask(ctx context.Context, client tlsclient.HttpClien
|
||||
"exploreMode": false,
|
||||
"creationSource": "tool-mode",
|
||||
}
|
||||
if modelID == "nano-banana-2" {
|
||||
taskType = "gemini_3_1_flash_image"
|
||||
opts["name"] = "Nano Banana 2 - " + prompt
|
||||
opts["model"] = "gemini-3.1-flash-image-preview"
|
||||
if strings.TrimSpace(aspectRatio) == "" {
|
||||
aspectRatio = "16:9"
|
||||
}
|
||||
opts["aspect_ratio"] = aspectRatio
|
||||
}
|
||||
if len(refImages) > 0 {
|
||||
opts["reference_images"] = refImages
|
||||
}
|
||||
res, err := c.submitTask(ctx, client, token, teamID, map[string]any{
|
||||
"taskType": "workflow_gemini_image",
|
||||
"taskType": taskType,
|
||||
"options": opts,
|
||||
"asTeamId": jsonNumberOrString(teamID),
|
||||
"sessionId": uuid.NewString(),
|
||||
|
||||
Reference in New Issue
Block a user