Skip to content

Commit ae3ed6e

Browse files
authored
💄 style: nano banana support aspect_ratio (#9528)
* ✨ feat: add nano banana model parameters and update image generation config * ✨ feat: 添加 Nano Banana 模型参数和图像生成定价配置
1 parent 5a69857 commit ae3ed6e

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

packages/model-bank/src/aiModels/google.ts

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,28 @@ const googleChatModels: AIChatModelCard[] = [
366366
'Nano Banana 是 Google 最新、最快、最高效的原生多模态模型,它允许您通过对话生成和编辑图像。',
367367
displayName: 'Nano Banana',
368368
enabled: true,
369+
id: 'gemini-2.5-flash-image',
370+
maxOutput: 8192,
371+
pricing: {
372+
units: [
373+
{ name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },
374+
{ name: 'imageInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },
375+
{ name: 'textOutput', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },
376+
{ name: 'imageOutput', rate: 30, strategy: 'fixed', unit: 'millionTokens' },
377+
],
378+
},
379+
releasedAt: '2025-08-26',
380+
type: 'chat',
381+
},
382+
{
383+
abilities: {
384+
imageOutput: true,
385+
vision: true,
386+
},
387+
contextWindowTokens: 32_768 + 8192,
388+
description:
389+
'Nano Banana 是 Google 最新、最快、最高效的原生多模态模型,它允许您通过对话生成和编辑图像。',
390+
displayName: 'Nano Banana (Preview)',
369391
id: 'gemini-2.5-flash-image-preview',
370392
maxOutput: 8192,
371393
pricing: {
@@ -805,22 +827,62 @@ const imagenBaseParameters: ModelParamsSchema = {
805827
prompt: { default: '' },
806828
};
807829

830+
const NANO_BANANA_ASPECT_RATIOS = [
831+
'1:1', // 1024x1024
832+
'2:3', // 832x1248
833+
'3:2', // 1248x832
834+
'3:4', // 864x1184
835+
'4:3', // 1184x864
836+
'4:5', // 896x1152
837+
'5:4', // 1152x896
838+
'9:16', // 768x1344
839+
'16:9', // 1344x768
840+
'21:9', // 1536x672
841+
];
842+
843+
const nanoBananaParameters: ModelParamsSchema = {
844+
aspectRatio: {
845+
default: '1:1',
846+
enum: NANO_BANANA_ASPECT_RATIOS,
847+
},
848+
imageUrls: {
849+
default: [],
850+
},
851+
prompt: { default: '' },
852+
};
853+
808854
/* eslint-disable sort-keys-fix/sort-keys-fix */
809855
const googleImageModels: AIImageModelCard[] = [
810856
{
811857
displayName: 'Nano Banana',
812-
id: 'gemini-2.5-flash-image-preview:image',
858+
id: 'gemini-2.5-flash-image:image',
813859
enabled: true,
814860
type: 'image',
815861
description:
816862
'Nano Banana 是 Google 最新、最快、最高效的原生多模态模型,它允许您通过对话生成和编辑图像。',
817863
releasedAt: '2025-08-26',
864+
parameters: nanoBananaParameters,
865+
pricing: {
866+
units: [
867+
{ name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },
868+
{ name: 'textOutput', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },
869+
{ name: 'imageOutput', rate: 30, strategy: 'fixed', unit: 'millionTokens' },
870+
],
871+
},
872+
},
873+
{
874+
displayName: 'Nano Banana (Preview)',
875+
id: 'gemini-2.5-flash-image-preview:image',
876+
type: 'image',
877+
description:
878+
'Nano Banana 是 Google 最新、最快、最高效的原生多模态模型,它允许您通过对话生成和编辑图像。',
879+
releasedAt: '2025-08-26',
818880
parameters: CHAT_MODEL_IMAGE_GENERATION_PARAMS,
819881
pricing: {
820882
units: [
821883
{ name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },
822884
{ name: 'textOutput', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },
823-
{ name: 'imageOutput', rate: 3, strategy: 'fixed', unit: 'millionTokens' },
885+
{ name: 'imageOutput', rate: 30, strategy: 'fixed', unit: 'millionTokens' },
824886
],
825887
},
826888
},

packages/model-runtime/src/providers/google/createImage.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Content, GoogleGenAI, Part } from '@google/genai';
1+
import { Content, GenerateContentConfig, GoogleGenAI, Part } from '@google/genai';
22

33
import { convertGoogleAIUsage } from '../../core/usageConverters/google-ai';
44
import { CreateImagePayload, CreateImageResponse } from '../../types/image';
@@ -141,10 +141,19 @@ async function generateImageByChatModel(
141141
},
142142
];
143143

144+
const config: GenerateContentConfig = {
145+
responseModalities: ['Image'],
146+
...(params.aspectRatio
147+
? {
148+
imageConfig: {
149+
aspectRatio: params.aspectRatio,
150+
},
151+
}
152+
: {}),
153+
};
154+
144155
const response = await client.models.generateContent({
145-
config: {
146-
responseModalities: ['Image'],
147-
},
156+
config,
148157
contents,
149158
model: actualModel,
150159
});

0 commit comments

Comments
 (0)