Skip to content

Commit c3ec037

Browse files
committed
feat(vertexai): Migrate to GenAI and add GoogleAI support
1 parent 0cbff6b commit c3ec037

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2501
-611
lines changed

.changeset/tall-zoos-stare.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'firebase': minor
3+
'@firebase/vertexai': minor
4+
---
5+
6+
Add support for the Google AI API, enabling usage in a free tier, and migrate from `VertexAI` naming to `GenAI`.

common/api-review/vertexai.api.md

Lines changed: 95 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ export class ArraySchema extends Schema {
1818
toJSON(): SchemaRequest;
1919
}
2020

21+
// @public
22+
export type Backend = GoogleAIBackend | VertexAIBackend;
23+
24+
// @public
25+
export const BackendType: {
26+
readonly VERTEX_AI: "VERTEX_AI";
27+
readonly GOOGLE_AI: "GOOGLE_AI";
28+
};
29+
30+
// @public
31+
export type BackendType = (typeof BackendType)[keyof typeof BackendType];
32+
2133
// @public
2234
export interface BaseParams {
2335
// (undocumented)
@@ -239,6 +251,60 @@ export interface FunctionResponsePart {
239251
text?: never;
240252
}
241253

254+
// @public
255+
export interface GenAI {
256+
app: FirebaseApp;
257+
backend: Backend;
258+
// @deprecated
259+
location: string;
260+
}
261+
262+
// @public
263+
export class GenAIError extends FirebaseError {
264+
constructor(code: GenAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined);
265+
// (undocumented)
266+
readonly code: GenAIErrorCode;
267+
// (undocumented)
268+
readonly customErrorData?: CustomErrorData | undefined;
269+
}
270+
271+
// @public
272+
const enum GenAIErrorCode {
273+
API_NOT_ENABLED = "api-not-enabled",
274+
ERROR = "error",
275+
FETCH_ERROR = "fetch-error",
276+
INVALID_CONTENT = "invalid-content",
277+
INVALID_SCHEMA = "invalid-schema",
278+
NO_API_KEY = "no-api-key",
279+
NO_APP_ID = "no-app-id",
280+
NO_MODEL = "no-model",
281+
NO_PROJECT_ID = "no-project-id",
282+
PARSE_FAILED = "parse-failed",
283+
REQUEST_ERROR = "request-error",
284+
RESPONSE_ERROR = "response-error",
285+
UNSUPPORTED = "unsupported"
286+
}
287+
288+
export { GenAIErrorCode }
289+
290+
export { GenAIErrorCode as VertexAIErrorCode }
291+
292+
// @public
293+
export abstract class GenAIModel {
294+
// @internal
295+
protected constructor(genAI: GenAI, modelName: string);
296+
// @internal (undocumented)
297+
protected _apiSettings: ApiSettings;
298+
readonly model: string;
299+
// @internal
300+
static normalizeModelName(modelName: string, backendType: BackendType): string;
301+
}
302+
303+
// @public
304+
export interface GenAIOptions {
305+
backend: Backend;
306+
}
307+
242308
// @public
243309
export interface GenerateContentCandidate {
244310
// (undocumented)
@@ -323,8 +389,8 @@ export interface GenerativeContentBlob {
323389
}
324390

325391
// @public
326-
export class GenerativeModel extends VertexAIModel {
327-
constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions);
392+
export class GenerativeModel extends GenAIModel {
393+
constructor(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions);
328394
countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
329395
generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
330396
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
@@ -344,14 +410,25 @@ export class GenerativeModel extends VertexAIModel {
344410
}
345411

346412
// @public
347-
export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;
413+
export function getGenAI(app?: FirebaseApp, options?: GenAIOptions): GenAI;
414+
415+
// @public
416+
export function getGenerativeModel(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;
348417

349418
// @beta
350-
export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
419+
export function getImagenModel(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
351420

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

424+
// @public
425+
export type GoogleAIBackend = {
426+
backendType: typeof BackendType.GOOGLE_AI;
427+
};
428+
429+
// @public
430+
export function googleAIBackend(): GoogleAIBackend;
431+
355432
// @public @deprecated (undocumented)
356433
export interface GroundingAttribution {
357434
// (undocumented)
@@ -374,7 +451,7 @@ export interface GroundingMetadata {
374451
webSearchQueries?: string[];
375452
}
376453

377-
// @public (undocumented)
454+
// @public
378455
export enum HarmBlockMethod {
379456
PROBABILITY = "PROBABILITY",
380457
SEVERITY = "SEVERITY"
@@ -413,7 +490,8 @@ export enum HarmSeverity {
413490
HARM_SEVERITY_HIGH = "HARM_SEVERITY_HIGH",
414491
HARM_SEVERITY_LOW = "HARM_SEVERITY_LOW",
415492
HARM_SEVERITY_MEDIUM = "HARM_SEVERITY_MEDIUM",
416-
HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE"
493+
HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE",
494+
HARM_SEVERITY_UNSUPPORTED = "HARM_SEVERITY_UNSUPPORTED"
417495
}
418496

419497
// @beta
@@ -461,8 +539,8 @@ export interface ImagenInlineImage {
461539
}
462540

463541
// @beta
464-
export class ImagenModel extends VertexAIModel {
465-
constructor(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined);
542+
export class ImagenModel extends GenAIModel {
543+
constructor(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined);
466544
generateImages(prompt: string): Promise<ImagenGenerationResponse<ImagenInlineImage>>;
467545
// @internal
468546
generateImagesGCS(prompt: string, gcsURI: string): Promise<ImagenGenerationResponse<ImagenGCSImage>>;
@@ -627,7 +705,6 @@ export interface SafetyRating {
627705
export interface SafetySetting {
628706
// (undocumented)
629707
category: HarmCategory;
630-
// (undocumented)
631708
method?: HarmBlockMethod;
632709
// (undocumented)
633710
threshold: HarmBlockThreshold;
@@ -779,46 +856,22 @@ export interface UsageMetadata {
779856
}
780857

781858
// @public
782-
export interface VertexAI {
783-
app: FirebaseApp;
784-
// (undocumented)
859+
export type VertexAI = GenAI;
860+
861+
// @public
862+
export type VertexAIBackend = {
863+
backendType: typeof BackendType.VERTEX_AI;
785864
location: string;
786-
}
865+
};
787866

788867
// @public
789-
export class VertexAIError extends FirebaseError {
790-
constructor(code: VertexAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined);
791-
// (undocumented)
792-
readonly code: VertexAIErrorCode;
793-
// (undocumented)
794-
readonly customErrorData?: CustomErrorData | undefined;
795-
}
868+
export function vertexAIBackend(location?: string): VertexAIBackend;
796869

797870
// @public
798-
export const enum VertexAIErrorCode {
799-
API_NOT_ENABLED = "api-not-enabled",
800-
ERROR = "error",
801-
FETCH_ERROR = "fetch-error",
802-
INVALID_CONTENT = "invalid-content",
803-
INVALID_SCHEMA = "invalid-schema",
804-
NO_API_KEY = "no-api-key",
805-
NO_APP_ID = "no-app-id",
806-
NO_MODEL = "no-model",
807-
NO_PROJECT_ID = "no-project-id",
808-
PARSE_FAILED = "parse-failed",
809-
REQUEST_ERROR = "request-error",
810-
RESPONSE_ERROR = "response-error"
811-
}
871+
export const VertexAIError: typeof GenAIError;
812872

813873
// @public
814-
export abstract class VertexAIModel {
815-
// @internal
816-
protected constructor(vertexAI: VertexAI, modelName: string);
817-
// @internal (undocumented)
818-
protected _apiSettings: ApiSettings;
819-
readonly model: string;
820-
static normalizeModelName(modelName: string): string;
821-
}
874+
export const VertexAIModel: typeof GenAIModel;
822875

823876
// @public
824877
export interface VertexAIOptions {

docs-devsite/_toc.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,14 @@ toc:
516516
path: /docs/reference/js/vertexai.functionresponse.md
517517
- title: FunctionResponsePart
518518
path: /docs/reference/js/vertexai.functionresponsepart.md
519+
- title: GenAI
520+
path: /docs/reference/js/vertexai.genai.md
521+
- title: GenAIError
522+
path: /docs/reference/js/vertexai.genaierror.md
523+
- title: GenAIModel
524+
path: /docs/reference/js/vertexai.genaimodel.md
525+
- title: GenAIOptions
526+
path: /docs/reference/js/vertexai.genaioptions.md
519527
- title: GenerateContentCandidate
520528
path: /docs/reference/js/vertexai.generatecontentcandidate.md
521529
- title: GenerateContentRequest
@@ -598,12 +606,6 @@ toc:
598606
path: /docs/reference/js/vertexai.toolconfig.md
599607
- title: UsageMetadata
600608
path: /docs/reference/js/vertexai.usagemetadata.md
601-
- title: VertexAI
602-
path: /docs/reference/js/vertexai.vertexai.md
603-
- title: VertexAIError
604-
path: /docs/reference/js/vertexai.vertexaierror.md
605-
- title: VertexAIModel
606-
path: /docs/reference/js/vertexai.vertexaimodel.md
607609
- title: VertexAIOptions
608610
path: /docs/reference/js/vertexai.vertexaioptions.md
609611
- title: VideoMetadata

docs-devsite/vertexai.genai.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# GenAI interface
13+
An instance of the Firebase GenAI SDK.
14+
15+
Do not create this instance directly. Instead, use [getGenAI()](./vertexai.md#getgenai_65c48ee)<!-- -->.
16+
17+
<b>Signature:</b>
18+
19+
```typescript
20+
export interface GenAI
21+
```
22+
23+
## Properties
24+
25+
| Property | Type | Description |
26+
| --- | --- | --- |
27+
| [app](./vertexai.genai.md#genaiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [GenAI](./vertexai.genai.md#genai_interface) instance is associated with. |
28+
| [backend](./vertexai.genai.md#genaibackend) | [Backend](./vertexai.md#backend) | A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. |
29+
| [location](./vertexai.genai.md#genailocation) | string | The location configured for this GenAI service instance, relevant for Vertex AI backends. |
30+
31+
## GenAI.app
32+
33+
The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [GenAI](./vertexai.genai.md#genai_interface) instance is associated with.
34+
35+
<b>Signature:</b>
36+
37+
```typescript
38+
app: FirebaseApp;
39+
```
40+
41+
## GenAI.backend
42+
43+
A [Backend](./vertexai.md#backend) instance that specifies the backend configuration.
44+
45+
<b>Signature:</b>
46+
47+
```typescript
48+
backend: Backend;
49+
```
50+
51+
## GenAI.location
52+
53+
> Warning: This API is now obsolete.
54+
>
55+
> use `GenAI.backend.location` instead.
56+
>
57+
58+
The location configured for this GenAI service instance, relevant for Vertex AI backends.
59+
60+
<b>Signature:</b>
61+
62+
```typescript
63+
location: string;
64+
```

docs-devsite/vertexai.vertexaierror.md renamed to docs-devsite/vertexai.genaierror.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,56 @@ overwritten. Changes should be made in the source code at
99
https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

12-
# VertexAIError class
12+
# GenAIError class
1313
Error class for the Vertex AI in Firebase SDK.
1414

1515
<b>Signature:</b>
1616

1717
```typescript
18-
export declare class VertexAIError extends FirebaseError
18+
export declare class GenAIError extends FirebaseError
1919
```
2020
<b>Extends:</b> [FirebaseError](./util.firebaseerror.md#firebaseerror_class)
2121
2222
## Constructors
2323
2424
| Constructor | Modifiers | Description |
2525
| --- | --- | --- |
26-
| [(constructor)(code, message, customErrorData)](./vertexai.vertexaierror.md#vertexaierrorconstructor) | | Constructs a new instance of the <code>VertexAIError</code> class. |
26+
| [(constructor)(code, message, customErrorData)](./vertexai.genaierror.md#genaierrorconstructor) | | Constructs a new instance of the <code>GenAIError</code> class. |
2727
2828
## Properties
2929
3030
| Property | Modifiers | Type | Description |
3131
| --- | --- | --- | --- |
32-
| [code](./vertexai.vertexaierror.md#vertexaierrorcode) | | [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | |
33-
| [customErrorData](./vertexai.vertexaierror.md#vertexaierrorcustomerrordata) | | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | |
32+
| [code](./vertexai.genaierror.md#genaierrorcode) | | [GenAIErrorCode](./vertexai.md#genaierrorcode) | |
33+
| [customErrorData](./vertexai.genaierror.md#genaierrorcustomerrordata) | | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | |
3434
35-
## VertexAIError.(constructor)
35+
## GenAIError.(constructor)
3636
37-
Constructs a new instance of the `VertexAIError` class.
37+
Constructs a new instance of the `GenAIError` class.
3838
3939
<b>Signature:</b>
4040
4141
```typescript
42-
constructor(code: VertexAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined);
42+
constructor(code: GenAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined);
4343
```
4444
4545
#### Parameters
4646
4747
| Parameter | Type | Description |
4848
| --- | --- | --- |
49-
| code | [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | The error code from [VertexAIErrorCode](./vertexai.md#vertexaierrorcode)<!-- -->. |
49+
| code | [GenAIErrorCode](./vertexai.md#genaierrorcode) | The error code from [GenAIErrorCode](./vertexai.md#genaierrorcode)<!-- -->. |
5050
| message | string | A human-readable message describing the error. |
5151
| customErrorData | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | Optional error data. |
5252
53-
## VertexAIError.code
53+
## GenAIError.code
5454
5555
<b>Signature:</b>
5656
5757
```typescript
58-
readonly code: VertexAIErrorCode;
58+
readonly code: GenAIErrorCode;
5959
```
6060
61-
## VertexAIError.customErrorData
61+
## GenAIError.customErrorData
6262
6363
<b>Signature:</b>
6464

0 commit comments

Comments
 (0)