Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Image Generation support using Imagen #8683

Merged
merged 37 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ec35231
WIP
dlarocque Dec 9, 2024
180f091
Introduce VertexAIModel base class, add documentation, and respond to…
dlarocque Jan 2, 2025
497727f
Generate devsite docs
dlarocque Jan 2, 2025
8471bbc
revert dataconnect change
dlarocque Jan 2, 2025
5c518b1
formatting
dlarocque Jan 2, 2025
b680a2a
WIP
dlarocque Dec 9, 2024
d00cccd
Introduce VertexAIModel base class, add documentation, and respond to…
dlarocque Jan 2, 2025
4b6c42f
Generate devsite docs
dlarocque Jan 2, 2025
6215781
revert dataconnect change
dlarocque Jan 2, 2025
025035a
formatting
dlarocque Jan 2, 2025
2f8b45d
Fix ImagenRequestConfig comment
dlarocque Jan 3, 2025
89a73de
Improve tests
dlarocque Jan 3, 2025
a0c8c89
Merge branch 'dl/vertex-imagen' of https://github.com/firebase/fireba…
dlarocque Jan 3, 2025
80021f9
Formatting
dlarocque Jan 3, 2025
858f260
Add ImagenGenerationResponse
dlarocque Jan 9, 2025
bfc2c0f
Formatting
dlarocque Jan 9, 2025
886a4df
Update to match API changes
dlarocque Jan 21, 2025
b8dd77e
Merge branch 'main' into dl/vertex-imagen
dlarocque Jan 22, 2025
d967900
fixes
dlarocque Feb 3, 2025
d53d3dd
format
dlarocque Feb 3, 2025
ae0f87e
Update API reports
dlarocque Feb 3, 2025
37aa71a
add changeset
dlarocque Feb 3, 2025
f7f919d
Merge branch 'main' into dl/vertex-imagen
dlarocque Feb 6, 2025
ece898f
update
dlarocque Feb 6, 2025
967cd78
format
dlarocque Feb 6, 2025
b27a45e
Update API reports
dlarocque Feb 6, 2025
f095563
remove public docs
dlarocque Feb 7, 2025
0cd9ae4
Merge branch 'main' into dl/vertex-imagen
dlarocque Feb 7, 2025
d6a4f24
Nest imageFormat in outputOptions
dlarocque Feb 10, 2025
66b3b9f
remove unecessary console.log
dlarocque Feb 10, 2025
48b658d
Log warning if compressionQuality outside of range
dlarocque Feb 11, 2025
c3173a9
format
dlarocque Feb 11, 2025
a33e819
Merge branch 'main' into dl/vertex-imagen
dlarocque Feb 12, 2025
0e9ff0a
Merge branch 'main' into dl/vertex-imagen
dlarocque Feb 13, 2025
0900f82
Imagen Documentation (#8776)
dlarocque Feb 20, 2025
5e7df2f
Cleanup
dlarocque Feb 20, 2025
4a306fa
update changeset
dlarocque Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/violet-planets-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'firebase': minor
'@firebase/vertexai': minor
---

Add Image Generation support using Imagen.
137 changes: 134 additions & 3 deletions common/api-review/vertexai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,14 @@ export interface GenerativeContentBlob {
}

// @public
export class GenerativeModel {
export class GenerativeModel extends VertexAIModel {
constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions);
countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
// (undocumented)
generationConfig: GenerationConfig;
// (undocumented)
model: string;
// (undocumented)
requestOptions?: RequestOptions;
// (undocumented)
safetySettings: SafetySetting[];
Expand All @@ -348,6 +346,9 @@ export class GenerativeModel {
// @public
export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;

// @public (undocumented)
export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;

// @public
export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI;

Expand Down Expand Up @@ -429,6 +430,125 @@ export enum HarmSeverity {
HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE"
}

// @public (undocumented)
export enum ImagenAspectRatio {
// (undocumented)
LANDSCAPE_16x9 = "16:9",
// (undocumented)
LANDSCAPE_3x4 = "3:4",
// (undocumented)
PORTRAIT_4x3 = "4:3",
// (undocumented)
PORTRAIT_9x16 = "9:16",
// (undocumented)
SQUARE = "1:1"
}

// @public (undocumented)
export interface ImagenGCSImage {
// (undocumented)
gcsURI: string;
// (undocumented)
mimeType: string;
}

// @public (undocumented)
export interface ImagenGenerationConfig {
// (undocumented)
addWatermark?: boolean;
// (undocumented)
aspectRatio?: ImagenAspectRatio;
// (undocumented)
imageFormat?: ImagenImageFormat;
// (undocumented)
negativePrompt?: string;
// (undocumented)
numberOfImages?: number;
}

// @public (undocumented)
export interface ImagenGenerationResponse<T extends ImagenInlineImage | ImagenGCSImage> {
// (undocumented)
filteredReason?: string;
// (undocumented)
images: T[];
}

// @public
export class ImagenImageFormat {
// (undocumented)
compressionQuality?: number;
// (undocumented)
static jpeg(compressionQuality?: number): ImagenImageFormat;
// (undocumented)
mimeType: string;
// (undocumented)
static png(): ImagenImageFormat;
}

// @public
export interface ImagenInlineImage {
// (undocumented)
bytesBase64Encoded: string;
// (undocumented)
mimeType: string;
}

// @public (undocumented)
export class ImagenModel extends VertexAIModel {
constructor(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined);
// (undocumented)
generateImages(prompt: string): Promise<ImagenGenerationResponse<ImagenInlineImage>>;
// (undocumented)
generateImagesGCS(prompt: string, gcsURI: string): Promise<ImagenGenerationResponse<ImagenGCSImage>>;
// (undocumented)
generationConfig?: ImagenGenerationConfig;
// (undocumented)
requestOptions?: RequestOptions | undefined;
// (undocumented)
safetySettings?: ImagenSafetySettings;
}

// @public (undocumented)
export interface ImagenModelParams {
// (undocumented)
generationConfig?: ImagenGenerationConfig;
// (undocumented)
model: string;
// (undocumented)
safetySettings?: ImagenSafetySettings;
}

// @public (undocumented)
export enum ImagenPersonFilterLevel {
// (undocumented)
ALLOW_ADULT = "allow_adult",
// (undocumented)
ALLOW_ALL = "allow_all",
// (undocumented)
BLOCK_ALL = "dont_allow"
}

// @public (undocumented)
export enum ImagenSafetyFilterLevel {
// (undocumented)
BLOCK_LOW_AND_ABOVE = "block_low_and_above",
// (undocumented)
BLOCK_MEDIUM_AND_ABOVE = "block_medium_and_above",
// (undocumented)
BLOCK_NONE = "block_none",
// (undocumented)
BLOCK_ONLY_HIGH = "block_only_high"
}

// @public (undocumented)
export interface ImagenSafetySettings {
// (undocumented)
personFilterLevel?: ImagenPersonFilterLevel;
// (undocumented)
safetyFilterLevel?: ImagenSafetyFilterLevel;
}

// @public
export interface InlineDataPart {
// (undocumented)
Expand Down Expand Up @@ -718,6 +838,17 @@ export const enum VertexAIErrorCode {
RESPONSE_ERROR = "response-error"
}

// @public (undocumented)
export abstract class VertexAIModel {
// @internal
protected constructor(vertexAI: VertexAI, modelName: string);
// @internal (undocumented)
protected _apiSettings: ApiSettings;
// (undocumented)
readonly model: string;
static normalizeModelName(modelName: string): string;
}

// @public
export interface VertexAIOptions {
// (undocumented)
Expand Down
18 changes: 18 additions & 0 deletions docs-devsite/_toc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,22 @@ toc:
path: /docs/reference/js/vertexai.groundingattribution.md
- title: GroundingMetadata
path: /docs/reference/js/vertexai.groundingmetadata.md
- title: ImagenGCSImage
path: /docs/reference/js/vertexai.imagengcsimage.md
- title: ImagenGenerationConfig
path: /docs/reference/js/vertexai.imagengenerationconfig.md
- title: ImagenGenerationResponse
path: /docs/reference/js/vertexai.imagengenerationresponse.md
- title: ImagenImageFormat
path: /docs/reference/js/vertexai.imagenimageformat.md
- title: ImagenInlineImage
path: /docs/reference/js/vertexai.imageninlineimage.md
- title: ImagenModel
path: /docs/reference/js/vertexai.imagenmodel.md
- title: ImagenModelParams
path: /docs/reference/js/vertexai.imagenmodelparams.md
- title: ImagenSafetySettings
path: /docs/reference/js/vertexai.imagensafetysettings.md
- title: InlineDataPart
path: /docs/reference/js/vertexai.inlinedatapart.md
- title: IntegerSchema
Expand Down Expand Up @@ -578,6 +594,8 @@ toc:
path: /docs/reference/js/vertexai.vertexai.md
- title: VertexAIError
path: /docs/reference/js/vertexai.vertexaierror.md
- title: VertexAIModel
path: /docs/reference/js/vertexai.vertexaimodel.md
- title: VertexAIOptions
path: /docs/reference/js/vertexai.vertexaioptions.md
- title: VideoMetadata
Expand Down
12 changes: 2 additions & 10 deletions docs-devsite/vertexai.generativemodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Class for generative model APIs.
<b>Signature:</b>

```typescript
export declare class GenerativeModel
export declare class GenerativeModel extends VertexAIModel
```
<b>Extends:</b> [VertexAIModel](./vertexai.vertexaimodel.md#vertexaimodel_class)

## Constructors

Expand All @@ -29,7 +30,6 @@ export declare class GenerativeModel
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [generationConfig](./vertexai.generativemodel.md#generativemodelgenerationconfig) | | [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | |
| [model](./vertexai.generativemodel.md#generativemodelmodel) | | string | |
| [requestOptions](./vertexai.generativemodel.md#generativemodelrequestoptions) | | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | |
| [safetySettings](./vertexai.generativemodel.md#generativemodelsafetysettings) | | [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface)<!-- -->\[\] | |
| [systemInstruction](./vertexai.generativemodel.md#generativemodelsysteminstruction) | | [Content](./vertexai.content.md#content_interface) | |
Expand Down Expand Up @@ -71,14 +71,6 @@ constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: Reque
generationConfig: GenerationConfig;
```

## GenerativeModel.model

<b>Signature:</b>

```typescript
model: string;
```

## GenerativeModel.requestOptions

<b>Signature:</b>
Expand Down
40 changes: 40 additions & 0 deletions docs-devsite/vertexai.imagengcsimage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference

{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# ImagenGCSImage interface
<b>Signature:</b>

```typescript
export interface ImagenGCSImage
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [gcsURI](./vertexai.imagengcsimage.md#imagengcsimagegcsuri) | string | |
| [mimeType](./vertexai.imagengcsimage.md#imagengcsimagemimetype) | string | |

## ImagenGCSImage.gcsURI

<b>Signature:</b>

```typescript
gcsURI: string;
```

## ImagenGCSImage.mimeType

<b>Signature:</b>

```typescript
mimeType: string;
```
67 changes: 67 additions & 0 deletions docs-devsite/vertexai.imagengenerationconfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference

{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# ImagenGenerationConfig interface
<b>Signature:</b>

```typescript
export interface ImagenGenerationConfig
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [addWatermark](./vertexai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | |
| [aspectRatio](./vertexai.imagengenerationconfig.md#imagengenerationconfigaspectratio) | [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | |
| [imageFormat](./vertexai.imagengenerationconfig.md#imagengenerationconfigimageformat) | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | |
| [negativePrompt](./vertexai.imagengenerationconfig.md#imagengenerationconfignegativeprompt) | string | |
| [numberOfImages](./vertexai.imagengenerationconfig.md#imagengenerationconfignumberofimages) | number | |

## ImagenGenerationConfig.addWatermark

<b>Signature:</b>

```typescript
addWatermark?: boolean;
```

## ImagenGenerationConfig.aspectRatio

<b>Signature:</b>

```typescript
aspectRatio?: ImagenAspectRatio;
```

## ImagenGenerationConfig.imageFormat

<b>Signature:</b>

```typescript
imageFormat?: ImagenImageFormat;
```

## ImagenGenerationConfig.negativePrompt

<b>Signature:</b>

```typescript
negativePrompt?: string;
```

## ImagenGenerationConfig.numberOfImages

<b>Signature:</b>

```typescript
numberOfImages?: number;
```
40 changes: 40 additions & 0 deletions docs-devsite/vertexai.imagengenerationresponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference

{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# ImagenGenerationResponse interface
<b>Signature:</b>

```typescript
export interface ImagenGenerationResponse<T extends ImagenInlineImage | ImagenGCSImage>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [filteredReason](./vertexai.imagengenerationresponse.md#imagengenerationresponsefilteredreason) | string | |
| [images](./vertexai.imagengenerationresponse.md#imagengenerationresponseimages) | T\[\] | |

## ImagenGenerationResponse.filteredReason

<b>Signature:</b>

```typescript
filteredReason?: string;
```

## ImagenGenerationResponse.images

<b>Signature:</b>

```typescript
images: T[];
```
Loading
Loading