Skip to content

Commit 8c14c71

Browse files
feat(ai): Add imageconfig and new finishreasons for image generation
Adds new `FinishReason` enum values for various image generation scenarios to provide more granular information when a generation request finishes. Also introduces a new `ImageConfig` interface and a corresponding `AspectRatio` enum. This allows specifying image-related configurations, like aspect ratio, within the main `GenerationConfig`.
1 parent ccbf7ba commit 8c14c71

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

packages/ai/src/types/enums.ts

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,28 @@ export const FinishReason = {
238238
/**
239239
* The function call generated by the model was invalid.
240240
*/
241-
MALFORMED_FUNCTION_CALL: 'MALFORMED_FUNCTION_CALL'
241+
MALFORMED_FUNCTION_CALL: 'MALFORMED_FUNCTION_CALL',
242+
/**
243+
* Image generation stopped due to safety settings.
244+
*/
245+
IMAGE_SAFETY: 'IMAGE_SAFETY',
246+
/**
247+
* Image generation stopped because generated images has other prohibited
248+
* content.
249+
*/
250+
IMAGE_PROHIBITED_CONTENT: 'IMAGE_PROHIBITED_CONTENT',
251+
/**
252+
* Image generation stopped due to recitation.
253+
*/
254+
IMAGE_RECITATION: 'IMAGE_RECITATION',
255+
/**
256+
* Image generation stopped because of other miscellaneous issue.
257+
*/
258+
IMAGE_OTHER: 'IMAGE_OTHER',
259+
/**
260+
* The model was expected to generate an image, but none was generated.
261+
*/
262+
NO_IMAGE: 'NO_IMAGE'
242263
} as const;
243264

244265
/**
@@ -414,3 +435,56 @@ export const Language = {
414435
* @beta
415436
*/
416437
export type Language = (typeof Language)[keyof typeof Language];
438+
439+
/**
440+
* Aspect ratios for generated images.
441+
* @public
442+
*/
443+
export const AspectRatio = {
444+
/**
445+
* Square (1:1) aspect ratio.
446+
*/
447+
SQUARE_1x1: '1:1',
448+
/**
449+
* Portrait (2:3) aspect ratio.
450+
*/
451+
PORTRAIT_2x3: '2:3',
452+
/**
453+
* Landscape (3:2) aspect ratio.
454+
*/
455+
LANDSCAPE_3x2: '3:2',
456+
/**
457+
* Portrait (3:4) aspect ratio.
458+
*/
459+
PORTRAIT_3x4: '3:4',
460+
/**
461+
* Landscape (4:3) aspect ratio.
462+
*/
463+
LANDSCAPE_4x3: '4:3',
464+
/**
465+
* Portrait (4:5) aspect ratio.
466+
*/
467+
PORTRAIT_4x5: '4:5',
468+
/**
469+
* Landscape (5:4) aspect ratio.
470+
*/
471+
LANDSCAPE_5x4: '5:4',
472+
/**
473+
* Portrait (9:16) aspect ratio.
474+
*/
475+
PORTRAIT_9x16: '9:16',
476+
/**
477+
* Landscape (16:9) aspect ratio.
478+
*/
479+
LANDSCAPE_16x9: '16:9',
480+
/**
481+
* Landscape (21:9) aspect ratio.
482+
*/
483+
LANDSCAPE_21x9: '21:9'
484+
} as const;
485+
486+
/**
487+
* Aspect ratios for generated images.
488+
* @public
489+
*/
490+
export type AspectRatio = (typeof AspectRatio)[keyof typeof AspectRatio];

packages/ai/src/types/requests.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
LanguageModelPromptOptions
2323
} from './language-model';
2424
import {
25+
AspectRatio,
2526
FunctionCallingMode,
2627
HarmBlockMethod,
2728
HarmBlockThreshold,
@@ -133,6 +134,12 @@ export interface GenerationConfig {
133134
* Configuration for "thinking" behavior of compatible Gemini models.
134135
*/
135136
thinkingConfig?: ThinkingConfig;
137+
/**
138+
* Configuration for image generation.
139+
*
140+
* @beta
141+
*/
142+
imageConfig?: ImageConfig;
136143
}
137144

138145
/**
@@ -441,6 +448,17 @@ export interface ThinkingConfig {
441448
includeThoughts?: boolean;
442449
}
443450

451+
/**
452+
* Configuration for image generation.
453+
* @public
454+
*/
455+
export interface ImageConfig {
456+
/**
457+
* The aspect ratio of the generated images.
458+
*/
459+
aspectRatio?: AspectRatio;
460+
}
461+
444462
/**
445463
* Configuration for a pre-built voice.
446464
*

0 commit comments

Comments
 (0)