From c3ec037c78827e4e0758b159e0fcb30e5109069d Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 15 Apr 2025 12:35:05 -0400 Subject: [PATCH 01/32] feat(vertexai): Migrate to `GenAI` and add GoogleAI support --- .changeset/tall-zoos-stare.md | 6 + common/api-review/vertexai.api.md | 137 ++++-- docs-devsite/_toc.yaml | 14 +- docs-devsite/vertexai.genai.md | 64 +++ ...ertexaierror.md => vertexai.genaierror.md} | 24 +- docs-devsite/vertexai.genaimodel.md | 37 ++ docs-devsite/vertexai.genaioptions.md | 35 ++ docs-devsite/vertexai.generativemodel.md | 10 +- .../vertexai.imagengenerationconfig.md | 2 + docs-devsite/vertexai.imagenmodel.md | 12 +- docs-devsite/vertexai.md | 299 +++++++++++-- docs-devsite/vertexai.modelparams.md | 2 +- docs-devsite/vertexai.requestoptions.md | 2 +- docs-devsite/vertexai.safetysetting.md | 4 +- docs-devsite/vertexai.schemashared.md | 4 +- docs-devsite/vertexai.vertexai.md | 44 -- docs-devsite/vertexai.vertexaimodel.md | 66 --- packages/firebase/package.json | 12 + packages/vertexai/.eslintrc.js | 3 +- packages/vertexai/src/api.test.ts | 126 +++--- packages/vertexai/src/api.ts | 150 ++++++- .../src/backwards-compatbility.test.ts | 85 ++++ packages/vertexai/src/constants.ts | 9 + packages/vertexai/src/errors.ts | 20 +- packages/vertexai/src/googleAIMappers.test.ts | 400 ++++++++++++++++++ packages/vertexai/src/googleAIMappers.ts | 235 ++++++++++ packages/vertexai/src/helpers.test.ts | 140 ++++++ packages/vertexai/src/helpers.ts | 86 ++++ packages/vertexai/src/index.node.ts | 28 +- packages/vertexai/src/index.ts | 27 +- .../src/methods/chat-session-helpers.ts | 34 +- .../vertexai/src/methods/chat-session.test.ts | 4 +- .../vertexai/src/methods/count-tokens.test.ts | 41 +- packages/vertexai/src/methods/count-tokens.ts | 11 +- .../src/methods/generate-content.test.ts | 95 ++++- .../vertexai/src/methods/generate-content.ts | 31 +- ...exai-model.test.ts => genai-model.test.ts} | 51 +-- .../{vertexai-model.ts => genai-model.ts} | 90 ++-- .../src/models/generative-model.test.ts | 20 +- .../vertexai/src/models/generative-model.ts | 10 +- .../vertexai/src/models/imagen-model.test.ts | 22 +- packages/vertexai/src/models/imagen-model.ts | 14 +- packages/vertexai/src/models/index.ts | 2 +- packages/vertexai/src/public-types.ts | 126 +++++- .../vertexai/src/requests/request-helpers.ts | 12 +- .../vertexai/src/requests/request.test.ts | 72 ++-- packages/vertexai/src/requests/request.ts | 67 +-- .../vertexai/src/requests/response-helpers.ts | 28 +- .../src/requests/schema-builder.test.ts | 4 +- .../vertexai/src/requests/schema-builder.ts | 8 +- .../src/requests/stream-reader.test.ts | 44 +- .../vertexai/src/requests/stream-reader.ts | 58 ++- packages/vertexai/src/service.test.ts | 18 +- packages/vertexai/src/service.ts | 18 +- packages/vertexai/src/types/enums.ts | 11 +- packages/vertexai/src/types/error.ts | 9 +- packages/vertexai/src/types/googleAI/index.ts | 19 + .../vertexai/src/types/googleAI/requests.ts | 29 ++ .../vertexai/src/types/googleAI/responses.ts | 46 ++ .../vertexai/src/types/imagen/requests.ts | 3 + packages/vertexai/src/types/internal.ts | 9 +- packages/vertexai/src/types/requests.ts | 5 + packages/vertexai/src/types/responses.ts | 10 +- packages/vertexai/src/types/schema.ts | 5 +- packages/vertexai/test-utils/mock-response.ts | 3 + 65 files changed, 2501 insertions(+), 611 deletions(-) create mode 100644 .changeset/tall-zoos-stare.md create mode 100644 docs-devsite/vertexai.genai.md rename docs-devsite/{vertexai.vertexaierror.md => vertexai.genaierror.md} (53%) create mode 100644 docs-devsite/vertexai.genaimodel.md create mode 100644 docs-devsite/vertexai.genaioptions.md delete mode 100644 docs-devsite/vertexai.vertexai.md delete mode 100644 docs-devsite/vertexai.vertexaimodel.md create mode 100644 packages/vertexai/src/backwards-compatbility.test.ts create mode 100644 packages/vertexai/src/googleAIMappers.test.ts create mode 100644 packages/vertexai/src/googleAIMappers.ts create mode 100644 packages/vertexai/src/helpers.test.ts create mode 100644 packages/vertexai/src/helpers.ts rename packages/vertexai/src/models/{vertexai-model.test.ts => genai-model.test.ts} (65%) rename packages/vertexai/src/models/{vertexai-model.ts => genai-model.ts} (61%) create mode 100644 packages/vertexai/src/types/googleAI/index.ts create mode 100644 packages/vertexai/src/types/googleAI/requests.ts create mode 100644 packages/vertexai/src/types/googleAI/responses.ts diff --git a/.changeset/tall-zoos-stare.md b/.changeset/tall-zoos-stare.md new file mode 100644 index 00000000000..f4e7601b4a4 --- /dev/null +++ b/.changeset/tall-zoos-stare.md @@ -0,0 +1,6 @@ +--- +'firebase': minor +'@firebase/vertexai': minor +--- + +Add support for the Google AI API, enabling usage in a free tier, and migrate from `VertexAI` naming to `GenAI`. diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index e7f00c2f4e0..66012360050 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -18,6 +18,18 @@ export class ArraySchema extends Schema { toJSON(): SchemaRequest; } +// @public +export type Backend = GoogleAIBackend | VertexAIBackend; + +// @public +export const BackendType: { + readonly VERTEX_AI: "VERTEX_AI"; + readonly GOOGLE_AI: "GOOGLE_AI"; +}; + +// @public +export type BackendType = (typeof BackendType)[keyof typeof BackendType]; + // @public export interface BaseParams { // (undocumented) @@ -239,6 +251,60 @@ export interface FunctionResponsePart { text?: never; } +// @public +export interface GenAI { + app: FirebaseApp; + backend: Backend; + // @deprecated + location: string; +} + +// @public +export class GenAIError extends FirebaseError { + constructor(code: GenAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); + // (undocumented) + readonly code: GenAIErrorCode; + // (undocumented) + readonly customErrorData?: CustomErrorData | undefined; +} + +// @public +const enum GenAIErrorCode { + API_NOT_ENABLED = "api-not-enabled", + ERROR = "error", + FETCH_ERROR = "fetch-error", + INVALID_CONTENT = "invalid-content", + INVALID_SCHEMA = "invalid-schema", + NO_API_KEY = "no-api-key", + NO_APP_ID = "no-app-id", + NO_MODEL = "no-model", + NO_PROJECT_ID = "no-project-id", + PARSE_FAILED = "parse-failed", + REQUEST_ERROR = "request-error", + RESPONSE_ERROR = "response-error", + UNSUPPORTED = "unsupported" +} + +export { GenAIErrorCode } + +export { GenAIErrorCode as VertexAIErrorCode } + +// @public +export abstract class GenAIModel { + // @internal + protected constructor(genAI: GenAI, modelName: string); + // @internal (undocumented) + protected _apiSettings: ApiSettings; + readonly model: string; + // @internal + static normalizeModelName(modelName: string, backendType: BackendType): string; + } + +// @public +export interface GenAIOptions { + backend: Backend; +} + // @public export interface GenerateContentCandidate { // (undocumented) @@ -323,8 +389,8 @@ export interface GenerativeContentBlob { } // @public -export class GenerativeModel extends VertexAIModel { - constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions); +export class GenerativeModel extends GenAIModel { + constructor(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions); countTokens(request: CountTokensRequest | string | Array): Promise; generateContent(request: GenerateContentRequest | string | Array): Promise; generateContentStream(request: GenerateContentRequest | string | Array): Promise; @@ -344,14 +410,25 @@ export class GenerativeModel extends VertexAIModel { } // @public -export function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; +export function getGenAI(app?: FirebaseApp, options?: GenAIOptions): GenAI; + +// @public +export function getGenerativeModel(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; // @beta -export function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; +export function getImagenModel(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; // @public export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; +// @public +export type GoogleAIBackend = { + backendType: typeof BackendType.GOOGLE_AI; +}; + +// @public +export function googleAIBackend(): GoogleAIBackend; + // @public @deprecated (undocumented) export interface GroundingAttribution { // (undocumented) @@ -374,7 +451,7 @@ export interface GroundingMetadata { webSearchQueries?: string[]; } -// @public (undocumented) +// @public export enum HarmBlockMethod { PROBABILITY = "PROBABILITY", SEVERITY = "SEVERITY" @@ -413,7 +490,8 @@ export enum HarmSeverity { HARM_SEVERITY_HIGH = "HARM_SEVERITY_HIGH", HARM_SEVERITY_LOW = "HARM_SEVERITY_LOW", HARM_SEVERITY_MEDIUM = "HARM_SEVERITY_MEDIUM", - HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE" + HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE", + HARM_SEVERITY_UNSUPPORTED = "HARM_SEVERITY_UNSUPPORTED" } // @beta @@ -461,8 +539,8 @@ export interface ImagenInlineImage { } // @beta -export class ImagenModel extends VertexAIModel { - constructor(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); +export class ImagenModel extends GenAIModel { + constructor(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); generateImages(prompt: string): Promise>; // @internal generateImagesGCS(prompt: string, gcsURI: string): Promise>; @@ -627,7 +705,6 @@ export interface SafetyRating { export interface SafetySetting { // (undocumented) category: HarmCategory; - // (undocumented) method?: HarmBlockMethod; // (undocumented) threshold: HarmBlockThreshold; @@ -779,46 +856,22 @@ export interface UsageMetadata { } // @public -export interface VertexAI { - app: FirebaseApp; - // (undocumented) +export type VertexAI = GenAI; + +// @public +export type VertexAIBackend = { + backendType: typeof BackendType.VERTEX_AI; location: string; -} +}; // @public -export class VertexAIError extends FirebaseError { - constructor(code: VertexAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); - // (undocumented) - readonly code: VertexAIErrorCode; - // (undocumented) - readonly customErrorData?: CustomErrorData | undefined; -} +export function vertexAIBackend(location?: string): VertexAIBackend; // @public -export const enum VertexAIErrorCode { - API_NOT_ENABLED = "api-not-enabled", - ERROR = "error", - FETCH_ERROR = "fetch-error", - INVALID_CONTENT = "invalid-content", - INVALID_SCHEMA = "invalid-schema", - NO_API_KEY = "no-api-key", - NO_APP_ID = "no-app-id", - NO_MODEL = "no-model", - NO_PROJECT_ID = "no-project-id", - PARSE_FAILED = "parse-failed", - REQUEST_ERROR = "request-error", - RESPONSE_ERROR = "response-error" -} +export const VertexAIError: typeof GenAIError; // @public -export abstract class VertexAIModel { - // @internal - protected constructor(vertexAI: VertexAI, modelName: string); - // @internal (undocumented) - protected _apiSettings: ApiSettings; - readonly model: string; - static normalizeModelName(modelName: string): string; -} +export const VertexAIModel: typeof GenAIModel; // @public export interface VertexAIOptions { diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index 665222edb9d..19ed87f1e54 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -516,6 +516,14 @@ toc: path: /docs/reference/js/vertexai.functionresponse.md - title: FunctionResponsePart path: /docs/reference/js/vertexai.functionresponsepart.md + - title: GenAI + path: /docs/reference/js/vertexai.genai.md + - title: GenAIError + path: /docs/reference/js/vertexai.genaierror.md + - title: GenAIModel + path: /docs/reference/js/vertexai.genaimodel.md + - title: GenAIOptions + path: /docs/reference/js/vertexai.genaioptions.md - title: GenerateContentCandidate path: /docs/reference/js/vertexai.generatecontentcandidate.md - title: GenerateContentRequest @@ -598,12 +606,6 @@ toc: path: /docs/reference/js/vertexai.toolconfig.md - title: UsageMetadata path: /docs/reference/js/vertexai.usagemetadata.md - - title: VertexAI - 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 diff --git a/docs-devsite/vertexai.genai.md b/docs-devsite/vertexai.genai.md new file mode 100644 index 00000000000..d8ce617941a --- /dev/null +++ b/docs-devsite/vertexai.genai.md @@ -0,0 +1,64 @@ +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 %} + +# GenAI interface +An instance of the Firebase GenAI SDK. + +Do not create this instance directly. Instead, use [getGenAI()](./vertexai.md#getgenai_65c48ee). + +Signature: + +```typescript +export interface GenAI +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [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. | +| [backend](./vertexai.genai.md#genaibackend) | [Backend](./vertexai.md#backend) | A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. | +| [location](./vertexai.genai.md#genailocation) | string | The location configured for this GenAI service instance, relevant for Vertex AI backends. | + +## GenAI.app + +The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [GenAI](./vertexai.genai.md#genai_interface) instance is associated with. + +Signature: + +```typescript +app: FirebaseApp; +``` + +## GenAI.backend + +A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. + +Signature: + +```typescript +backend: Backend; +``` + +## GenAI.location + +> Warning: This API is now obsolete. +> +> use `GenAI.backend.location` instead. +> + +The location configured for this GenAI service instance, relevant for Vertex AI backends. + +Signature: + +```typescript +location: string; +``` diff --git a/docs-devsite/vertexai.vertexaierror.md b/docs-devsite/vertexai.genaierror.md similarity index 53% rename from docs-devsite/vertexai.vertexaierror.md rename to docs-devsite/vertexai.genaierror.md index 31f527e59b3..eed0a54d264 100644 --- a/docs-devsite/vertexai.vertexaierror.md +++ b/docs-devsite/vertexai.genaierror.md @@ -9,13 +9,13 @@ overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %} -# VertexAIError class +# GenAIError class Error class for the Vertex AI in Firebase SDK. Signature: ```typescript -export declare class VertexAIError extends FirebaseError +export declare class GenAIError extends FirebaseError ``` Extends: [FirebaseError](./util.firebaseerror.md#firebaseerror_class) @@ -23,42 +23,42 @@ export declare class VertexAIError extends FirebaseError | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(code, message, customErrorData)](./vertexai.vertexaierror.md#vertexaierrorconstructor) | | Constructs a new instance of the VertexAIError class. | +| [(constructor)(code, message, customErrorData)](./vertexai.genaierror.md#genaierrorconstructor) | | Constructs a new instance of the GenAIError class. | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [code](./vertexai.vertexaierror.md#vertexaierrorcode) | | [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | | -| [customErrorData](./vertexai.vertexaierror.md#vertexaierrorcustomerrordata) | | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | | +| [code](./vertexai.genaierror.md#genaierrorcode) | | [GenAIErrorCode](./vertexai.md#genaierrorcode) | | +| [customErrorData](./vertexai.genaierror.md#genaierrorcustomerrordata) | | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | | -## VertexAIError.(constructor) +## GenAIError.(constructor) -Constructs a new instance of the `VertexAIError` class. +Constructs a new instance of the `GenAIError` class. Signature: ```typescript -constructor(code: VertexAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); +constructor(code: GenAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| code | [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | The error code from [VertexAIErrorCode](./vertexai.md#vertexaierrorcode). | +| code | [GenAIErrorCode](./vertexai.md#genaierrorcode) | The error code from [GenAIErrorCode](./vertexai.md#genaierrorcode). | | message | string | A human-readable message describing the error. | | customErrorData | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | Optional error data. | -## VertexAIError.code +## GenAIError.code Signature: ```typescript -readonly code: VertexAIErrorCode; +readonly code: GenAIErrorCode; ``` -## VertexAIError.customErrorData +## GenAIError.customErrorData Signature: diff --git a/docs-devsite/vertexai.genaimodel.md b/docs-devsite/vertexai.genaimodel.md new file mode 100644 index 00000000000..3d744a77e28 --- /dev/null +++ b/docs-devsite/vertexai.genaimodel.md @@ -0,0 +1,37 @@ +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 %} + +# GenAIModel class +Base class for Vertex AI in Firebase model APIs. + +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `GenAIModel` class. + +Signature: + +```typescript +export declare abstract class GenAIModel +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [model](./vertexai.genaimodel.md#genaimodelmodel) | | string | The fully qualified model resource name to use for generating images (for example, publishers/google/models/imagen-3.0-generate-002). | + +## GenAIModel.model + +The fully qualified model resource name to use for generating images (for example, `publishers/google/models/imagen-3.0-generate-002`). + +Signature: + +```typescript +readonly model: string; +``` diff --git a/docs-devsite/vertexai.genaioptions.md b/docs-devsite/vertexai.genaioptions.md new file mode 100644 index 00000000000..d7f5b499f67 --- /dev/null +++ b/docs-devsite/vertexai.genaioptions.md @@ -0,0 +1,35 @@ +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 %} + +# GenAIOptions interface +Options interface for initializing the GenAI service using [getGenAI()](./vertexai.md#getgenai_65c48ee). + +Signature: + +```typescript +export interface GenAIOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [backend](./vertexai.genaioptions.md#genaioptionsbackend) | [Backend](./vertexai.md#backend) | The backend configuration to use for the GenAI service instance. Use [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) to create this configuration. | + +## GenAIOptions.backend + +The backend configuration to use for the GenAI service instance. Use [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) to create this configuration. + +Signature: + +```typescript +backend: Backend; +``` diff --git a/docs-devsite/vertexai.generativemodel.md b/docs-devsite/vertexai.generativemodel.md index e4a238b0af5..2cbb56958b1 100644 --- a/docs-devsite/vertexai.generativemodel.md +++ b/docs-devsite/vertexai.generativemodel.md @@ -15,15 +15,15 @@ Class for generative model APIs. Signature: ```typescript -export declare class GenerativeModel extends VertexAIModel +export declare class GenerativeModel extends GenAIModel ``` -Extends: [VertexAIModel](./vertexai.vertexaimodel.md#vertexaimodel_class) +Extends: [GenAIModel](./vertexai.genaimodel.md#genaimodel_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(vertexAI, modelParams, requestOptions)](./vertexai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the GenerativeModel class | +| [(constructor)(genAI, modelParams, requestOptions)](./vertexai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the GenerativeModel class | ## Properties @@ -52,14 +52,14 @@ Constructs a new instance of the `GenerativeModel` class Signature: ```typescript -constructor(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions); +constructor(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions); ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| vertexAI | [VertexAI](./vertexai.vertexai.md#vertexai_interface) | | +| genAI | [GenAI](./vertexai.genai.md#genai_interface) | | | modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | diff --git a/docs-devsite/vertexai.imagengenerationconfig.md b/docs-devsite/vertexai.imagengenerationconfig.md index b6785b9b2bb..8c452bcd116 100644 --- a/docs-devsite/vertexai.imagengenerationconfig.md +++ b/docs-devsite/vertexai.imagengenerationconfig.md @@ -44,6 +44,8 @@ If set to `true`, an invisible SynthID watermark is embedded in generate For Imagen 3 models, the default value is `true`; see the addWatermark documentation for more details. +In Google AI, the default value is true, and it cannot be turned off. + Signature: ```typescript diff --git a/docs-devsite/vertexai.imagenmodel.md b/docs-devsite/vertexai.imagenmodel.md index ed40dc8f578..b6c29dc5d81 100644 --- a/docs-devsite/vertexai.imagenmodel.md +++ b/docs-devsite/vertexai.imagenmodel.md @@ -20,15 +20,15 @@ This class provides methods for generating images using the Imagen model. Signature: ```typescript -export declare class ImagenModel extends VertexAIModel +export declare class ImagenModel extends GenAIModel ``` -Extends: [VertexAIModel](./vertexai.vertexaimodel.md#vertexaimodel_class) +Extends: [GenAIModel](./vertexai.genaimodel.md#genaimodel_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(vertexAI, modelParams, requestOptions)](./vertexai.imagenmodel.md#imagenmodelconstructor) | | (Public Preview) Constructs a new instance of the [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class. | +| [(constructor)(genAI, modelParams, requestOptions)](./vertexai.imagenmodel.md#imagenmodelconstructor) | | (Public Preview) Constructs a new instance of the [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class. | ## Properties @@ -54,14 +54,14 @@ Constructs a new instance of the [ImagenModel](./vertexai.imagenmodel.md#imagenm Signature: ```typescript -constructor(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); +constructor(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| vertexAI | [VertexAI](./vertexai.vertexai.md#vertexai_interface) | An instance of the Vertex AI in Firebase SDK. | +| genAI | [GenAI](./vertexai.genai.md#genai_interface) | A [GenAI](./vertexai.genai.md#genai_interface) instance. | | modelParams | [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making requests to Imagen. | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) \| undefined | Additional options to use when making requests. | @@ -142,7 +142,7 @@ If the request to generate images fails. This happens if the prompt is blocked. ```javascript const imagen = new ImagenModel( - vertexAI, + genAI, { model: 'imagen-3.0-generate-002' } diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index f67254eef20..1b93328851e 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -17,10 +17,15 @@ The Vertex AI in Firebase Web SDK. | Function | Description | | --- | --- | | function(app, ...) | -| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | Returns a [VertexAI](./vertexai.vertexai.md#vertexai_interface) instance for the given app. | -| function(vertexAI, ...) | -| [getGenerativeModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_e3037c9) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | -| [getImagenModel(vertexAI, modelParams, requestOptions)](./vertexai.md#getimagenmodel_812c375) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | +| [getGenAI(app, options)](./vertexai.md#getgenai_65c48ee) | Returns the default [GenAI](./vertexai.genai.md#genai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | +| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app. | +| function() | +| [googleAIBackend()](./vertexai.md#googleaibackend) | Creates a [Backend](./vertexai.md#backend) instance configured to use Google AI. | +| function(genAI, ...) | +| [getGenerativeModel(genAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_e3ccf80) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | +| [getImagenModel(genAI, modelParams, requestOptions)](./vertexai.md#getimagenmodel_bffbd6b) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | +| function(location, ...) | +| [vertexAIBackend(location)](./vertexai.md#vertexaibackend_d0a4534) | Creates a [Backend](./vertexai.md#backend) instance configured to use Vertex AI. | ## Classes @@ -29,6 +34,8 @@ The Vertex AI in Firebase Web SDK. | [ArraySchema](./vertexai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | | [BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | | [ChatSession](./vertexai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | +| [GenAIError](./vertexai.genaierror.md#genaierror_class) | Error class for the Vertex AI in Firebase SDK. | +| [GenAIModel](./vertexai.genaimodel.md#genaimodel_class) | Base class for Vertex AI in Firebase model APIs. | | [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) Defines the image format for images generated by Imagen.Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface). | | [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) | (Public Preview) Class for Imagen model APIs.This class provides methods for generating images using the Imagen model. | @@ -37,8 +44,6 @@ The Vertex AI in Firebase Web SDK. | [ObjectSchema](./vertexai.objectschema.md#objectschema_class) | Schema class for "object" types. The properties param must be a map of Schema objects. | | [Schema](./vertexai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with JSON.stringify() into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) | | [StringSchema](./vertexai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. | -| [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) | Error class for the Vertex AI in Firebase SDK. | -| [VertexAIModel](./vertexai.vertexaimodel.md#vertexaimodel_class) | Base class for Vertex AI in Firebase model APIs. | ## Enumerations @@ -47,7 +52,8 @@ The Vertex AI in Firebase Web SDK. | [BlockReason](./vertexai.md#blockreason) | Reason that a prompt was blocked. | | [FinishReason](./vertexai.md#finishreason) | Reason that a candidate finished. | | [FunctionCallingMode](./vertexai.md#functioncallingmode) | | -| [HarmBlockMethod](./vertexai.md#harmblockmethod) | | +| [GenAIErrorCode](./vertexai.md#genaierrorcode) | Standardized error codes that [GenAIError](./vertexai.genaierror.md#genaierror_class) can have. | +| [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in Google AI. | | [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | | [HarmCategory](./vertexai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | | [HarmProbability](./vertexai.md#harmprobability) | Probability that a prompt or candidate matches a harm category. | @@ -57,7 +63,6 @@ The Vertex AI in Firebase Web SDK. | [ImagenSafetyFilterLevel](./vertexai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | | [Modality](./vertexai.md#modality) | Content part modality. | | [SchemaType](./vertexai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | -| [VertexAIErrorCode](./vertexai.md#vertexaierrorcode) | Standardized error codes that [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) can have. | ## Interfaces @@ -82,6 +87,8 @@ The Vertex AI in Firebase Web SDK. | [FunctionDeclarationsTool](./vertexai.functiondeclarationstool.md#functiondeclarationstool_interface) | A FunctionDeclarationsTool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. | | [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface) | The result output from a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) that contains a string representing the [FunctionDeclaration.name](./vertexai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) made based on model prediction. | | [FunctionResponsePart](./vertexai.functionresponsepart.md#functionresponsepart_interface) | Content part interface if the part represents [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface). | +| [GenAI](./vertexai.genai.md#genai_interface) | An instance of the Firebase GenAI SDK.Do not create this instance directly. Instead, use [getGenAI()](./vertexai.md#getgenai_65c48ee). | +| [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) | Options interface for initializing the GenAI service using [getGenAI()](./vertexai.md#getgenai_65c48ee). | | [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | A candidate returned as part of a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | | [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) | Request sent through [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) | | [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface) | Individual response from [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) and [GenerativeModel.generateContentStream()](./vertexai.generativemodel.md#generativemodelgeneratecontentstream). generateContentStream() will return one in each chunk until the stream is done. | @@ -99,10 +106,10 @@ The Vertex AI in Firebase Web SDK. | [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Settings for controlling the aggressiveness of filtering out sensitive content.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details. | | [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. | | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. | -| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9). | +| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3ccf80). | | [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. | | [PromptFeedback](./vertexai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with blockReason and the relevant safetyRatings. | -| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9). | +| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3ccf80). | | [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | | | [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | | [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. | @@ -115,7 +122,6 @@ The Vertex AI in Firebase Web SDK. | [TextPart](./vertexai.textpart.md#textpart_interface) | Content part interface if the part represents a text string. | | [ToolConfig](./vertexai.toolconfig.md#toolconfig_interface) | Tool config. This config is shared for all tools provided in the request. | | [UsageMetadata](./vertexai.usagemetadata.md#usagemetadata_interface) | Usage metadata about a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | -| [VertexAI](./vertexai.vertexai.md#vertexai_interface) | An instance of the Vertex AI in Firebase SDK. | | [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | Options when initializing the Vertex AI in Firebase SDK. | | [VideoMetadata](./vertexai.videometadata.md#videometadata_interface) | Describes the input video content. | | [WebAttribution](./vertexai.webattribution.md#webattribution_interface) | | @@ -124,22 +130,79 @@ The Vertex AI in Firebase Web SDK. | Variable | Description | | --- | --- | +| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase GenAI SDK.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.md#googleaibackend) or [VertexAIBackend](./vertexai.md#vertexaibackend)) to identify which service to target. | | [POSSIBLE\_ROLES](./vertexai.md#possible_roles) | Possible roles. | +| [VertexAIError](./vertexai.md#vertexaierror) | Error class for the Vertex AI in Firebase SDK.For more information, refer to the documentation for the new [GenAIError](./vertexai.genaierror.md#genaierror_class). | +| [VertexAIModel](./vertexai.md#vertexaimodel) | Base class for Vertex AI in Firebase model APIs.For more information, refer to the documentation for the new [GenAIModel](./vertexai.genaimodel.md#genaimodel_class). | ## Type Aliases | Type Alias | Description | | --- | --- | +| [Backend](./vertexai.md#backend) | Union type representing the backend configuration for the GenAI service. This can be either a [GoogleAIBackend](./vertexai.md#googleaibackend) or a [VertexAIBackend](./vertexai.md#vertexaibackend) configuration object.Create instances using [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534). | +| [BackendType](./vertexai.md#backendtype) | Type alias representing valid backend types. It can be either 'VERTEX_AI' or 'GOOGLE_AI'. | +| [GoogleAIBackend](./vertexai.md#googleaibackend) | Represents the configuration object for the Google AI backend. Use this with [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) when initializing the service with [getGenAI()](./vertexai.md#getgenai_65c48ee). Create an instance using [googleAIBackend()](./vertexai.md#googleaibackend). | | [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. | | [Role](./vertexai.md#role) | Role is the producer of the content. | | [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. | | [TypedSchema](./vertexai.md#typedschema) | A type that includes all specific Schema types. | +| [VertexAI](./vertexai.md#vertexai) | An instance of the Vertex AI in Firebase SDK.For more information, refer to the documentation for the new [GenAI](./vertexai.genai.md#genai_interface). | +| [VertexAIBackend](./vertexai.md#vertexaibackend) | Represents the configuration object for the Vertex AI backend. Use this with [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) when initializing the server with [getGenAI()](./vertexai.md#getgenai_65c48ee). Create an instance using [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) function. | ## function(app, ...) +### getGenAI(app, options) {:#getgenai_65c48ee} + +Returns the default [GenAI](./vertexai.genai.md#genai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. + +Signature: + +```typescript +export declare function getGenAI(app?: FirebaseApp, options?: GenAIOptions): GenAI; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | +| options | [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) | [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) that configure the GenAI instance. | + +Returns: + +[GenAI](./vertexai.genai.md#genai_interface) + +The default [GenAI](./vertexai.genai.md#genai_interface) instance for the given [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). + +### Example 1 + + +```javascript +const genAI = getGenAI(app); + +``` + +### Example 2 + + +```javascript +// Get a GenAI instance configured to use Google AI. +const genAI = getGenAI(app, { backend: googleAIBackend() }); + +``` + +### Example 3 + + +```javascript +// Get a GenAI instance configured to use Vertex AI. +const genAI = getGenAI(app, { backend: vertexAIBackend() }); + +``` + ### getVertexAI(app, options) {:#getvertexai_04094cf} -Returns a [VertexAI](./vertexai.vertexai.md#vertexai_interface) instance for the given app. +Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app. Signature: @@ -156,25 +219,42 @@ export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions Returns: -[VertexAI](./vertexai.vertexai.md#vertexai_interface) +[VertexAI](./vertexai.md#vertexai) + +## function() + +### googleAIBackend() {:#googleaibackend} + +Creates a [Backend](./vertexai.md#backend) instance configured to use Google AI. + +Signature: + +```typescript +export declare function googleAIBackend(): GoogleAIBackend; +``` +Returns: + +[GoogleAIBackend](./vertexai.md#googleaibackend) + +A [GoogleAIBackend](./vertexai.md#googleaibackend) object. -## function(vertexAI, ...) +## function(genAI, ...) -### getGenerativeModel(vertexAI, modelParams, requestOptions) {:#getgenerativemodel_e3037c9} +### getGenerativeModel(genAI, modelParams, requestOptions) {:#getgenerativemodel_e3ccf80} Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. Signature: ```typescript -export declare function getGenerativeModel(vertexAI: VertexAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; +export declare function getGenerativeModel(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| vertexAI | [VertexAI](./vertexai.vertexai.md#vertexai_interface) | | +| genAI | [GenAI](./vertexai.genai.md#genai_interface) | | | modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | @@ -182,7 +262,7 @@ export declare function getGenerativeModel(vertexAI: VertexAI, modelParams: Mode [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) -### getImagenModel(vertexAI, modelParams, requestOptions) {:#getimagenmodel_812c375} +### getImagenModel(genAI, modelParams, requestOptions) {:#getimagenmodel_bffbd6b} > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > @@ -194,14 +274,14 @@ Only Imagen 3 models (named `imagen-3.0-*`) are supported. Signature: ```typescript -export declare function getImagenModel(vertexAI: VertexAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; +export declare function getImagenModel(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| vertexAI | [VertexAI](./vertexai.vertexai.md#vertexai_interface) | An instance of the Vertex AI in Firebase SDK. | +| genAI | [GenAI](./vertexai.genai.md#genai_interface) | A [GenAI](./vertexai.genai.md#genai_interface) instance. | | modelParams | [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making Imagen requests. | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. | @@ -213,6 +293,45 @@ export declare function getImagenModel(vertexAI: VertexAI, modelParams: ImagenMo If the `apiKey` or `projectId` fields are missing in your Firebase config. +## function(location, ...) + +### vertexAIBackend(location) {:#vertexaibackend_d0a4534} + +Creates a [Backend](./vertexai.md#backend) instance configured to use Vertex AI. + +Signature: + +```typescript +export declare function vertexAIBackend(location?: string): VertexAIBackend; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| location | string | The region identifier, defaulting to us-central1; see [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations) for a list of supported locations. | + +Returns: + +[VertexAIBackend](./vertexai.md#vertexaibackend) + +A [VertexAIBackend](./vertexai.md#vertexaibackend) object. + +## BackendType + +An enum-like object containing constants that represent the supported backends for the Firebase GenAI SDK. + +These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.md#googleaibackend) or [VertexAIBackend](./vertexai.md#vertexaibackend)) to identify which service to target. + +Signature: + +```typescript +BackendType: { + readonly VERTEX_AI: "VERTEX_AI"; + readonly GOOGLE_AI: "GOOGLE_AI"; +} +``` + ## POSSIBLE\_ROLES Possible roles. @@ -223,6 +342,64 @@ Possible roles. POSSIBLE_ROLES: readonly ["user", "model", "function", "system"] ``` +## VertexAIError + +Error class for the Vertex AI in Firebase SDK. + +For more information, refer to the documentation for the new [GenAIError](./vertexai.genaierror.md#genaierror_class). + +Signature: + +```typescript +VertexAIError: typeof GenAIError +``` + +## VertexAIModel + +Base class for Vertex AI in Firebase model APIs. + +For more information, refer to the documentation for the new [GenAIModel](./vertexai.genaimodel.md#genaimodel_class). + +Signature: + +```typescript +VertexAIModel: typeof GenAIModel +``` + +## Backend + +Union type representing the backend configuration for the GenAI service. This can be either a [GoogleAIBackend](./vertexai.md#googleaibackend) or a [VertexAIBackend](./vertexai.md#vertexaibackend) configuration object. + +Create instances using [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534). + +Signature: + +```typescript +export type Backend = GoogleAIBackend | VertexAIBackend; +``` + +## BackendType + +Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. + +Signature: + +```typescript +export type BackendType = (typeof BackendType)[keyof typeof BackendType]; +``` + +## GoogleAIBackend + +Represents the configuration object for the Google AI backend. Use this with [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) when initializing the service with [getGenAI()](./vertexai.md#getgenai_65c48ee). Create an instance using [googleAIBackend()](./vertexai.md#googleaibackend). + +Signature: + +```typescript +export type GoogleAIBackend = { + backendType: typeof BackendType.GOOGLE_AI; +}; +``` + ## Part Content part - includes text, image/video, or function call/response part types. @@ -263,6 +440,31 @@ A type that includes all specific Schema types. export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; ``` +## VertexAI + +An instance of the Vertex AI in Firebase SDK. + +For more information, refer to the documentation for the new [GenAI](./vertexai.genai.md#genai_interface). + +Signature: + +```typescript +export type VertexAI = GenAI; +``` + +## VertexAIBackend + +Represents the configuration object for the Vertex AI backend. Use this with [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) when initializing the server with [getGenAI()](./vertexai.md#getgenai_65c48ee). Create an instance using [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) function. + +Signature: + +```typescript +export type VertexAIBackend = { + backendType: typeof BackendType.VERTEX_AI; + location: string; +}; +``` + ## BlockReason Reason that a prompt was blocked. @@ -323,8 +525,37 @@ export declare enum FunctionCallingMode | AUTO | "AUTO" | Default model behavior; model decides to predict either a function call or a natural language response. | | NONE | "NONE" | Model will not predict any function call. Model behavior is same as when not passing any function declarations. | +## GenAIErrorCode + +Standardized error codes that [GenAIError](./vertexai.genaierror.md#genaierror_class) can have. + +Signature: + +```typescript +export declare const enum GenAIErrorCode +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| API\_NOT\_ENABLED | "api-not-enabled" | An error due to the Firebase API not being enabled in the Console. | +| ERROR | "error" | A generic error occurred. | +| FETCH\_ERROR | "fetch-error" | An error occurred while performing a fetch. | +| INVALID\_CONTENT | "invalid-content" | An error associated with a Content object. | +| INVALID\_SCHEMA | "invalid-schema" | An error due to invalid Schema input. | +| NO\_API\_KEY | "no-api-key" | An error occurred due to a missing Firebase API key. | +| NO\_APP\_ID | "no-app-id" | An error occured due to a missing Firebase app ID. | +| NO\_MODEL | "no-model" | An error occurred due to a model name not being specified during initialization. | +| NO\_PROJECT\_ID | "no-project-id" | An error occurred due to a missing project ID. | +| PARSE\_FAILED | "parse-failed" | An error occurred while parsing. | +| REQUEST\_ERROR | "request-error" | An error occurred in a request. | +| RESPONSE\_ERROR | "response-error" | An error occurred in a response. | +| UNSUPPORTED | "unsupported" | An error occured due an attempt to use an unsupported feature. | + ## HarmBlockMethod +This property is not supported in Google AI. Signature: @@ -414,6 +645,7 @@ export declare enum HarmSeverity | HARM\_SEVERITY\_LOW | "HARM_SEVERITY_LOW" | Low level of harm severity. | | HARM\_SEVERITY\_MEDIUM | "HARM_SEVERITY_MEDIUM" | Medium level of harm severity. | | HARM\_SEVERITY\_NEGLIGIBLE | "HARM_SEVERITY_NEGLIGIBLE" | Negligible level of harm severity. | +| HARM\_SEVERITY\_UNSUPPORTED | "HARM_SEVERITY_UNSUPPORTED" | Harm severity is not supported. The GoogleAI backend does not support HarmSeverity, so this value is used as a fallback. | ## ImagenAspectRatio @@ -531,30 +763,3 @@ export declare enum SchemaType | OBJECT | "object" | Object type. | | STRING | "string" | String type. | -## VertexAIErrorCode - -Standardized error codes that [VertexAIError](./vertexai.vertexaierror.md#vertexaierror_class) can have. - -Signature: - -```typescript -export declare const enum VertexAIErrorCode -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| API\_NOT\_ENABLED | "api-not-enabled" | An error due to the Firebase API not being enabled in the Console. | -| ERROR | "error" | A generic error occurred. | -| FETCH\_ERROR | "fetch-error" | An error occurred while performing a fetch. | -| INVALID\_CONTENT | "invalid-content" | An error associated with a Content object. | -| INVALID\_SCHEMA | "invalid-schema" | An error due to invalid Schema input. | -| NO\_API\_KEY | "no-api-key" | An error occurred due to a missing Firebase API key. | -| NO\_APP\_ID | "no-app-id" | An error occured due to a missing Firebase app ID. | -| NO\_MODEL | "no-model" | An error occurred due to a model name not being specified during initialization. | -| NO\_PROJECT\_ID | "no-project-id" | An error occurred due to a missing project ID. | -| PARSE\_FAILED | "parse-failed" | An error occurred while parsing. | -| REQUEST\_ERROR | "request-error" | An error occurred in a request. | -| RESPONSE\_ERROR | "response-error" | An error occurred in a response. | - diff --git a/docs-devsite/vertexai.modelparams.md b/docs-devsite/vertexai.modelparams.md index d3963d240eb..f25f37e4dd6 100644 --- a/docs-devsite/vertexai.modelparams.md +++ b/docs-devsite/vertexai.modelparams.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # ModelParams interface -Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9). +Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3ccf80). Signature: diff --git a/docs-devsite/vertexai.requestoptions.md b/docs-devsite/vertexai.requestoptions.md index dcd0c552ecb..ffedaa69859 100644 --- a/docs-devsite/vertexai.requestoptions.md +++ b/docs-devsite/vertexai.requestoptions.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # RequestOptions interface -Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3037c9). +Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3ccf80). Signature: diff --git a/docs-devsite/vertexai.safetysetting.md b/docs-devsite/vertexai.safetysetting.md index 17fa1cff839..5a837e8aeff 100644 --- a/docs-devsite/vertexai.safetysetting.md +++ b/docs-devsite/vertexai.safetysetting.md @@ -23,7 +23,7 @@ export interface SafetySetting | Property | Type | Description | | --- | --- | --- | | [category](./vertexai.safetysetting.md#safetysettingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | -| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | | +| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in Google AI. If this is a property on a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) to be sent, a [GenAIError](./vertexai.genaierror.md#genaierror_class) will be thrown. | | [threshold](./vertexai.safetysetting.md#safetysettingthreshold) | [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | | ## SafetySetting.category @@ -36,6 +36,8 @@ category: HarmCategory; ## SafetySetting.method +This property is not supported in Google AI. If this is a property on a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) to be sent, a [GenAIError](./vertexai.genaierror.md#genaierror_class) will be thrown. + Signature: ```typescript diff --git a/docs-devsite/vertexai.schemashared.md b/docs-devsite/vertexai.schemashared.md index 0764a53bdc0..90956b93606 100644 --- a/docs-devsite/vertexai.schemashared.md +++ b/docs-devsite/vertexai.schemashared.md @@ -25,7 +25,7 @@ export interface SchemaShared | [description](./vertexai.schemashared.md#schemashareddescription) | string | Optional. The description of the property. | | [enum](./vertexai.schemashared.md#schemasharedenum) | string\[\] | Optional. The enum of the property. | | [example](./vertexai.schemashared.md#schemasharedexample) | unknown | Optional. The example of the property. | -| [format](./vertexai.schemashared.md#schemasharedformat) | string | Optional. The format of the property. | +| [format](./vertexai.schemashared.md#schemasharedformat) | string | Optional. The format of the property. When using the Google AI backend, this must be either 'enum' or 'date-time', otherwise requests will fail. | | [items](./vertexai.schemashared.md#schemashareditems) | T | Optional. The items of the property. | | [nullable](./vertexai.schemashared.md#schemasharednullable) | boolean | Optional. Whether the property is nullable. | | [properties](./vertexai.schemashared.md#schemasharedproperties) | { \[k: string\]: T; } | Optional. Map of Schema objects. | @@ -62,7 +62,7 @@ example?: unknown; ## SchemaShared.format -Optional. The format of the property. +Optional. The format of the property. When using the Google AI backend, this must be either `'enum'` or `'date-time'`, otherwise requests will fail. Signature: diff --git a/docs-devsite/vertexai.vertexai.md b/docs-devsite/vertexai.vertexai.md deleted file mode 100644 index d30d0f7113e..00000000000 --- a/docs-devsite/vertexai.vertexai.md +++ /dev/null @@ -1,44 +0,0 @@ -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 %} - -# VertexAI interface -An instance of the Vertex AI in Firebase SDK. - -Signature: - -```typescript -export interface VertexAI -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [app](./vertexai.vertexai.md#vertexaiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [VertexAI](./vertexai.vertexai.md#vertexai_interface) instance is associated with. | -| [location](./vertexai.vertexai.md#vertexailocation) | string | | - -## VertexAI.app - -The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [VertexAI](./vertexai.vertexai.md#vertexai_interface) instance is associated with. - -Signature: - -```typescript -app: FirebaseApp; -``` - -## VertexAI.location - -Signature: - -```typescript -location: string; -``` diff --git a/docs-devsite/vertexai.vertexaimodel.md b/docs-devsite/vertexai.vertexaimodel.md deleted file mode 100644 index 5c3244fe1e5..00000000000 --- a/docs-devsite/vertexai.vertexaimodel.md +++ /dev/null @@ -1,66 +0,0 @@ -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 %} - -# VertexAIModel class -Base class for Vertex AI in Firebase model APIs. - -The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `VertexAIModel` class. - -Signature: - -```typescript -export declare abstract class VertexAIModel -``` - -## Properties - -| Property | Modifiers | Type | Description | -| --- | --- | --- | --- | -| [model](./vertexai.vertexaimodel.md#vertexaimodelmodel) | | string | The fully qualified model resource name to use for generating images (for example, publishers/google/models/imagen-3.0-generate-002). | - -## Methods - -| Method | Modifiers | Description | -| --- | --- | --- | -| [normalizeModelName(modelName)](./vertexai.vertexaimodel.md#vertexaimodelnormalizemodelname) | static | Normalizes the given model name to a fully qualified model resource name. | - -## VertexAIModel.model - -The fully qualified model resource name to use for generating images (for example, `publishers/google/models/imagen-3.0-generate-002`). - -Signature: - -```typescript -readonly model: string; -``` - -## VertexAIModel.normalizeModelName() - -Normalizes the given model name to a fully qualified model resource name. - -Signature: - -```typescript -static normalizeModelName(modelName: string): string; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| modelName | string | The model name to normalize. | - -Returns: - -string - -The fully qualified model resource name. - diff --git a/packages/firebase/package.json b/packages/firebase/package.json index 0a108875770..f47e3378ee2 100644 --- a/packages/firebase/package.json +++ b/packages/firebase/package.json @@ -227,6 +227,18 @@ }, "default": "./storage/dist/esm/index.esm.js" }, + "./genai": { + "types": "./vertexai/dist/vertexai/index.d.ts", + "node": { + "require": "./vertexai/dist/index.cjs.js", + "import": "./vertexai/dist/index.mjs" + }, + "browser": { + "require": "./vertexai/dist/index.cjs.js", + "import": "./vertexai/dist/esm/index.esm.js" + }, + "default": "./vertexai/dist/esm/index.esm.js" + }, "./vertexai": { "types": "./vertexai/dist/vertexai/index.d.ts", "node": { diff --git a/packages/vertexai/.eslintrc.js b/packages/vertexai/.eslintrc.js index 1e8712b0633..dbc1d5aa33c 100644 --- a/packages/vertexai/.eslintrc.js +++ b/packages/vertexai/.eslintrc.js @@ -30,6 +30,7 @@ module.exports = { { 'packageDir': [path.resolve(__dirname, '../../'), __dirname] } - ] + ], + '@typescript-eslint/consistent-type-definitions': 0 } }; diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index 4a0b978d858..dc04b918dd9 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -14,14 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImagenModelParams, ModelParams, VertexAIErrorCode } from './types'; -import { VertexAIError } from './errors'; -import { ImagenModel, getGenerativeModel, getImagenModel } from './api'; +import { ImagenModelParams, ModelParams, GenAIErrorCode } from './types'; +import { GenAIError } from './errors'; +import { + ImagenModel, + getGenerativeModel, + getImagenModel, + googleAIBackend, + vertexAIBackend +} from './api'; import { expect } from 'chai'; -import { VertexAI } from './public-types'; +import { BackendType, GenAI } from './public-types'; import { GenerativeModel } from './models/generative-model'; +import { DEFAULT_LOCATION } from './constants'; -const fakeVertexAI: VertexAI = { +const fakeGenAI: GenAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -31,140 +38,161 @@ const fakeVertexAI: VertexAI = { appId: 'my-appid' } }, + backend: vertexAIBackend('us-central1'), location: 'us-central1' }; describe('Top level API', () => { it('getGenerativeModel throws if no model is provided', () => { try { - getGenerativeModel(fakeVertexAI, {} as ModelParams); + getGenerativeModel(fakeGenAI, {} as ModelParams); } catch (e) { - expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_MODEL); - expect((e as VertexAIError).message).includes( + expect((e as GenAIError).code).includes(GenAIErrorCode.NO_MODEL); + expect((e as GenAIError).message).includes( `VertexAI: Must provide a model name. Example: ` + - `getGenerativeModel({ model: 'my-model-name' }) (vertexAI/${VertexAIErrorCode.NO_MODEL})` + `getGenerativeModel({ model: 'my-model-name' }) (vertexAI/${GenAIErrorCode.NO_MODEL})` ); } }); it('getGenerativeModel throws if no apiKey is provided', () => { const fakeVertexNoApiKey = { - ...fakeVertexAI, + ...fakeGenAI, app: { options: { projectId: 'my-project', appId: 'my-appid' } } - } as VertexAI; + } as GenAI; try { getGenerativeModel(fakeVertexNoApiKey, { model: 'my-model' }); } catch (e) { - expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_API_KEY); - expect((e as VertexAIError).message).equals( + expect((e as GenAIError).code).includes(GenAIErrorCode.NO_API_KEY); + expect((e as GenAIError).message).equals( `VertexAI: The "apiKey" field is empty in the local ` + `Firebase config. Firebase VertexAI requires this field to` + - ` contain a valid API key. (vertexAI/${VertexAIErrorCode.NO_API_KEY})` + ` contain a valid API key. (vertexAI/${GenAIErrorCode.NO_API_KEY})` ); } }); it('getGenerativeModel throws if no projectId is provided', () => { const fakeVertexNoProject = { - ...fakeVertexAI, + ...fakeGenAI, app: { options: { apiKey: 'my-key', appId: 'my-appid' } } - } as VertexAI; + } as GenAI; try { getGenerativeModel(fakeVertexNoProject, { model: 'my-model' }); } catch (e) { - expect((e as VertexAIError).code).includes( - VertexAIErrorCode.NO_PROJECT_ID - ); - expect((e as VertexAIError).message).equals( + expect((e as GenAIError).code).includes(GenAIErrorCode.NO_PROJECT_ID); + expect((e as GenAIError).message).equals( `VertexAI: The "projectId" field is empty in the local` + ` Firebase config. Firebase VertexAI requires this field ` + - `to contain a valid project ID. (vertexAI/${VertexAIErrorCode.NO_PROJECT_ID})` + `to contain a valid project ID. (vertexAI/${GenAIErrorCode.NO_PROJECT_ID})` ); } }); it('getGenerativeModel throws if no appId is provided', () => { const fakeVertexNoProject = { - ...fakeVertexAI, + ...fakeGenAI, app: { options: { apiKey: 'my-key', projectId: 'my-projectid' } } - } as VertexAI; + } as GenAI; try { getGenerativeModel(fakeVertexNoProject, { model: 'my-model' }); } catch (e) { - expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_APP_ID); - expect((e as VertexAIError).message).equals( + expect((e as GenAIError).code).includes(GenAIErrorCode.NO_APP_ID); + expect((e as GenAIError).message).equals( `VertexAI: The "appId" field is empty in the local` + ` Firebase config. Firebase VertexAI requires this field ` + - `to contain a valid app ID. (vertexAI/${VertexAIErrorCode.NO_APP_ID})` + `to contain a valid app ID. (vertexAI/${GenAIErrorCode.NO_APP_ID})` ); } }); it('getGenerativeModel gets a GenerativeModel', () => { - const genModel = getGenerativeModel(fakeVertexAI, { model: 'my-model' }); + const genModel = getGenerativeModel(fakeGenAI, { model: 'my-model' }); expect(genModel).to.be.an.instanceOf(GenerativeModel); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); it('getImagenModel throws if no model is provided', () => { try { - getImagenModel(fakeVertexAI, {} as ImagenModelParams); + getImagenModel(fakeGenAI, {} as ImagenModelParams); } catch (e) { - expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_MODEL); - expect((e as VertexAIError).message).includes( + expect((e as GenAIError).code).includes(GenAIErrorCode.NO_MODEL); + expect((e as GenAIError).message).includes( `VertexAI: Must provide a model name. Example: ` + - `getImagenModel({ model: 'my-model-name' }) (vertexAI/${VertexAIErrorCode.NO_MODEL})` + `getImagenModel({ model: 'my-model-name' }) (vertexAI/${GenAIErrorCode.NO_MODEL})` ); } }); it('getImagenModel throws if no apiKey is provided', () => { const fakeVertexNoApiKey = { - ...fakeVertexAI, + ...fakeGenAI, app: { options: { projectId: 'my-project', appId: 'my-appid' } } - } as VertexAI; + } as GenAI; try { getImagenModel(fakeVertexNoApiKey, { model: 'my-model' }); } catch (e) { - expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_API_KEY); - expect((e as VertexAIError).message).equals( + expect((e as GenAIError).code).includes(GenAIErrorCode.NO_API_KEY); + expect((e as GenAIError).message).equals( `VertexAI: The "apiKey" field is empty in the local ` + `Firebase config. Firebase VertexAI requires this field to` + - ` contain a valid API key. (vertexAI/${VertexAIErrorCode.NO_API_KEY})` + ` contain a valid API key. (vertexAI/${GenAIErrorCode.NO_API_KEY})` ); } }); it('getImagenModel throws if no projectId is provided', () => { const fakeVertexNoProject = { - ...fakeVertexAI, + ...fakeGenAI, app: { options: { apiKey: 'my-key', appId: 'my-appid' } } - } as VertexAI; + } as GenAI; try { getImagenModel(fakeVertexNoProject, { model: 'my-model' }); } catch (e) { - expect((e as VertexAIError).code).includes( - VertexAIErrorCode.NO_PROJECT_ID - ); - expect((e as VertexAIError).message).equals( + expect((e as GenAIError).code).includes(GenAIErrorCode.NO_PROJECT_ID); + expect((e as GenAIError).message).equals( `VertexAI: The "projectId" field is empty in the local` + ` Firebase config. Firebase VertexAI requires this field ` + - `to contain a valid project ID. (vertexAI/${VertexAIErrorCode.NO_PROJECT_ID})` + `to contain a valid project ID. (vertexAI/${GenAIErrorCode.NO_PROJECT_ID})` ); } }); it('getImagenModel throws if no appId is provided', () => { const fakeVertexNoProject = { - ...fakeVertexAI, + ...fakeGenAI, app: { options: { apiKey: 'my-key', projectId: 'my-project' } } - } as VertexAI; + } as GenAI; try { getImagenModel(fakeVertexNoProject, { model: 'my-model' }); } catch (e) { - expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_APP_ID); - expect((e as VertexAIError).message).equals( + expect((e as GenAIError).code).includes(GenAIErrorCode.NO_APP_ID); + expect((e as GenAIError).message).equals( `VertexAI: The "appId" field is empty in the local` + ` Firebase config. Firebase VertexAI requires this field ` + - `to contain a valid app ID. (vertexAI/${VertexAIErrorCode.NO_APP_ID})` + `to contain a valid app ID. (vertexAI/${GenAIErrorCode.NO_APP_ID})` ); } }); it('getImagenModel gets an ImagenModel', () => { - const genModel = getImagenModel(fakeVertexAI, { model: 'my-model' }); + const genModel = getImagenModel(fakeGenAI, { model: 'my-model' }); expect(genModel).to.be.an.instanceOf(ImagenModel); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); + it('googleAIBackend returns a backend with backendType GOOGLE_AI', () => { + const backend = googleAIBackend(); + expect(backend.backendType).to.equal(BackendType.GOOGLE_AI); + }); + it('vertexAIBackend returns a backend with backendType VERTEX_AI', () => { + const backend = vertexAIBackend(); + expect(backend.backendType).to.equal(BackendType.VERTEX_AI); + expect(backend.location).to.equal(DEFAULT_LOCATION); + }); + it('vertexAIBackend sets custom location', () => { + const backend = vertexAIBackend('test-location'); + expect(backend.backendType).to.equal(BackendType.VERTEX_AI); + expect(backend.location).to.equal('test-location'); + }); + it('vertexAIBackend sets custom location even if empty string', () => { + const backend = vertexAIBackend(''); + expect(backend.backendType).to.equal(BackendType.VERTEX_AI); + expect(backend.location).to.equal(''); + }); + it('vertexAIBackend uses default location if location is null', () => { + const backend = vertexAIBackend(null as any); + expect(backend.backendType).to.equal(BackendType.VERTEX_AI); + expect(backend.location).to.equal(DEFAULT_LOCATION); + }); }); diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index 7843a5bdeee..11f9dbcf56c 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -18,27 +18,55 @@ import { FirebaseApp, getApp, _getProvider } from '@firebase/app'; import { Provider } from '@firebase/component'; import { getModularInstance } from '@firebase/util'; -import { DEFAULT_LOCATION, VERTEX_TYPE } from './constants'; -import { VertexAIService } from './service'; -import { VertexAI, VertexAIOptions } from './public-types'; +import { DEFAULT_LOCATION, GENAI_TYPE } from './constants'; +import { GenAIService } from './service'; +import { + BackendType, + GenAI, + GenAIOptions, + GoogleAIBackend, + VertexAI, + VertexAIBackend, + VertexAIOptions +} from './public-types'; import { ImagenModelParams, ModelParams, RequestOptions, - VertexAIErrorCode + GenAIErrorCode } from './types'; -import { VertexAIError } from './errors'; -import { VertexAIModel, GenerativeModel, ImagenModel } from './models'; +import { GenAIError } from './errors'; +import { GenAIModel, GenerativeModel, ImagenModel } from './models'; +import { encodeInstanceIdentifier } from './helpers'; export { ChatSession } from './methods/chat-session'; export * from './requests/schema-builder'; export { ImagenImageFormat } from './requests/imagen-image-format'; -export { VertexAIModel, GenerativeModel, ImagenModel }; -export { VertexAIError }; +export { GenAIModel, GenerativeModel, ImagenModel, GenAIError }; + +export { GenAIErrorCode as VertexAIErrorCode }; + +/** + * Base class for Vertex AI in Firebase model APIs. + * + * For more information, refer to the documentation for the new {@link GenAIModel}. + * + * @public + */ +export const VertexAIModel = GenAIModel; + +/** + * Error class for the Vertex AI in Firebase SDK. + * + * For more information, refer to the documentation for the new {@link GenAIError}. + * + * @public + */ +export const VertexAIError = GenAIError; declare module '@firebase/component' { interface NameServiceMapping { - [VERTEX_TYPE]: VertexAIService; + [GENAI_TYPE]: GenAIService; } } @@ -55,13 +83,93 @@ export function getVertexAI( ): VertexAI { app = getModularInstance(app); // Dependencies - const vertexProvider: Provider<'vertexAI'> = _getProvider(app, VERTEX_TYPE); + const genAIProvider: Provider<'genAI'> = _getProvider(app, GENAI_TYPE); - return vertexProvider.getImmediate({ - identifier: options?.location || DEFAULT_LOCATION + const identifier = encodeInstanceIdentifier({ + backendType: BackendType.VERTEX_AI, + location: options?.location ?? DEFAULT_LOCATION + }); + return genAIProvider.getImmediate({ + identifier }); } +/** + * Returns the default {@link GenAI} instance that is associated with the provided + * {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new instance with the + * default settings. + * + * @example + * ```javascript + * const genAI = getGenAI(app); + * ``` + * + * @example + * ```javascript + * // Get a GenAI instance configured to use Google AI. + * const genAI = getGenAI(app, { backend: googleAIBackend() }); + * ``` + * + * @example + * ```javascript + * // Get a GenAI instance configured to use Vertex AI. + * const genAI = getGenAI(app, { backend: vertexAIBackend() }); + * ``` + * + * @param app - The {@link @firebase/app#FirebaseApp} to use. + * @param options - {@link GenAIOptions} that configure the GenAI instance. + * @returns The default {@link GenAI} instance for the given {@link @firebase/app#FirebaseApp}. + * + * @public + */ +export function getGenAI( + app: FirebaseApp = getApp(), + options: GenAIOptions = { backend: googleAIBackend() } +): GenAI { + app = getModularInstance(app); + // Dependencies + const genAIProvider: Provider<'genAI'> = _getProvider(app, GENAI_TYPE); + + const identifier = encodeInstanceIdentifier(options.backend); + return genAIProvider.getImmediate({ + identifier + }); +} + +/** + * Creates a {@link Backend} instance configured to use Google AI. + * + * @returns A {@link GoogleAIBackend} object. + * + * @public + */ +export function googleAIBackend(): GoogleAIBackend { + const backend: GoogleAIBackend = { + backendType: BackendType.GOOGLE_AI + }; + + return backend; +} + +/** + * Creates a {@link Backend} instance configured to use Vertex AI. + * + * @param location - The region identifier, defaulting to `us-central1`; + * see {@link https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations | Vertex AI locations} + * for a list of supported locations. + * @returns A {@link VertexAIBackend} object. + * + * @public + */ +export function vertexAIBackend(location?: string): VertexAIBackend { + const backend: VertexAIBackend = { + backendType: BackendType.VERTEX_AI, + location: location ?? DEFAULT_LOCATION + }; + + return backend; +} + /** * Returns a {@link GenerativeModel} class with methods for inference * and other functionality. @@ -69,17 +177,17 @@ export function getVertexAI( * @public */ export function getGenerativeModel( - vertexAI: VertexAI, + genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions ): GenerativeModel { if (!modelParams.model) { - throw new VertexAIError( - VertexAIErrorCode.NO_MODEL, + throw new GenAIError( + GenAIErrorCode.NO_MODEL, `Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })` ); } - return new GenerativeModel(vertexAI, modelParams, requestOptions); + return new GenerativeModel(genAI, modelParams, requestOptions); } /** @@ -87,7 +195,7 @@ export function getGenerativeModel( * * Only Imagen 3 models (named `imagen-3.0-*`) are supported. * - * @param vertexAI - An instance of the Vertex AI in Firebase SDK. + * @param genAI - A {@link GenAI} instance. * @param modelParams - Parameters to use when making Imagen requests. * @param requestOptions - Additional options to use when making requests. * @@ -97,15 +205,15 @@ export function getGenerativeModel( * @beta */ export function getImagenModel( - vertexAI: VertexAI, + genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions ): ImagenModel { if (!modelParams.model) { - throw new VertexAIError( - VertexAIErrorCode.NO_MODEL, + throw new GenAIError( + GenAIErrorCode.NO_MODEL, `Must provide a model name. Example: getImagenModel({ model: 'my-model-name' })` ); } - return new ImagenModel(vertexAI, modelParams, requestOptions); + return new ImagenModel(genAI, modelParams, requestOptions); } diff --git a/packages/vertexai/src/backwards-compatbility.test.ts b/packages/vertexai/src/backwards-compatbility.test.ts new file mode 100644 index 00000000000..23d0511445a --- /dev/null +++ b/packages/vertexai/src/backwards-compatbility.test.ts @@ -0,0 +1,85 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; +import { + GenAIError, + GenAIModel, + GenerativeModel, + VertexAIError, + VertexAIErrorCode, + VertexAIModel, + getGenerativeModel, + getImagenModel, + vertexAIBackend +} from './api'; +import { GenAI, VertexAI, GenAIErrorCode } from './public-types'; + +function assertAssignable(): void {} + +const fakeGenAI: GenAI = { + app: { + name: 'DEFAULT', + automaticDataCollectionEnabled: true, + options: { + apiKey: 'key', + projectId: 'my-project', + appId: 'app-id' + } + }, + backend: vertexAIBackend('us-central1'), + location: 'us-central1' +}; + +const fakeVertexAI: VertexAI = fakeGenAI; + +describe('backwards-compatible types', () => { + it('GenAI is backwards compatible with VertexAI', () => { + assertAssignable(); + }); + it('GenAIError is backwards compatible with VertexAIError', () => { + assertAssignable(); + const err = new VertexAIError(VertexAIErrorCode.ERROR, ''); + expect(err).instanceOf(GenAIError); + expect(err).instanceOf(VertexAIError); + }); + it('GenAIErrorCode is backwards compatible with VertexAIErrorCode', () => { + assertAssignable(); + const errCode = GenAIErrorCode.ERROR; + expect(errCode).to.equal(VertexAIErrorCode.ERROR); + }); + it('GenAIModel is backwards compatible with VertexAIModel', () => { + assertAssignable(); + + const model = new GenerativeModel(fakeGenAI, { model: 'model-name' }); + expect(model).to.be.instanceOf(GenAIModel); + expect(model).to.be.instanceOf(VertexAIModel); + }); +}); + +describe('backward-compatible functions', () => { + it('getGenerativeModel', () => { + const model = getGenerativeModel(fakeVertexAI, { model: 'model-name' }); + expect(model).to.be.instanceOf(GenAIModel); + expect(model).to.be.instanceOf(VertexAIModel); + }); + it('getImagenModel', () => { + const model = getImagenModel(fakeVertexAI, { model: 'model-name' }); + expect(model).to.be.instanceOf(GenAIModel); + expect(model).to.be.instanceOf(VertexAIModel); + }); +}); diff --git a/packages/vertexai/src/constants.ts b/packages/vertexai/src/constants.ts index 357e6c4e77c..4034e410003 100644 --- a/packages/vertexai/src/constants.ts +++ b/packages/vertexai/src/constants.ts @@ -16,9 +16,18 @@ */ import { version } from '../package.json'; +import { BackendType } from './public-types'; +import { InstanceIdentifier } from './types/internal'; +// TODO (v12): Remove this export const VERTEX_TYPE = 'vertexAI'; +export const GENAI_TYPE = 'genAI'; + +export const DEFAULT_INSTANCE_IDENTIFER: InstanceIdentifier = { + backendType: BackendType.GOOGLE_AI +}; + export const DEFAULT_LOCATION = 'us-central1'; export const DEFAULT_BASE_URL = 'https://firebasevertexai.googleapis.com'; diff --git a/packages/vertexai/src/errors.ts b/packages/vertexai/src/errors.ts index ad3f9b72f5a..c836e49d51e 100644 --- a/packages/vertexai/src/errors.ts +++ b/packages/vertexai/src/errors.ts @@ -16,7 +16,7 @@ */ import { FirebaseError } from '@firebase/util'; -import { VertexAIErrorCode, CustomErrorData } from './types'; +import { GenAIErrorCode as GenAIErrorCode, CustomErrorData } from './types'; import { VERTEX_TYPE } from './constants'; /** @@ -24,22 +24,22 @@ import { VERTEX_TYPE } from './constants'; * * @public */ -export class VertexAIError extends FirebaseError { +export class GenAIError extends FirebaseError { /** - * Constructs a new instance of the `VertexAIError` class. + * Constructs a new instance of the `GenAIError` class. * - * @param code - The error code from {@link VertexAIErrorCode}. + * @param code - The error code from {@link GenAIErrorCode}. * @param message - A human-readable message describing the error. * @param customErrorData - Optional error data. */ constructor( - readonly code: VertexAIErrorCode, + readonly code: GenAIErrorCode, message: string, readonly customErrorData?: CustomErrorData ) { // Match error format used by FirebaseError from ErrorFactory - const service = VERTEX_TYPE; - const serviceName = 'VertexAI'; + const service = VERTEX_TYPE; // TODO (v12): Rename to GENAI_TYPE + const serviceName = 'VertexAI'; // TODO (v12): Rename to GenAI on breaking release. const fullCode = `${service}/${code}`; const fullMessage = `${serviceName}: ${message} (${fullCode})`; super(code, fullMessage); @@ -51,14 +51,14 @@ export class VertexAIError extends FirebaseError { if (Error.captureStackTrace) { // Allows us to initialize the stack trace without including the constructor itself at the // top level of the stack trace. - Error.captureStackTrace(this, VertexAIError); + Error.captureStackTrace(this, GenAIError); } - // Allows instanceof VertexAIError in ES5/ES6 + // Allows instanceof GenAIError in ES5/ES6 // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work // TODO(dlarocque): Replace this with `new.target`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget // which we can now use since we no longer target ES5. - Object.setPrototypeOf(this, VertexAIError.prototype); + Object.setPrototypeOf(this, GenAIError.prototype); // Since Error is an interface, we don't inherit toString and so we define it ourselves. this.toString = () => fullMessage; diff --git a/packages/vertexai/src/googleAIMappers.test.ts b/packages/vertexai/src/googleAIMappers.test.ts new file mode 100644 index 00000000000..3952cce2544 --- /dev/null +++ b/packages/vertexai/src/googleAIMappers.test.ts @@ -0,0 +1,400 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect, use } from 'chai'; +import sinon, { restore, stub } from 'sinon'; +import sinonChai from 'sinon-chai'; +import { + mapCountTokensRequest, + mapGenerateContentCandidates, + mapGenerateContentRequest, + mapGenerateContentResponse, + mapPromptFeedback +} from './googleAIMappers'; +import { + BlockReason, + Content, + CountTokensRequest, + GenerateContentRequest, + HarmBlockMethod, + HarmBlockThreshold, + HarmCategory, + HarmProbability, + HarmSeverity, + SafetyRating, + GenAIErrorCode, + FinishReason, + PromptFeedback +} from './types'; +import { + GoogleAIGenerateContentResponse, + GoogleAIGenerateContentCandidate, + GoogleAICountTokensRequest +} from './types/googleAI'; +import { logger } from './logger'; +import { GenAIError } from './errors'; +import { getMockResponse } from '../test-utils/mock-response'; + +use(sinonChai); + +const fakeModel = 'models/gemini-pro'; + +const fakeContents: Content[] = [{ role: 'user', parts: [{ text: 'hello' }] }]; + +describe('Google AI Mappers', () => { + let loggerWarnStub: sinon.SinonStub; + + beforeEach(() => { + loggerWarnStub = stub(logger, 'warn'); + }); + + afterEach(() => { + restore(); + }); + + describe('mapGenerateContentRequest', () => { + it('should throw if safetySettings contain method', () => { + const request: GenerateContentRequest = { + contents: fakeContents, + safetySettings: [ + { + category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, + threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, + method: HarmBlockMethod.SEVERITY + } + ] + }; + expect(() => mapGenerateContentRequest(request)) + .to.throw(GenAIError, /SafetySetting.method is not supported/i) + .with.property('code', GenAIErrorCode.UNSUPPORTED); + }); + + it('should warn and round topK if present', () => { + const request: GenerateContentRequest = { + contents: fakeContents, + generationConfig: { + topK: 15.7 + } + }; + const mappedRequest = mapGenerateContentRequest(request); + expect(loggerWarnStub).to.have.been.calledOnceWith( + 'topK in GenerationConfig has been rounded to the nearest integer.' + ); + expect(mappedRequest.generationConfig?.topK).to.equal(16); + }); + + it('should not modify topK if it is already an integer', () => { + const request: GenerateContentRequest = { + contents: fakeContents, + generationConfig: { + topK: 16 + } + }; + const mappedRequest = mapGenerateContentRequest(request); + expect(loggerWarnStub).to.not.have.been.called; + expect(mappedRequest.generationConfig?.topK).to.equal(16); + }); + + it('should return the request mostly unchanged if valid', () => { + const request: GenerateContentRequest = { + contents: fakeContents, + safetySettings: [ + { + category: HarmCategory.HARM_CATEGORY_HATE_SPEECH, + threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE + } + ], + generationConfig: { + temperature: 0.5 + } + }; + const mappedRequest = mapGenerateContentRequest({ ...request }); + expect(mappedRequest).to.deep.equal(request); + expect(loggerWarnStub).to.not.have.been.called; + }); + }); + + describe('mapGenerateContentResponse', () => { + it('should map a full Google AI response', async () => { + const googleAIMockResponse: GoogleAIGenerateContentResponse = await ( + getMockResponse('googleAI', 'unary-success-citations.txt') as Response + ).json(); + console.log(JSON.stringify(googleAIMockResponse)); + const mappedResponse = mapGenerateContentResponse(googleAIMockResponse); + + console.log(JSON.stringify(googleAIMockResponse)); + console.log(JSON.stringify(mappedResponse)); + + expect(mappedResponse.candidates).to.exist; + expect(mappedResponse.candidates?.[0].content.parts[0].text).to.contain( + 'quantum mechanics' + ); + + // Mapped citations + expect( + mappedResponse.candidates?.[0].citationMetadata?.citations[0].startIndex + ).to.equal( + googleAIMockResponse.candidates?.[0].citationMetadata + ?.citationSources[0].startIndex + ); + expect( + mappedResponse.candidates?.[0].citationMetadata?.citations[0].endIndex + ).to.equal( + googleAIMockResponse.candidates?.[0].citationMetadata + ?.citationSources[0].endIndex + ); + + // Mapped safety ratings + expect( + mappedResponse.candidates?.[0].safetyRatings?.[0].probabilityScore + ).to.equal(0); + expect( + mappedResponse.candidates?.[0].safetyRatings?.[0].severityScore + ).to.equal(0); + expect( + mappedResponse.candidates?.[0].safetyRatings?.[0].severity + ).to.equal(HarmSeverity.HARM_SEVERITY_UNSUPPORTED); + + expect(mappedResponse.candidates?.[0].finishReason).to.equal( + FinishReason.STOP + ); + + // Check usage metadata passthrough + expect(mappedResponse.usageMetadata).to.deep.equal( + googleAIMockResponse.usageMetadata + ); + }); + + it('should handle missing candidates and promptFeedback', () => { + const googleAIResponse: GoogleAIGenerateContentResponse = { + // No candidates + // No promptFeedback + usageMetadata: { + promptTokenCount: 5, + candidatesTokenCount: 0, + totalTokenCount: 5 + } + }; + const mappedResponse = mapGenerateContentResponse(googleAIResponse); + expect(mappedResponse.candidates).to.be.undefined; + expect(mappedResponse.promptFeedback).to.be.undefined; // Mapped to undefined + expect(mappedResponse.usageMetadata).to.deep.equal( + googleAIResponse.usageMetadata + ); + }); + + it('should handle empty candidates array', () => { + const googleAIResponse: GoogleAIGenerateContentResponse = { + candidates: [], + usageMetadata: { + promptTokenCount: 5, + candidatesTokenCount: 0, + totalTokenCount: 5 + } + }; + const mappedResponse = mapGenerateContentResponse(googleAIResponse); + expect(mappedResponse.candidates).to.deep.equal([]); + expect(mappedResponse.promptFeedback).to.be.undefined; + expect(mappedResponse.usageMetadata).to.deep.equal( + googleAIResponse.usageMetadata + ); + }); + }); + + describe('mapCountTokensRequest', () => { + it('should map a Vertex AI CountTokensRequest to Google AI format', () => { + const vertexRequest: CountTokensRequest = { + contents: fakeContents, + systemInstruction: { role: 'system', parts: [{ text: 'Be nice' }] }, + tools: [ + { functionDeclarations: [{ name: 'foo', description: 'bar' }] } + ], + generationConfig: { temperature: 0.8 } + }; + + const expectedGoogleAIRequest: GoogleAICountTokensRequest = { + generateContentRequest: { + model: fakeModel, + contents: vertexRequest.contents, + systemInstruction: vertexRequest.systemInstruction, + tools: vertexRequest.tools, + generationConfig: vertexRequest.generationConfig + } + }; + + const mappedRequest = mapCountTokensRequest(vertexRequest, fakeModel); + expect(mappedRequest).to.deep.equal(expectedGoogleAIRequest); + }); + + it('should map a minimal Vertex AI CountTokensRequest', () => { + const vertexRequest: CountTokensRequest = { + contents: fakeContents + }; + + const expectedGoogleAIRequest: GoogleAICountTokensRequest = { + generateContentRequest: { + model: fakeModel, + contents: vertexRequest.contents, + systemInstruction: undefined, + tools: undefined, + generationConfig: undefined + } + }; + + const mappedRequest = mapCountTokensRequest(vertexRequest, fakeModel); + expect(mappedRequest).to.deep.equal(expectedGoogleAIRequest); + }); + }); + + describe('mapGenerateContentCandidates', () => { + it('should map citationSources to citationMetadata.citations', () => { + const candidates: GoogleAIGenerateContentCandidate[] = [ + { + index: 0, + content: { role: 'model', parts: [{ text: 'Cited text' }] }, + citationMetadata: { + citationSources: [ + { startIndex: 0, endIndex: 5, uri: 'uri1', license: 'MIT' }, + { startIndex: 6, endIndex: 10, uri: 'uri2' } + ] + } + } + ]; + const mapped = mapGenerateContentCandidates(candidates); + expect(mapped[0].citationMetadata).to.exist; + expect(mapped[0].citationMetadata?.citations).to.deep.equal( + candidates[0].citationMetadata?.citationSources + ); + expect(mapped[0].citationMetadata?.citations[0].title).to.be.undefined; // Not in Google AI + expect(mapped[0].citationMetadata?.citations[0].publicationDate).to.be + .undefined; // Not in Google AI + }); + + it('should add default safety rating properties and warn', () => { + const candidates: GoogleAIGenerateContentCandidate[] = [ + { + index: 0, + content: { role: 'model', parts: [{ text: 'Maybe unsafe' }] }, + safetyRatings: [ + { + category: HarmCategory.HARM_CATEGORY_HARASSMENT, + probability: HarmProbability.MEDIUM, + blocked: false + // Missing severity, probabilityScore, severityScore + } as any + ] + } + ]; + const mapped = mapGenerateContentCandidates(candidates); + expect(loggerWarnStub).to.have.been.calledOnceWith( + "Candidate safety rating properties 'severity', 'severityScore', and 'probabilityScore' are not included in responses from Google AI. Properties have been assigned to default values." + ); + expect(mapped[0].safetyRatings).to.exist; + const safetyRating = mapped[0].safetyRatings?.[0] as SafetyRating; // Type assertion + expect(safetyRating.severity).to.equal( + HarmSeverity.HARM_SEVERITY_UNSUPPORTED + ); + expect(safetyRating.probabilityScore).to.equal(0); + expect(safetyRating.severityScore).to.equal(0); + // Existing properties should be preserved + expect(safetyRating.category).to.equal( + HarmCategory.HARM_CATEGORY_HARASSMENT + ); + expect(safetyRating.probability).to.equal(HarmProbability.MEDIUM); + expect(safetyRating.blocked).to.be.false; + }); + + it('should throw if videoMetadata is present in parts', () => { + const candidates: GoogleAIGenerateContentCandidate[] = [ + { + index: 0, + content: { + role: 'model', + parts: [ + { + inlineData: { mimeType: 'video/mp4', data: 'base64==' }, + videoMetadata: { startOffset: '0s', endOffset: '5s' } // Unsupported + } + ] + } + } + ]; + expect(() => mapGenerateContentCandidates(candidates)) + .to.throw(GenAIError, /Part.videoMetadata is not supported/i) + .with.property('code', GenAIErrorCode.UNSUPPORTED); + }); + + it('should handle candidates without citation or safety ratings', () => { + const candidates: GoogleAIGenerateContentCandidate[] = [ + { + index: 0, + content: { role: 'model', parts: [{ text: 'Simple text' }] }, + finishReason: FinishReason.STOP + } + ]; + const mapped = mapGenerateContentCandidates(candidates); + expect(mapped[0].citationMetadata).to.be.undefined; + expect(mapped[0].safetyRatings).to.be.undefined; + expect(mapped[0].content.parts[0].text).to.equal('Simple text'); + expect(loggerWarnStub).to.not.have.been.called; + }); + + it('should handle empty candidate array', () => { + const candidates: GoogleAIGenerateContentCandidate[] = []; + const mapped = mapGenerateContentCandidates(candidates); + expect(mapped).to.deep.equal([]); + expect(loggerWarnStub).to.not.have.been.called; + }); + }); + + describe('mapPromptFeedback', () => { + it('should add default safety rating properties and warn', () => { + const feedback: PromptFeedback = { + blockReason: BlockReason.OTHER, + safetyRatings: [ + { + category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, + probability: HarmProbability.HIGH, + blocked: true + // Missing severity, probabilityScore, severityScore + } as any + ] + // Missing blockReasonMessage + }; + const mapped = mapPromptFeedback(feedback); + expect(loggerWarnStub).to.have.been.calledOnceWith( + "PromptFeedback safety ratings' properties severity, severityScore, and probabilityScore are not included in responses from Google AI. Properties have been assigned to default values." + ); + expect(mapped.safetyRatings).to.exist; + const safetyRating = mapped.safetyRatings[0] as SafetyRating; // Type assertion + expect(safetyRating.severity).to.equal( + HarmSeverity.HARM_SEVERITY_UNSUPPORTED + ); + expect(safetyRating.probabilityScore).to.equal(0); + expect(safetyRating.severityScore).to.equal(0); + // Existing properties should be preserved + expect(safetyRating.category).to.equal( + HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT + ); + expect(safetyRating.probability).to.equal(HarmProbability.HIGH); + expect(safetyRating.blocked).to.be.true; + // Other properties + expect(mapped.blockReason).to.equal(BlockReason.OTHER); + expect(mapped.blockReasonMessage).to.be.undefined; // Not present in input + }); + }); +}); diff --git a/packages/vertexai/src/googleAIMappers.ts b/packages/vertexai/src/googleAIMappers.ts new file mode 100644 index 00000000000..e61a3532be1 --- /dev/null +++ b/packages/vertexai/src/googleAIMappers.ts @@ -0,0 +1,235 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { GenAIError } from './errors'; +import { logger } from './logger'; +import { + CitationMetadata, + CountTokensRequest, + GenerateContentCandidate, + GenerateContentRequest, + GenerateContentResponse, + HarmSeverity, + InlineDataPart, + PromptFeedback, + SafetyRating, + GenAIErrorCode +} from './types'; +import { + GoogleAIGenerateContentResponse, + GoogleAIGenerateContentCandidate, + GoogleAICountTokensRequest +} from './types/googleAI'; + +/** + * This SDK supports both Vertex AI and Google AI APIs. + * The public API prioritizes the Vertex AI API. + * We avoid having two sets of types by translating requests and responses between the two API formats. + * We want to avoid two sets of types so that developers can switch between Vertex AI and Google AI + * with minimal changes to their code. + * + * In here are functions that map requests and responses between the two API formats. + * VertexAI requests defined by the user are mapped to Google AI requests before they're sent. + * Google AI responses are mapped to VertexAI responses so they can be returned to the user. + */ + +/** + * Maps a Vertex AI {@link GenerateContentRequest} to a format that can be sent to Google AI. + * + * @param generateContentRequest The {@link GenerateContentRequest} to map. + * @returns A {@link GenerateContentResponse} that conforms to the Google AI format. + * + * @throws If the request contains properties that are unsupported by Google AI. + * + * @internal + */ +export function mapGenerateContentRequest( + generateContentRequest: GenerateContentRequest +): GenerateContentRequest { + generateContentRequest.safetySettings?.forEach(safetySetting => { + if (safetySetting.method) { + throw new GenAIError( + GenAIErrorCode.UNSUPPORTED, + 'SafetySetting.method is not supported in the Google AI. Please remove this property.' + ); + } + }); + + if (generateContentRequest.generationConfig?.topK) { + const roundedTopK = Math.round( + generateContentRequest.generationConfig.topK + ); + + if (roundedTopK !== generateContentRequest.generationConfig.topK) { + logger.warn( + 'topK in GenerationConfig has been rounded to the nearest integer.' + ); + generateContentRequest.generationConfig.topK = roundedTopK; + } + } + + return generateContentRequest; +} + +/** + * Maps a {@link GenerateContentResponse} from Google AI to the format of the + * {@link GenerateContentResponse} that we get from VertexAI that is exposed in the public API. + * + * @param googleAIResponse The {@link GenerateContentResponse} from Google AI. + * @returns A {@link GenerateContentResponse} that conforms to the public API's format. + * + * @internal + */ +export function mapGenerateContentResponse( + googleAIResponse: GoogleAIGenerateContentResponse +): GenerateContentResponse { + const generateContentResponse = { + candidates: googleAIResponse.candidates + ? mapGenerateContentCandidates(googleAIResponse.candidates) + : undefined, + prompt: googleAIResponse.promptFeedback + ? mapPromptFeedback(googleAIResponse.promptFeedback) + : undefined, + usageMetadata: googleAIResponse.usageMetadata + }; + + return generateContentResponse; +} + +/** + * Maps a Vertex AI {@link CountTokensRequest} to a format that can be sent to Google AI. + * + * @param countTokensRequest The {@link CountTokensRequest} to map. + * @param model The model to count tokens with. + * @returns A {@link CountTokensRequest} that conforms to the Google AI format. + * + * @internal + */ +export function mapCountTokensRequest( + countTokensRequest: CountTokensRequest, + model: string +): GoogleAICountTokensRequest { + const mappedCountTokensRequest: GoogleAICountTokensRequest = { + generateContentRequest: { + model, + contents: countTokensRequest.contents, + systemInstruction: countTokensRequest.systemInstruction, + tools: countTokensRequest.tools, + generationConfig: countTokensRequest.generationConfig + } + }; + + return mappedCountTokensRequest; +} + +/** + * Maps a Google AI {@link GoogleAIGenerateContentCandidate} to a format that conforms + * to the Vertex AI API format. + * + * @param candidates The {@link GoogleAIGenerateContentCandidate} to map. + * @returns A {@link GenerateContentCandidate} that conforms to the Vertex AI format. + * + * @throws If any {@link Part} in the candidates has a `videoMetadata` property. + * + * @internal + */ +export function mapGenerateContentCandidates( + candidates: GoogleAIGenerateContentCandidate[] +): GenerateContentCandidate[] { + const mappedCandidates: GenerateContentCandidate[] = []; + let mappedSafetyRatings: SafetyRating[]; + if (mappedCandidates) { + candidates.forEach(candidate => { + // Map citationSources to citations. + let citationMetadata: CitationMetadata | undefined; + if (candidate.citationMetadata) { + citationMetadata = { + citations: candidate.citationMetadata.citationSources + }; + } + + // Assign missing candidate SafetyRatings properties to their defaults. + if (candidate.safetyRatings) { + logger.warn( + "Candidate safety rating properties 'severity', 'severityScore', and 'probabilityScore' are not included in responses from Google AI. Properties have been assigned to default values." + ); + mappedSafetyRatings = candidate.safetyRatings.map(safetyRating => { + return { + ...safetyRating, + severity: HarmSeverity.HARM_SEVERITY_UNSUPPORTED, + probabilityScore: 0, + severityScore: 0 + }; + }); + } + + // videoMetadata is not supported. + // Throw early since developers may send a long video as input and only expect to pay + // for inference on a small portion of the video. + if ( + candidate.content?.parts.some( + part => (part as InlineDataPart)?.videoMetadata + ) + ) { + throw new GenAIError( + GenAIErrorCode.UNSUPPORTED, + 'Part.videoMetadata is not supported in Google AI. Please remove this property.' + ); + } + + const mappedCandidate = { + index: candidate.index, + content: candidate.content, + finishReason: candidate.finishReason, + finishMessage: candidate.finishMessage, + safetyRatings: mappedSafetyRatings, + citationMetadata, + groundingMetadata: candidate.groundingMetadata + }; + mappedCandidates.push(mappedCandidate); + }); + } + + return mappedCandidates; +} + +export function mapPromptFeedback( + promptFeedback: PromptFeedback +): PromptFeedback { + // Assign missing PromptFeedback SafetyRatings properties to their defaults. + const mappedSafetyRatings: SafetyRating[] = []; + promptFeedback.safetyRatings.forEach(safetyRating => { + mappedSafetyRatings.push({ + category: safetyRating.category, + probability: safetyRating.probability, + severity: HarmSeverity.HARM_SEVERITY_UNSUPPORTED, + probabilityScore: 0, + severityScore: 0, + blocked: safetyRating.blocked + }); + }); + logger.warn( + "PromptFeedback safety ratings' properties severity, severityScore, and probabilityScore are not included in responses from Google AI. Properties have been assigned to default values." + ); + + const mappedPromptFeedback: PromptFeedback = { + blockReason: promptFeedback.blockReason, + safetyRatings: mappedSafetyRatings, + blockReasonMessage: promptFeedback.blockReasonMessage + }; + return mappedPromptFeedback; +} diff --git a/packages/vertexai/src/helpers.test.ts b/packages/vertexai/src/helpers.test.ts new file mode 100644 index 00000000000..f7316e3f119 --- /dev/null +++ b/packages/vertexai/src/helpers.test.ts @@ -0,0 +1,140 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from 'chai'; +import { GENAI_TYPE } from './constants'; +import { encodeInstanceIdentifier, decodeInstanceIdentifier } from './helpers'; +import { GenAIError } from './errors'; +import { BackendType } from './public-types'; +import { InstanceIdentifier } from './types/internal'; +import { GenAIErrorCode } from './types'; + +describe('Identifier Encoding/Decoding', () => { + describe('encodeInstanceIdentifier', () => { + it('should encode Vertex AI identifier with a specific location', () => { + const identifier: InstanceIdentifier = { + backendType: BackendType.VERTEX_AI, + location: 'us-central1' + }; + console.log(identifier); + const expected = `${GENAI_TYPE}/vertexai/us-central1`; + expect(encodeInstanceIdentifier(identifier)).to.equal(expected); + }); + + it('should encode Vertex AI identifier using empty location', () => { + const identifier: InstanceIdentifier = { + backendType: BackendType.VERTEX_AI, + location: '' + }; + const expected = `${GENAI_TYPE}/vertexai/`; + expect(encodeInstanceIdentifier(identifier)).to.equal(expected); + }); + + it('should encode Google AI identifier', () => { + const identifier: InstanceIdentifier = { + backendType: BackendType.GOOGLE_AI + }; + const expected = `${GENAI_TYPE}/googleai`; + expect(encodeInstanceIdentifier(identifier)).to.equal(expected); + }); + + it('should throw GenAIError for unknown backend type', () => { + const identifier = { + backendType: 'some-future-backend' + } as any; // bypass type checking for the test + + expect(() => encodeInstanceIdentifier(identifier)).to.throw(GenAIError); + + try { + encodeInstanceIdentifier(identifier); + expect.fail('Expected encodeInstanceIdentifier to throw'); + } catch (e) { + expect(e).to.be.instanceOf(GenAIError); + const error = e as GenAIError; + expect(error.message).to.contain(`Unknown backend`); + expect(error.code).to.equal(GenAIErrorCode.ERROR); + } + }); + }); + + describe('decodeInstanceIdentifier', () => { + it('should decode Vertex AI identifier with location', () => { + const encoded = `${GENAI_TYPE}/vertexai/europe-west1`; + const expected: InstanceIdentifier = { + backendType: BackendType.VERTEX_AI, + location: 'europe-west1' + }; + expect(decodeInstanceIdentifier(encoded)).to.deep.equal(expected); + }); + + it('should throw an error if Vertex AI identifier string without explicit location part', () => { + const encoded = `${GENAI_TYPE}/vertexai`; + expect(() => decodeInstanceIdentifier(encoded)).to.throw(GenAIError); + + try { + decodeInstanceIdentifier(encoded); + expect.fail('Expected encodeInstanceIdentifier to throw'); + } catch (e) { + expect(e).to.be.instanceOf(GenAIError); + const error = e as GenAIError; + expect(error.message).to.contain( + `Invalid instance identifier, unknown location` + ); + expect(error.code).to.equal(GenAIErrorCode.ERROR); + } + }); + + it('should decode Google AI identifier', () => { + const encoded = `${GENAI_TYPE}/googleai`; + const expected: InstanceIdentifier = { + backendType: BackendType.GOOGLE_AI + }; + expect(decodeInstanceIdentifier(encoded)).to.deep.equal(expected); + }); + + it('should throw GenAIError for invalid backend string', () => { + const encoded = `${GENAI_TYPE}/someotherbackend/location`; + expect(() => decodeInstanceIdentifier(encoded)).to.throw( + GenAIError, + `Invalid instance identifier string: '${encoded}'` + ); + try { + decodeInstanceIdentifier(encoded); + expect.fail('Expected decodeInstanceIdentifier to throw'); + } catch (e) { + expect(e).to.be.instanceOf(GenAIError); + expect((e as GenAIError).code).to.equal(GenAIErrorCode.ERROR); + } + }); + + it('should throw GenAIError for malformed identifier string (too few parts)', () => { + const encoded = GENAI_TYPE; + expect(() => decodeInstanceIdentifier(encoded)).to.throw( + GenAIError, + `Invalid instance identifier string: '${encoded}'` + ); + }); + + it('should throw GenAIError for malformed identifier string (incorrect prefix)', () => { + const encoded = 'firebase/vertexai/location'; + // This will also hit the default case in the switch statement + expect(() => decodeInstanceIdentifier(encoded)).to.throw( + GenAIError, + `Invalid instance identifier, unknown prefix 'firebase'` + ); + }); + }); +}); diff --git a/packages/vertexai/src/helpers.ts b/packages/vertexai/src/helpers.ts new file mode 100644 index 00000000000..28f11a4b2bd --- /dev/null +++ b/packages/vertexai/src/helpers.ts @@ -0,0 +1,86 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { GENAI_TYPE } from './constants'; +import { GenAIError } from './errors'; +import { BackendType } from './public-types'; +import { InstanceIdentifier } from './types/internal'; +import { GenAIErrorCode } from './types'; + +/** + * Encodes an {@link InstanceIdentifier} into a string. + * + * This string is used to identify unique {@link GenAI} instances by backend type. + * + * @internal + */ +export function encodeInstanceIdentifier( + instanceIdentifier: InstanceIdentifier +): string { + switch (instanceIdentifier.backendType) { + case BackendType.VERTEX_AI: + return `${GENAI_TYPE}/vertexai/${instanceIdentifier.location}`; + case BackendType.GOOGLE_AI: + return `${GENAI_TYPE}/googleai`; + default: + throw new GenAIError( + GenAIErrorCode.ERROR, + `Unknown backend '${instanceIdentifier}'` + ); + } +} + +/** + * Decodes an instance identifier string into an {@link InstanceIdentifier}. + * + * @internal + */ +export function decodeInstanceIdentifier( + instanceIdentifier: string +): InstanceIdentifier { + const identifierParts = instanceIdentifier.split('/'); + if (identifierParts[0] !== GENAI_TYPE) { + throw new GenAIError( + GenAIErrorCode.ERROR, + `Invalid instance identifier, unknown prefix '${identifierParts[0]}'` + ); + } + const backend = identifierParts[1]; + switch (backend) { + case 'vertexai': + const location: string | undefined = identifierParts[2]; + if (!location) { + throw new GenAIError( + GenAIErrorCode.ERROR, + `Invalid instance identifier, unknown location '${instanceIdentifier}'` + ); + } + return { + backendType: BackendType.VERTEX_AI, + location + }; + case 'googleai': + return { + backendType: BackendType.GOOGLE_AI + }; + default: + throw new GenAIError( + GenAIErrorCode.ERROR, + `Invalid instance identifier string: '${instanceIdentifier}'` + ); + } +} diff --git a/packages/vertexai/src/index.node.ts b/packages/vertexai/src/index.node.ts index 6a18788141a..414aefdaffb 100644 --- a/packages/vertexai/src/index.node.ts +++ b/packages/vertexai/src/index.node.ts @@ -22,21 +22,35 @@ */ import { registerVersion, _registerComponent } from '@firebase/app'; -import { VertexAIService } from './service'; -import { VERTEX_TYPE } from './constants'; +import { GenAIService } from './service'; +import { DEFAULT_INSTANCE_IDENTIFER, GENAI_TYPE } from './constants'; import { Component, ComponentType } from '@firebase/component'; import { name, version } from '../package.json'; +import { InstanceIdentifier } from './types/internal'; +import { decodeInstanceIdentifier } from './helpers'; -function registerVertex(): void { +function registerGenAI(): void { _registerComponent( new Component( - VERTEX_TYPE, - (container, { instanceIdentifier: location }) => { + GENAI_TYPE, + (container, options) => { // getImmediate for FirebaseApp will always succeed const app = container.getProvider('app').getImmediate(); const auth = container.getProvider('auth-internal'); const appCheckProvider = container.getProvider('app-check-internal'); - return new VertexAIService(app, auth, appCheckProvider, { location }); + + let instanceIdentifier: InstanceIdentifier; + if (options.instanceIdentifier) { + instanceIdentifier = decodeInstanceIdentifier( + options.instanceIdentifier + ); + } else { + instanceIdentifier = DEFAULT_INSTANCE_IDENTIFER; + } + + const backend = instanceIdentifier; + + return new GenAIService(app, backend, auth, appCheckProvider); }, ComponentType.PUBLIC ).setMultipleInstances(true) @@ -47,7 +61,7 @@ function registerVertex(): void { registerVersion(name, version, '__BUILD_TARGET__'); } -registerVertex(); +registerGenAI(); export * from './api'; export * from './public-types'; diff --git a/packages/vertexai/src/index.ts b/packages/vertexai/src/index.ts index 5d646e8d9d0..985469c5ce1 100644 --- a/packages/vertexai/src/index.ts +++ b/packages/vertexai/src/index.ts @@ -6,7 +6,7 @@ /** * @license - * Copyright 2024 Google LLC + * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,13 @@ */ import { registerVersion, _registerComponent } from '@firebase/app'; -import { VertexAIService } from './service'; -import { VERTEX_TYPE } from './constants'; +import { GenAIService } from './service'; +import { GENAI_TYPE } from './constants'; import { Component, ComponentType } from '@firebase/component'; import { name, version } from '../package.json'; +import { decodeInstanceIdentifier } from './helpers'; +import { GenAIError } from './api'; +import { GenAIErrorCode } from './types'; declare global { interface Window { @@ -33,16 +36,24 @@ declare global { } } -function registerVertex(): void { +function registerGenAI(): void { _registerComponent( new Component( - VERTEX_TYPE, - (container, { instanceIdentifier: location }) => { + GENAI_TYPE, + (container, { instanceIdentifier }) => { + if (!instanceIdentifier) { + throw new GenAIError( + GenAIErrorCode.ERROR, + 'GenAIService instance identifier is undefined.' + ); + } + + const backend = decodeInstanceIdentifier(instanceIdentifier); // getImmediate for FirebaseApp will always succeed const app = container.getProvider('app').getImmediate(); const auth = container.getProvider('auth-internal'); const appCheckProvider = container.getProvider('app-check-internal'); - return new VertexAIService(app, auth, appCheckProvider, { location }); + return new GenAIService(app, backend, auth, appCheckProvider); }, ComponentType.PUBLIC ).setMultipleInstances(true) @@ -53,7 +64,7 @@ function registerVertex(): void { registerVersion(name, version, '__BUILD_TARGET__'); } -registerVertex(); +registerGenAI(); export * from './api'; export * from './public-types'; diff --git a/packages/vertexai/src/methods/chat-session-helpers.ts b/packages/vertexai/src/methods/chat-session-helpers.ts index 899db4f626a..a1a1713f584 100644 --- a/packages/vertexai/src/methods/chat-session-helpers.ts +++ b/packages/vertexai/src/methods/chat-session-helpers.ts @@ -15,14 +15,8 @@ * limitations under the License. */ -import { - Content, - POSSIBLE_ROLES, - Part, - Role, - VertexAIErrorCode -} from '../types'; -import { VertexAIError } from '../errors'; +import { Content, POSSIBLE_ROLES, Part, Role, GenAIErrorCode } from '../types'; +import { GenAIError } from '../errors'; // https://ai.google.dev/api/rest/v1beta/Content#part @@ -54,14 +48,14 @@ export function validateChatHistory(history: Content[]): void { for (const currContent of history) { const { role, parts } = currContent; if (!prevContent && role !== 'user') { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, `First Content should be with role 'user', got ${role}` ); } if (!POSSIBLE_ROLES.includes(role)) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, `Each item should include role field. Got ${role} but valid roles are: ${JSON.stringify( POSSIBLE_ROLES )}` @@ -69,15 +63,15 @@ export function validateChatHistory(history: Content[]): void { } if (!Array.isArray(parts)) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, `Content should have 'parts' but property with an array of Parts` ); } if (parts.length === 0) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, `Each Content should have at least one part` ); } @@ -99,8 +93,8 @@ export function validateChatHistory(history: Content[]): void { const validParts = VALID_PARTS_PER_ROLE[role]; for (const key of VALID_PART_FIELDS) { if (!validParts.includes(key) && countFields[key] > 0) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, `Content with role '${role}' can't contain '${key}' part` ); } @@ -109,8 +103,8 @@ export function validateChatHistory(history: Content[]): void { if (prevContent) { const validPreviousContentRoles = VALID_PREVIOUS_CONTENT_ROLES[role]; if (!validPreviousContentRoles.includes(prevContent.role)) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, `Content with role '${role} can't follow '${ prevContent.role }'. Valid previous roles: ${JSON.stringify( diff --git a/packages/vertexai/src/methods/chat-session.test.ts b/packages/vertexai/src/methods/chat-session.test.ts index bd389a3d778..cbfcd22e3e0 100644 --- a/packages/vertexai/src/methods/chat-session.test.ts +++ b/packages/vertexai/src/methods/chat-session.test.ts @@ -23,6 +23,7 @@ import * as generateContentMethods from './generate-content'; import { GenerateContentStreamResult } from '../types'; import { ChatSession } from './chat-session'; import { ApiSettings } from '../types/internal'; +import { vertexAIBackend } from '../api'; use(sinonChai); use(chaiAsPromised); @@ -31,7 +32,8 @@ const fakeApiSettings: ApiSettings = { apiKey: 'key', project: 'my-project', appId: 'my-appid', - location: 'us-central1' + location: 'us-central1', + backend: vertexAIBackend() }; describe('ChatSession', () => { diff --git a/packages/vertexai/src/methods/count-tokens.test.ts b/packages/vertexai/src/methods/count-tokens.test.ts index 9eccbf702fe..bdf99711f55 100644 --- a/packages/vertexai/src/methods/count-tokens.test.ts +++ b/packages/vertexai/src/methods/count-tokens.test.ts @@ -16,7 +16,7 @@ */ import { expect, use } from 'chai'; -import { match, restore, stub } from 'sinon'; +import Sinon, { match, restore, stub } from 'sinon'; import sinonChai from 'sinon-chai'; import chaiAsPromised from 'chai-as-promised'; import { getMockResponse } from '../../test-utils/mock-response'; @@ -25,6 +25,8 @@ import { countTokens } from './count-tokens'; import { CountTokensRequest } from '../types'; import { ApiSettings } from '../types/internal'; import { Task } from '../requests/request'; +import { googleAIBackend, vertexAIBackend } from '../api'; +import { mapCountTokensRequest } from '../googleAIMappers'; use(sinonChai); use(chaiAsPromised); @@ -33,7 +35,16 @@ const fakeApiSettings: ApiSettings = { apiKey: 'key', project: 'my-project', appId: 'my-appid', - location: 'us-central1' + location: 'us-central1', + backend: vertexAIBackend() +}; + +const fakeGoogleAIApiSettings: ApiSettings = { + apiKey: 'key', + project: 'my-project', + appId: 'my-appid', + location: 'us-central1', + backend: googleAIBackend() }; const fakeRequestParams: CountTokensRequest = { @@ -139,4 +150,30 @@ describe('countTokens()', () => { ).to.be.rejectedWith(/404.*not found/); expect(mockFetch).to.be.called; }); + describe('googleAI', () => { + let makeRequestStub: Sinon.SinonStub; + + beforeEach(() => { + makeRequestStub = stub(request, 'makeRequest'); + }); + + afterEach(() => { + restore(); + }); + + it('maps request to GoogleAI format', async () => { + makeRequestStub.resolves({ ok: true, json: () => {} } as Response); // Unused + + await countTokens(fakeGoogleAIApiSettings, 'model', fakeRequestParams); + + expect(makeRequestStub).to.be.calledWith( + 'model', + Task.COUNT_TOKENS, + fakeGoogleAIApiSettings, + false, + JSON.stringify(mapCountTokensRequest(fakeRequestParams, 'model')), + undefined + ); + }); + }); }); diff --git a/packages/vertexai/src/methods/count-tokens.ts b/packages/vertexai/src/methods/count-tokens.ts index c9d43a5b6fd..3a94f181126 100644 --- a/packages/vertexai/src/methods/count-tokens.ts +++ b/packages/vertexai/src/methods/count-tokens.ts @@ -22,6 +22,8 @@ import { } from '../types'; import { Task, makeRequest } from '../requests/request'; import { ApiSettings } from '../types/internal'; +import * as GoogleAIMapper from '../googleAIMappers'; +import { BackendType } from '../public-types'; export async function countTokens( apiSettings: ApiSettings, @@ -29,12 +31,19 @@ export async function countTokens( params: CountTokensRequest, requestOptions?: RequestOptions ): Promise { + let body: string = ''; + if (apiSettings.backend.backendType === BackendType.GOOGLE_AI) { + const mappedParams = GoogleAIMapper.mapCountTokensRequest(params, model); + body = JSON.stringify(mappedParams); + } else { + body = JSON.stringify(params); + } const response = await makeRequest( model, Task.COUNT_TOKENS, apiSettings, false, - JSON.stringify(params), + body, requestOptions ); return response.json(); diff --git a/packages/vertexai/src/methods/generate-content.test.ts b/packages/vertexai/src/methods/generate-content.test.ts index 1d15632f828..181d7d45b84 100644 --- a/packages/vertexai/src/methods/generate-content.test.ts +++ b/packages/vertexai/src/methods/generate-content.test.ts @@ -16,13 +16,14 @@ */ import { expect, use } from 'chai'; -import { match, restore, stub } from 'sinon'; +import Sinon, { match, restore, stub } from 'sinon'; import sinonChai from 'sinon-chai'; import chaiAsPromised from 'chai-as-promised'; import { getMockResponse } from '../../test-utils/mock-response'; import * as request from '../requests/request'; import { generateContent } from './generate-content'; import { + GenAIErrorCode, GenerateContentRequest, HarmBlockMethod, HarmBlockThreshold, @@ -30,6 +31,8 @@ import { } from '../types'; import { ApiSettings } from '../types/internal'; import { Task } from '../requests/request'; +import { GenAIError, googleAIBackend, vertexAIBackend } from '../api'; +import { mapGenerateContentRequest } from '../googleAIMappers'; use(sinonChai); use(chaiAsPromised); @@ -38,7 +41,16 @@ const fakeApiSettings: ApiSettings = { apiKey: 'key', project: 'my-project', appId: 'my-appid', - location: 'us-central1' + location: 'us-central1', + backend: vertexAIBackend() +}; + +const fakeGoogleAIApiSettings: ApiSettings = { + apiKey: 'key', + project: 'my-project', + appId: 'my-appid', + location: 'us-central1', + backend: googleAIBackend() }; const fakeRequestParams: GenerateContentRequest = { @@ -55,6 +67,19 @@ const fakeRequestParams: GenerateContentRequest = { ] }; +const fakeGoogleAIRequestParams: GenerateContentRequest = { + contents: [{ parts: [{ text: 'hello' }], role: 'user' }], + generationConfig: { + topK: 16 + }, + safetySettings: [ + { + category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, + threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE + } + ] +}; + describe('generateContent()', () => { afterEach(() => { restore(); @@ -78,9 +103,7 @@ describe('generateContent()', () => { Task.GENERATE_CONTENT, fakeApiSettings, false, - match((value: string) => { - return value.includes('contents'); - }), + JSON.stringify(fakeRequestParams), undefined ); }); @@ -289,4 +312,66 @@ describe('generateContent()', () => { ); expect(mockFetch).to.be.called; }); + describe('googleAI', () => { + let makeRequestStub: Sinon.SinonStub; + + beforeEach(() => { + makeRequestStub = stub(request, 'makeRequest'); + }); + + afterEach(() => { + restore(); + }); + + it('throws error when method is defined', async () => { + const mockResponse = getMockResponse( + 'googleAI', + 'unary-success-basic-reply-short.txt' + ); + makeRequestStub.resolves(mockResponse as Response); + + const requestParamsWithMethod: GenerateContentRequest = { + contents: [{ parts: [{ text: 'hello' }], role: 'user' }], + safetySettings: [ + { + category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, + threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, + method: HarmBlockMethod.SEVERITY // Unsupported in Google AI. + } + ] + }; + + // Expect generateContent to throw a GenAIError that method is not supported. + await expect( + generateContent( + fakeGoogleAIApiSettings, + 'model', + requestParamsWithMethod + ) + ).to.be.rejectedWith(GenAIError, GenAIErrorCode.UNSUPPORTED); + expect(makeRequestStub).to.not.be.called; + }); + it('maps request to GoogleAI format', async () => { + const mockResponse = getMockResponse( + 'googleAI', + 'unary-success-basic-reply-short.txt' + ); + makeRequestStub.resolves(mockResponse as Response); + + await generateContent( + fakeGoogleAIApiSettings, + 'model', + fakeGoogleAIRequestParams + ); + + expect(makeRequestStub).to.be.calledWith( + 'model', + Task.GENERATE_CONTENT, + fakeGoogleAIApiSettings, + false, + JSON.stringify(mapGenerateContentRequest(fakeGoogleAIRequestParams)), + undefined + ); + }); + }); }); diff --git a/packages/vertexai/src/methods/generate-content.ts b/packages/vertexai/src/methods/generate-content.ts index 0944b38016a..f05ca41c0bc 100644 --- a/packages/vertexai/src/methods/generate-content.ts +++ b/packages/vertexai/src/methods/generate-content.ts @@ -26,6 +26,8 @@ import { Task, makeRequest } from '../requests/request'; import { createEnhancedContentResponse } from '../requests/response-helpers'; import { processStream } from '../requests/stream-reader'; import { ApiSettings } from '../types/internal'; +import * as GoogleAIMapper from '../googleAIMappers'; +import { BackendType } from '../public-types'; export async function generateContentStream( apiSettings: ApiSettings, @@ -33,6 +35,9 @@ export async function generateContentStream( params: GenerateContentRequest, requestOptions?: RequestOptions ): Promise { + if (apiSettings.backend.backendType === BackendType.GOOGLE_AI) { + params = GoogleAIMapper.mapGenerateContentRequest(params); + } const response = await makeRequest( model, Task.STREAM_GENERATE_CONTENT, @@ -41,7 +46,7 @@ export async function generateContentStream( JSON.stringify(params), requestOptions ); - return processStream(response); + return processStream(response, apiSettings); // TODO: Map streaming responses } export async function generateContent( @@ -50,6 +55,9 @@ export async function generateContent( params: GenerateContentRequest, requestOptions?: RequestOptions ): Promise { + if (apiSettings.backend.backendType === BackendType.GOOGLE_AI) { + params = GoogleAIMapper.mapGenerateContentRequest(params); + } const response = await makeRequest( model, Task.GENERATE_CONTENT, @@ -58,9 +66,26 @@ export async function generateContent( JSON.stringify(params), requestOptions ); - const responseJson: GenerateContentResponse = await response.json(); - const enhancedResponse = createEnhancedContentResponse(responseJson); + const generateContentResponse = await handleGenerateContentResponse( + response, + apiSettings + ); + const enhancedResponse = createEnhancedContentResponse( + generateContentResponse + ); return { response: enhancedResponse }; } + +async function handleGenerateContentResponse( + response: Response, + apiSettings: ApiSettings +): Promise { + const responseJson = await response.json(); + if (apiSettings.backend.backendType === BackendType.GOOGLE_AI) { + return GoogleAIMapper.mapGenerateContentResponse(responseJson); + } else { + return responseJson; + } +} diff --git a/packages/vertexai/src/models/vertexai-model.test.ts b/packages/vertexai/src/models/genai-model.test.ts similarity index 65% rename from packages/vertexai/src/models/vertexai-model.test.ts rename to packages/vertexai/src/models/genai-model.test.ts index 7aa7f806e7f..16bd54d9f6f 100644 --- a/packages/vertexai/src/models/vertexai-model.test.ts +++ b/packages/vertexai/src/models/genai-model.test.ts @@ -15,24 +15,25 @@ * limitations under the License. */ import { use, expect } from 'chai'; -import { VertexAI, VertexAIErrorCode } from '../public-types'; +import { GenAI, GenAIErrorCode } from '../public-types'; import sinonChai from 'sinon-chai'; -import { VertexAIModel } from './vertexai-model'; -import { VertexAIError } from '../errors'; +import { GenAIModel } from './genai-model'; +import { GenAIError } from '../errors'; +import { vertexAIBackend } from '../api'; use(sinonChai); /** - * A class that extends VertexAIModel that allows us to test the protected constructor. + * A class that extends GenAIModel that allows us to test the protected constructor. */ -class TestModel extends VertexAIModel { +class TestModel extends GenAIModel { /* eslint-disable @typescript-eslint/no-useless-constructor */ - constructor(vertexAI: VertexAI, modelName: string) { - super(vertexAI, modelName); + constructor(genAI: GenAI, modelName: string) { + super(genAI, modelName); } } -const fakeVertexAI: VertexAI = { +const fakeGenAI: GenAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -42,31 +43,32 @@ const fakeVertexAI: VertexAI = { appId: 'my-appid' } }, + backend: vertexAIBackend('us-central1'), location: 'us-central1' }; -describe('VertexAIModel', () => { +describe('GenAIModel', () => { it('handles plain model name', () => { - const testModel = new TestModel(fakeVertexAI, 'my-model'); + const testModel = new TestModel(fakeGenAI, 'my-model'); expect(testModel.model).to.equal('publishers/google/models/my-model'); }); it('handles models/ prefixed model name', () => { - const testModel = new TestModel(fakeVertexAI, 'models/my-model'); + const testModel = new TestModel(fakeGenAI, 'models/my-model'); expect(testModel.model).to.equal('publishers/google/models/my-model'); }); it('handles full model name', () => { const testModel = new TestModel( - fakeVertexAI, + fakeGenAI, 'publishers/google/models/my-model' ); expect(testModel.model).to.equal('publishers/google/models/my-model'); }); it('handles prefixed tuned model name', () => { - const testModel = new TestModel(fakeVertexAI, 'tunedModels/my-model'); + const testModel = new TestModel(fakeGenAI, 'tunedModels/my-model'); expect(testModel.model).to.equal('tunedModels/my-model'); }); it('throws if not passed an api key', () => { - const fakeVertexAI: VertexAI = { + const fakeGenAI: GenAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -74,16 +76,17 @@ describe('VertexAIModel', () => { projectId: 'my-project' } }, + backend: vertexAIBackend('us-central1'), location: 'us-central1' }; try { - new TestModel(fakeVertexAI, 'my-model'); + new TestModel(fakeGenAI, 'my-model'); } catch (e) { - expect((e as VertexAIError).code).to.equal(VertexAIErrorCode.NO_API_KEY); + expect((e as GenAIError).code).to.equal(GenAIErrorCode.NO_API_KEY); } }); it('throws if not passed a project ID', () => { - const fakeVertexAI: VertexAI = { + const fakeGenAI: GenAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -91,18 +94,17 @@ describe('VertexAIModel', () => { apiKey: 'key' } }, + backend: vertexAIBackend('us-central1'), location: 'us-central1' }; try { - new TestModel(fakeVertexAI, 'my-model'); + new TestModel(fakeGenAI, 'my-model'); } catch (e) { - expect((e as VertexAIError).code).to.equal( - VertexAIErrorCode.NO_PROJECT_ID - ); + expect((e as GenAIError).code).to.equal(GenAIErrorCode.NO_PROJECT_ID); } }); it('throws if not passed an app ID', () => { - const fakeVertexAI: VertexAI = { + const fakeGenAI: GenAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -111,12 +113,13 @@ describe('VertexAIModel', () => { projectId: 'my-project' } }, + backend: vertexAIBackend('us-central1'), location: 'us-central1' }; try { - new TestModel(fakeVertexAI, 'my-model'); + new TestModel(fakeGenAI, 'my-model'); } catch (e) { - expect((e as VertexAIError).code).to.equal(VertexAIErrorCode.NO_APP_ID); + expect((e as GenAIError).code).to.equal(GenAIErrorCode.NO_APP_ID); } }); }); diff --git a/packages/vertexai/src/models/vertexai-model.ts b/packages/vertexai/src/models/genai-model.ts similarity index 61% rename from packages/vertexai/src/models/vertexai-model.ts rename to packages/vertexai/src/models/genai-model.ts index cac14845961..28e67c8552d 100644 --- a/packages/vertexai/src/models/vertexai-model.ts +++ b/packages/vertexai/src/models/genai-model.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import { VertexAIError } from '../errors'; -import { VertexAI, VertexAIErrorCode } from '../public-types'; -import { VertexAIService } from '../service'; +import { GenAIError } from '../errors'; +import { GenAIErrorCode, GenAI, BackendType } from '../public-types'; +import { GenAIService } from '../service'; import { ApiSettings } from '../types/internal'; import { _isFirebaseServerApp } from '@firebase/app'; @@ -26,7 +26,7 @@ import { _isFirebaseServerApp } from '@firebase/app'; * * @public */ -export abstract class VertexAIModel { +export abstract class GenAIModel { /** * The fully qualified model resource name to use for generating images * (for example, `publishers/google/models/imagen-3.0-generate-002`). @@ -39,12 +39,12 @@ export abstract class VertexAIModel { protected _apiSettings: ApiSettings; /** - * Constructs a new instance of the {@link VertexAIModel} class. + * Constructs a new instance of the {@link GenAIModel} class. * * This constructor should only be called from subclasses that provide * a model API. * - * @param vertexAI - An instance of the Vertex AI in Firebase SDK. + * @param genAI - A {@link GenAI} instance. * @param modelName - The name of the model being used. It can be in one of the following formats: * - `my-model` (short name, will resolve to `publishers/google/models/my-model`) * - `models/my-model` (will resolve to `publishers/google/models/my-model`) @@ -55,51 +55,52 @@ export abstract class VertexAIModel { * * @internal */ - protected constructor(vertexAI: VertexAI, modelName: string) { - this.model = VertexAIModel.normalizeModelName(modelName); - - if (!vertexAI.app?.options?.apiKey) { - throw new VertexAIError( - VertexAIErrorCode.NO_API_KEY, + protected constructor(genAI: GenAI, modelName: string) { + if (!genAI.app?.options?.apiKey) { + throw new GenAIError( + GenAIErrorCode.NO_API_KEY, `The "apiKey" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid API key.` ); - } else if (!vertexAI.app?.options?.projectId) { - throw new VertexAIError( - VertexAIErrorCode.NO_PROJECT_ID, + } else if (!genAI.app?.options?.projectId) { + throw new GenAIError( + GenAIErrorCode.NO_PROJECT_ID, `The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.` ); - } else if (!vertexAI.app?.options?.appId) { - throw new VertexAIError( - VertexAIErrorCode.NO_APP_ID, + } else if (!genAI.app?.options?.appId) { + throw new GenAIError( + GenAIErrorCode.NO_APP_ID, `The "appId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid app ID.` ); } else { this._apiSettings = { - apiKey: vertexAI.app.options.apiKey, - project: vertexAI.app.options.projectId, - appId: vertexAI.app.options.appId, + apiKey: genAI.app.options.apiKey, + project: genAI.app.options.projectId, + appId: genAI.app.options.appId, automaticDataCollectionEnabled: - vertexAI.app.automaticDataCollectionEnabled, - location: vertexAI.location + genAI.app.automaticDataCollectionEnabled, + location: genAI.location, + backend: genAI.backend }; - if ( - _isFirebaseServerApp(vertexAI.app) && - vertexAI.app.settings.appCheckToken - ) { - const token = vertexAI.app.settings.appCheckToken; + if (_isFirebaseServerApp(genAI.app) && genAI.app.settings.appCheckToken) { + const token = genAI.app.settings.appCheckToken; this._apiSettings.getAppCheckToken = () => { return Promise.resolve({ token }); }; - } else if ((vertexAI as VertexAIService).appCheck) { + } else if ((genAI as GenAIService).appCheck) { this._apiSettings.getAppCheckToken = () => - (vertexAI as VertexAIService).appCheck!.getToken(); + (genAI as GenAIService).appCheck!.getToken(); } - if ((vertexAI as VertexAIService).auth) { + if ((genAI as GenAIService).auth) { this._apiSettings.getAuthToken = () => - (vertexAI as VertexAIService).auth!.getToken(); + (genAI as GenAIService).auth!.getToken(); } + + this.model = GenAIModel.normalizeModelName( + modelName, + this._apiSettings.backend.backendType + ); } } @@ -108,8 +109,31 @@ export abstract class VertexAIModel { * * @param modelName - The model name to normalize. * @returns The fully qualified model resource name. + * + * @internal + */ + static normalizeModelName( + modelName: string, + backendType: BackendType + ): string { + if (backendType === BackendType.GOOGLE_AI) { + return GenAIModel.normalizeGoogleAIModelName(modelName); + } else { + return GenAIModel.normalizeVertexAIModelName(modelName); + } + } + + /** + * @internal + */ + private static normalizeGoogleAIModelName(modelName: string): string { + return `models/${modelName}`; + } + + /** + * @internal */ - static normalizeModelName(modelName: string): string { + private static normalizeVertexAIModelName(modelName: string): string { let model: string; if (modelName.includes('/')) { if (modelName.startsWith('models/')) { diff --git a/packages/vertexai/src/models/generative-model.test.ts b/packages/vertexai/src/models/generative-model.test.ts index 987f9b115e2..a8245fe16ef 100644 --- a/packages/vertexai/src/models/generative-model.test.ts +++ b/packages/vertexai/src/models/generative-model.test.ts @@ -16,15 +16,16 @@ */ import { use, expect } from 'chai'; import { GenerativeModel } from './generative-model'; -import { FunctionCallingMode, VertexAI } from '../public-types'; +import { FunctionCallingMode, GenAI } from '../public-types'; import * as request from '../requests/request'; import { match, restore, stub } from 'sinon'; import { getMockResponse } from '../../test-utils/mock-response'; import sinonChai from 'sinon-chai'; +import { vertexAIBackend } from '../api'; use(sinonChai); -const fakeVertexAI: VertexAI = { +const fakeGenAI: GenAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -34,12 +35,13 @@ const fakeVertexAI: VertexAI = { appId: 'my-appid' } }, + backend: vertexAIBackend('us-central1'), location: 'us-central1' }; describe('GenerativeModel', () => { it('passes params through to generateContent', async () => { - const genModel = new GenerativeModel(fakeVertexAI, { + const genModel = new GenerativeModel(fakeGenAI, { model: 'my-model', tools: [ { @@ -84,7 +86,7 @@ describe('GenerativeModel', () => { restore(); }); it('passes text-only systemInstruction through to generateContent', async () => { - const genModel = new GenerativeModel(fakeVertexAI, { + const genModel = new GenerativeModel(fakeGenAI, { model: 'my-model', systemInstruction: 'be friendly' }); @@ -110,7 +112,7 @@ describe('GenerativeModel', () => { restore(); }); it('generateContent overrides model values', async () => { - const genModel = new GenerativeModel(fakeVertexAI, { + const genModel = new GenerativeModel(fakeGenAI, { model: 'my-model', tools: [ { @@ -166,7 +168,7 @@ describe('GenerativeModel', () => { restore(); }); it('passes params through to chat.sendMessage', async () => { - const genModel = new GenerativeModel(fakeVertexAI, { + const genModel = new GenerativeModel(fakeGenAI, { model: 'my-model', tools: [ { functionDeclarations: [{ name: 'myfunc', description: 'mydesc' }] } @@ -204,7 +206,7 @@ describe('GenerativeModel', () => { restore(); }); it('passes text-only systemInstruction through to chat.sendMessage', async () => { - const genModel = new GenerativeModel(fakeVertexAI, { + const genModel = new GenerativeModel(fakeGenAI, { model: 'my-model', systemInstruction: 'be friendly' }); @@ -230,7 +232,7 @@ describe('GenerativeModel', () => { restore(); }); it('startChat overrides model values', async () => { - const genModel = new GenerativeModel(fakeVertexAI, { + const genModel = new GenerativeModel(fakeGenAI, { model: 'my-model', tools: [ { functionDeclarations: [{ name: 'myfunc', description: 'mydesc' }] } @@ -282,7 +284,7 @@ describe('GenerativeModel', () => { restore(); }); it('calls countTokens', async () => { - const genModel = new GenerativeModel(fakeVertexAI, { model: 'my-model' }); + const genModel = new GenerativeModel(fakeGenAI, { model: 'my-model' }); const mockResponse = getMockResponse( 'vertexAI', 'unary-success-total-tokens.json' diff --git a/packages/vertexai/src/models/generative-model.ts b/packages/vertexai/src/models/generative-model.ts index 983118bf6ff..37880a794b7 100644 --- a/packages/vertexai/src/models/generative-model.ts +++ b/packages/vertexai/src/models/generative-model.ts @@ -41,14 +41,14 @@ import { formatGenerateContentInput, formatSystemInstruction } from '../requests/request-helpers'; -import { VertexAI } from '../public-types'; -import { VertexAIModel } from './vertexai-model'; +import { GenAI } from '../public-types'; +import { GenAIModel } from './genai-model'; /** * Class for generative model APIs. * @public */ -export class GenerativeModel extends VertexAIModel { +export class GenerativeModel extends GenAIModel { generationConfig: GenerationConfig; safetySettings: SafetySetting[]; requestOptions?: RequestOptions; @@ -57,11 +57,11 @@ export class GenerativeModel extends VertexAIModel { systemInstruction?: Content; constructor( - vertexAI: VertexAI, + genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions ) { - super(vertexAI, modelParams.model); + super(genAI, modelParams.model); this.generationConfig = modelParams.generationConfig || {}; this.safetySettings = modelParams.safetySettings || []; this.tools = modelParams.tools; diff --git a/packages/vertexai/src/models/imagen-model.test.ts b/packages/vertexai/src/models/imagen-model.test.ts index 9e534f2195a..e2a426a2416 100644 --- a/packages/vertexai/src/models/imagen-model.test.ts +++ b/packages/vertexai/src/models/imagen-model.test.ts @@ -20,18 +20,19 @@ import { ImagenAspectRatio, ImagenPersonFilterLevel, ImagenSafetyFilterLevel, - VertexAI, - VertexAIErrorCode + GenAI, + GenAIErrorCode } from '../public-types'; import * as request from '../requests/request'; import sinonChai from 'sinon-chai'; -import { VertexAIError } from '../errors'; +import { GenAIError } from '../errors'; import { getMockResponse } from '../../test-utils/mock-response'; import { match, restore, stub } from 'sinon'; +import { vertexAIBackend } from '../api'; use(sinonChai); -const fakeVertexAI: VertexAI = { +const fakeGenAI: GenAI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -41,6 +42,7 @@ const fakeVertexAI: VertexAI = { appId: 'my-appid' } }, + backend: vertexAIBackend('us-central1'), location: 'us-central1' }; @@ -54,7 +56,7 @@ describe('ImagenModel', () => { mockResponse as Response ); - const imagenModel = new ImagenModel(fakeVertexAI, { + const imagenModel = new ImagenModel(fakeGenAI, { model: 'my-model' }); const prompt = 'A photorealistic image of a toy boat at sea.'; @@ -75,7 +77,7 @@ describe('ImagenModel', () => { restore(); }); it('generateImages makes a request to predict with generation config and safety settings', async () => { - const imagenModel = new ImagenModel(fakeVertexAI, { + const imagenModel = new ImagenModel(fakeGenAI, { model: 'my-model', generationConfig: { negativePrompt: 'do not hallucinate', @@ -146,15 +148,15 @@ describe('ImagenModel', () => { json: mockResponse.json } as Response); - const imagenModel = new ImagenModel(fakeVertexAI, { + const imagenModel = new ImagenModel(fakeGenAI, { model: 'my-model' }); try { await imagenModel.generateImages('some inappropriate prompt.'); } catch (e) { - expect((e as VertexAIError).code).to.equal(VertexAIErrorCode.FETCH_ERROR); - expect((e as VertexAIError).message).to.include('400'); - expect((e as VertexAIError).message).to.include( + expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); + expect((e as GenAIError).message).to.include('400'); + expect((e as GenAIError).message).to.include( "Image generation failed with the following error: The prompt could not be submitted. This prompt contains sensitive words that violate Google's Responsible AI practices. Try rephrasing the prompt. If you think this was an error, send feedback." ); } finally { diff --git a/packages/vertexai/src/models/imagen-model.ts b/packages/vertexai/src/models/imagen-model.ts index 04514ef6ffd..9a36b3f6954 100644 --- a/packages/vertexai/src/models/imagen-model.ts +++ b/packages/vertexai/src/models/imagen-model.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { VertexAI } from '../public-types'; +import { GenAI } from '../public-types'; import { Task, makeRequest } from '../requests/request'; import { createPredictRequestBody } from '../requests/request-helpers'; import { handlePredictResponse } from '../requests/response-helpers'; @@ -28,7 +28,7 @@ import { ImagenGenerationResponse, ImagenSafetySettings } from '../types'; -import { VertexAIModel } from './vertexai-model'; +import { GenAIModel } from './genai-model'; /** * Class for Imagen model APIs. @@ -38,7 +38,7 @@ import { VertexAIModel } from './vertexai-model'; * @example * ```javascript * const imagen = new ImagenModel( - * vertexAI, + * genAI, * { * model: 'imagen-3.0-generate-002' * } @@ -52,7 +52,7 @@ import { VertexAIModel } from './vertexai-model'; * * @beta */ -export class ImagenModel extends VertexAIModel { +export class ImagenModel extends GenAIModel { /** * The Imagen generation configuration. */ @@ -65,7 +65,7 @@ export class ImagenModel extends VertexAIModel { /** * Constructs a new instance of the {@link ImagenModel} class. * - * @param vertexAI - An instance of the Vertex AI in Firebase SDK. + * @param genAI - A {@link GenAI} instance. * @param modelParams - Parameters to use when making requests to Imagen. * @param requestOptions - Additional options to use when making requests. * @@ -73,12 +73,12 @@ export class ImagenModel extends VertexAIModel { * Firebase config. */ constructor( - vertexAI: VertexAI, + genAI: GenAI, modelParams: ImagenModelParams, public requestOptions?: RequestOptions ) { const { model, generationConfig, safetySettings } = modelParams; - super(vertexAI, model); + super(genAI, model); this.generationConfig = generationConfig; this.safetySettings = safetySettings; } diff --git a/packages/vertexai/src/models/index.ts b/packages/vertexai/src/models/index.ts index aec06be26fd..3034aadedc8 100644 --- a/packages/vertexai/src/models/index.ts +++ b/packages/vertexai/src/models/index.ts @@ -15,6 +15,6 @@ * limitations under the License. */ -export * from './vertexai-model'; +export * from './genai-model'; export * from './generative-model'; export * from './imagen-model'; diff --git a/packages/vertexai/src/public-types.ts b/packages/vertexai/src/public-types.ts index fbc5d51084d..4dd7b3a53ba 100644 --- a/packages/vertexai/src/public-types.ts +++ b/packages/vertexai/src/public-types.ts @@ -21,20 +21,136 @@ export * from './types'; /** * An instance of the Vertex AI in Firebase SDK. + * + * For more information, refer to the documentation for the new {@link GenAI}. + * + * @public + */ +export type VertexAI = GenAI; + +/** + * Options when initializing the Vertex AI in Firebase SDK. + * + * @public + */ +export interface VertexAIOptions { + location?: string; +} + +/** + * An instance of the Firebase GenAI SDK. + * + * Do not create this instance directly. Instead, use {@link getGenAI | getGenAI()}. + * * @public */ -export interface VertexAI { +export interface GenAI { /** - * The {@link @firebase/app#FirebaseApp} this {@link VertexAI} instance is associated with. + * The {@link @firebase/app#FirebaseApp} this {@link GenAI} instance is associated with. */ app: FirebaseApp; + /** + * A {@link Backend} instance that specifies the backend configuration. + */ + backend: Backend; + /** + * The location configured for this GenAI service instance, relevant for Vertex AI backends. + * + * @deprecated use `GenAI.backend.location` instead. + */ location: string; } /** - * Options when initializing the Vertex AI in Firebase SDK. + * Union type representing the backend configuration for the GenAI service. + * This can be either a {@link GoogleAIBackend} or a + * {@link VertexAIBackend} configuration object. + * + * Create instances using {@link googleAIBackend | googleAIBackend() } or + * {@link vertexAIBackend | vertexAIBackend() }. + * * @public */ -export interface VertexAIOptions { - location?: string; +export type Backend = GoogleAIBackend | VertexAIBackend; + +/** + * Represents the configuration object for the Google AI backend. + * Use this with {@link GenAIOptions} when initializing the service with + * {@link getGenAI | getGenAI()}. + * Create an instance using {@link googleAIBackend | googleAIBackend()}. + * + * @public + */ +export type GoogleAIBackend = { + /** + * Specifies the backend type as Google AI. + */ + backendType: typeof BackendType.GOOGLE_AI; +}; + +/** + * Represents the configuration object for the Vertex AI backend. + * Use this with {@link GenAIOptions} when initializing the server with + * {@link getGenAI | getGenAI() }. + * Create an instance using {@link vertexAIBackend | vertexAIBackend() } function. + * + * @public + */ +export type VertexAIBackend = { + /** + * Specifies the backend type as Vertex AI. + */ + backendType: typeof BackendType.VERTEX_AI; + /** + * The region identifier, defaulting to `us-central1`; see {@link https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations | Vertex AI locations} + * for a list of supported locations. + */ + location: string; +}; + +/** + * An enum-like object containing constants that represent the supported backends + * for the Firebase GenAI SDK. + * + * These values are assigned to the `backendType` property within the specific backend + * configuration objects ({@link GoogleAIBackend} or {@link VertexAIBackend}) to identify + * which service to target. + * + * @public + */ +export const BackendType = { + /** + * Identifies the Vertex AI backend service provided through Google Cloud. + * Use this constant when creating a {@link VertexAIBackend} configuration. + */ + VERTEX_AI: 'VERTEX_AI', + + /** + * Identifies the Google AI backend service (often associated with models available + * through Google AI Studio, like Gemini). + * Use this constant when creating a {@link GoogleAIBackend} configuration. + */ + GOOGLE_AI: 'GOOGLE_AI' +} as const; // Using 'as const' makes the string values literal types + +/** + * Type alias representing valid backend types. + * It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. + * + * @public + */ +export type BackendType = (typeof BackendType)[keyof typeof BackendType]; + +/** + * Options interface for initializing the GenAI service using {@link getGenAI | getGenAI()}. + * + * @public + */ +export interface GenAIOptions { + /** + * The backend configuration to use for the GenAI service instance. + * Use {@link googleAIBackend | googleAIBackend()} or + * {@link vertexAIBackend | vertexAIBackend() } to create this configuration. + */ + backend: Backend; } diff --git a/packages/vertexai/src/requests/request-helpers.ts b/packages/vertexai/src/requests/request-helpers.ts index fd2cd04e0fd..411e61c991b 100644 --- a/packages/vertexai/src/requests/request-helpers.ts +++ b/packages/vertexai/src/requests/request-helpers.ts @@ -19,9 +19,9 @@ import { Content, GenerateContentRequest, Part, - VertexAIErrorCode + GenAIErrorCode } from '../types'; -import { VertexAIError } from '../errors'; +import { GenAIError } from '../errors'; import { ImagenGenerationParams, PredictRequestBody } from '../types/internal'; export function formatSystemInstruction( @@ -87,15 +87,15 @@ function assignRoleToPartsAndValidateSendMessageRequest( } if (hasUserContent && hasFunctionContent) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, 'Within a single message, FunctionResponse cannot be mixed with other type of Part in the request for sending chat message.' ); } if (!hasUserContent && !hasFunctionContent) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, 'No Content is provided for sending chat message.' ); } diff --git a/packages/vertexai/src/requests/request.test.ts b/packages/vertexai/src/requests/request.test.ts index cd39a0f8ae5..62c0a230944 100644 --- a/packages/vertexai/src/requests/request.test.ts +++ b/packages/vertexai/src/requests/request.test.ts @@ -22,9 +22,10 @@ import chaiAsPromised from 'chai-as-promised'; import { RequestUrl, Task, getHeaders, makeRequest } from './request'; import { ApiSettings } from '../types/internal'; import { DEFAULT_API_VERSION } from '../constants'; -import { VertexAIErrorCode } from '../types'; -import { VertexAIError } from '../errors'; +import { GenAIErrorCode } from '../types'; +import { GenAIError } from '../errors'; import { getMockResponse } from '../../test-utils/mock-response'; +import { vertexAIBackend } from '../api'; use(sinonChai); use(chaiAsPromised); @@ -33,7 +34,8 @@ const fakeApiSettings: ApiSettings = { apiKey: 'key', project: 'my-project', appId: 'my-appid', - location: 'us-central1' + location: 'us-central1', + backend: vertexAIBackend() }; describe('request methods', () => { @@ -106,6 +108,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', + backend: vertexAIBackend(), getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }), getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' }) }; @@ -132,6 +135,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', + backend: vertexAIBackend(), automaticDataCollectionEnabled: true, getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }), getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' }) @@ -156,6 +160,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', + backend: vertexAIBackend(), automaticDataCollectionEnabled: false, getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }), getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' }) @@ -182,7 +187,8 @@ describe('request methods', () => { apiKey: 'key', project: 'myproject', appId: 'my-appid', - location: 'moon' + location: 'moon', + backend: vertexAIBackend() }, true, {} @@ -216,6 +222,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', + backend: vertexAIBackend(), getAppCheckToken: () => Promise.resolve({ token: 'dummytoken', error: Error('oops') }) }, @@ -242,7 +249,8 @@ describe('request methods', () => { apiKey: 'key', project: 'myproject', appId: 'my-appid', - location: 'moon' + location: 'moon', + backend: vertexAIBackend() }, true, {} @@ -302,14 +310,12 @@ describe('request methods', () => { } ); } catch (e) { - expect((e as VertexAIError).code).to.equal( - VertexAIErrorCode.FETCH_ERROR - ); - expect((e as VertexAIError).customErrorData?.status).to.equal(500); - expect((e as VertexAIError).customErrorData?.statusText).to.equal( + expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); + expect((e as GenAIError).customErrorData?.status).to.equal(500); + expect((e as GenAIError).customErrorData?.statusText).to.equal( 'AbortError' ); - expect((e as VertexAIError).message).to.include('500 AbortError'); + expect((e as GenAIError).message).to.include('500 AbortError'); } expect(fetchStub).to.be.calledOnce; @@ -329,14 +335,12 @@ describe('request methods', () => { '' ); } catch (e) { - expect((e as VertexAIError).code).to.equal( - VertexAIErrorCode.FETCH_ERROR - ); - expect((e as VertexAIError).customErrorData?.status).to.equal(500); - expect((e as VertexAIError).customErrorData?.statusText).to.equal( + expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); + expect((e as GenAIError).customErrorData?.status).to.equal(500); + expect((e as GenAIError).customErrorData?.statusText).to.equal( 'Server Error' ); - expect((e as VertexAIError).message).to.include('500 Server Error'); + expect((e as GenAIError).message).to.include('500 Server Error'); } expect(fetchStub).to.be.calledOnce; }); @@ -356,15 +360,13 @@ describe('request methods', () => { '' ); } catch (e) { - expect((e as VertexAIError).code).to.equal( - VertexAIErrorCode.FETCH_ERROR - ); - expect((e as VertexAIError).customErrorData?.status).to.equal(500); - expect((e as VertexAIError).customErrorData?.statusText).to.equal( + expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); + expect((e as GenAIError).customErrorData?.status).to.equal(500); + expect((e as GenAIError).customErrorData?.statusText).to.equal( 'Server Error' ); - expect((e as VertexAIError).message).to.include('500 Server Error'); - expect((e as VertexAIError).message).to.include('extra info'); + expect((e as GenAIError).message).to.include('500 Server Error'); + expect((e as GenAIError).message).to.include('extra info'); } expect(fetchStub).to.be.calledOnce; }); @@ -396,16 +398,14 @@ describe('request methods', () => { '' ); } catch (e) { - expect((e as VertexAIError).code).to.equal( - VertexAIErrorCode.FETCH_ERROR - ); - expect((e as VertexAIError).customErrorData?.status).to.equal(500); - expect((e as VertexAIError).customErrorData?.statusText).to.equal( + expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); + expect((e as GenAIError).customErrorData?.status).to.equal(500); + expect((e as GenAIError).customErrorData?.statusText).to.equal( 'Server Error' ); - expect((e as VertexAIError).message).to.include('500 Server Error'); - expect((e as VertexAIError).message).to.include('extra info'); - expect((e as VertexAIError).message).to.include( + expect((e as GenAIError).message).to.include('500 Server Error'); + expect((e as GenAIError).message).to.include('extra info'); + expect((e as GenAIError).message).to.include( 'generic::invalid_argument' ); } @@ -429,11 +429,9 @@ describe('request methods', () => { '' ); } catch (e) { - expect((e as VertexAIError).code).to.equal( - VertexAIErrorCode.API_NOT_ENABLED - ); - expect((e as VertexAIError).message).to.include('my-project'); - expect((e as VertexAIError).message).to.include('googleapis.com'); + expect((e as GenAIError).code).to.equal(GenAIErrorCode.API_NOT_ENABLED); + expect((e as GenAIError).message).to.include('my-project'); + expect((e as GenAIError).message).to.include('googleapis.com'); } expect(fetchStub).to.be.calledOnce; }); diff --git a/packages/vertexai/src/requests/request.ts b/packages/vertexai/src/requests/request.ts index 47e4c6ab446..64e299fc422 100644 --- a/packages/vertexai/src/requests/request.ts +++ b/packages/vertexai/src/requests/request.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { ErrorDetails, RequestOptions, VertexAIErrorCode } from '../types'; -import { VertexAIError } from '../errors'; +import { ErrorDetails, RequestOptions, GenAIErrorCode } from '../types'; +import { GenAIError } from '../errors'; import { ApiSettings } from '../types/internal'; import { DEFAULT_API_VERSION, @@ -26,6 +26,7 @@ import { PACKAGE_VERSION } from '../constants'; import { logger } from '../logger'; +import { BackendType } from '../public-types'; export enum Task { GENERATE_CONTENT = 'generateContent', @@ -43,29 +44,35 @@ export class RequestUrl { public requestOptions?: RequestOptions ) {} toString(): string { - // TODO: allow user-set option if that feature becomes available - const apiVersion = DEFAULT_API_VERSION; - const baseUrl = this.requestOptions?.baseUrl || DEFAULT_BASE_URL; - let url = `${baseUrl}/${apiVersion}`; - url += `/projects/${this.apiSettings.project}`; - url += `/locations/${this.apiSettings.location}`; - url += `/${this.model}`; - url += `:${this.task}`; - if (this.stream) { - url += '?alt=sse'; + const url = new URL(this.baseUrl); // Throws if the URL is invalid + url.pathname = `/${this.apiVersion}/${this.modelPath}:${this.task}`; + url.search = this.queryParams.toString(); + return url.toString(); + } + + private get baseUrl(): string { + return this.requestOptions?.baseUrl || DEFAULT_BASE_URL; + } + + private get apiVersion(): string { + return DEFAULT_API_VERSION; // TODO: allow user-set options if that feature becomes available + } + + private get modelPath(): string { + if (this.apiSettings.backend.backendType === BackendType.GOOGLE_AI) { + return `projects/${this.apiSettings.project}/${this.model}`; + } else { + return `projects/${this.apiSettings.project}/locations/${this.apiSettings.backend.location}/${this.model}`; } - return url; } - /** - * If the model needs to be passed to the backend, it needs to - * include project and location path. - */ - get fullModelString(): string { - let modelString = `projects/${this.apiSettings.project}`; - modelString += `/locations/${this.apiSettings.location}`; - modelString += `/${this.model}`; - return modelString; + private get queryParams(): URLSearchParams { + const params = new URLSearchParams(); + if (this.stream) { + params.set('alt', 'sse'); + } + + return params; } } @@ -184,8 +191,8 @@ export async function makeRequest( ) ) ) { - throw new VertexAIError( - VertexAIErrorCode.API_NOT_ENABLED, + throw new GenAIError( + GenAIErrorCode.API_NOT_ENABLED, `The Vertex AI in Firebase SDK requires the Vertex AI in Firebase ` + `API ('firebasevertexai.googleapis.com') to be enabled in your ` + `Firebase project. Enable this API by visiting the Firebase Console ` + @@ -200,8 +207,8 @@ export async function makeRequest( } ); } - throw new VertexAIError( - VertexAIErrorCode.FETCH_ERROR, + throw new GenAIError( + GenAIErrorCode.FETCH_ERROR, `Error fetching from ${url}: [${response.status} ${response.statusText}] ${message}`, { status: response.status, @@ -213,12 +220,12 @@ export async function makeRequest( } catch (e) { let err = e as Error; if ( - (e as VertexAIError).code !== VertexAIErrorCode.FETCH_ERROR && - (e as VertexAIError).code !== VertexAIErrorCode.API_NOT_ENABLED && + (e as GenAIError).code !== GenAIErrorCode.FETCH_ERROR && + (e as GenAIError).code !== GenAIErrorCode.API_NOT_ENABLED && e instanceof Error ) { - err = new VertexAIError( - VertexAIErrorCode.ERROR, + err = new GenAIError( + GenAIErrorCode.ERROR, `Error fetching from ${url.toString()}: ${e.message}` ); err.stack = e.stack; diff --git a/packages/vertexai/src/requests/response-helpers.ts b/packages/vertexai/src/requests/response-helpers.ts index 6d0e3bf2a0a..db79abaf937 100644 --- a/packages/vertexai/src/requests/response-helpers.ts +++ b/packages/vertexai/src/requests/response-helpers.ts @@ -23,9 +23,9 @@ import { GenerateContentResponse, ImagenGCSImage, ImagenInlineImage, - VertexAIErrorCode + GenAIErrorCode } from '../types'; -import { VertexAIError } from '../errors'; +import { GenAIError } from '../errors'; import { logger } from '../logger'; import { ImagenResponseInternal } from '../types/internal'; @@ -67,8 +67,8 @@ export function addHelpers( ); } if (hadBadFinishReason(response.candidates[0])) { - throw new VertexAIError( - VertexAIErrorCode.RESPONSE_ERROR, + throw new GenAIError( + GenAIErrorCode.RESPONSE_ERROR, `Response error: ${formatBlockErrorMessage( response )}. Response body stored in error.response`, @@ -79,8 +79,8 @@ export function addHelpers( } return getText(response); } else if (response.promptFeedback) { - throw new VertexAIError( - VertexAIErrorCode.RESPONSE_ERROR, + throw new GenAIError( + GenAIErrorCode.RESPONSE_ERROR, `Text not available. ${formatBlockErrorMessage(response)}`, { response @@ -99,8 +99,8 @@ export function addHelpers( ); } if (hadBadFinishReason(response.candidates[0])) { - throw new VertexAIError( - VertexAIErrorCode.RESPONSE_ERROR, + throw new GenAIError( + GenAIErrorCode.RESPONSE_ERROR, `Response error: ${formatBlockErrorMessage( response )}. Response body stored in error.response`, @@ -111,8 +111,8 @@ export function addHelpers( } return getFunctionCalls(response); } else if (response.promptFeedback) { - throw new VertexAIError( - VertexAIErrorCode.RESPONSE_ERROR, + throw new GenAIError( + GenAIErrorCode.RESPONSE_ERROR, `Function call not available. ${formatBlockErrorMessage(response)}`, { response @@ -217,8 +217,8 @@ export async function handlePredictResponse< // The backend should always send a non-empty array of predictions if the response was successful. if (!responseJson.predictions || responseJson.predictions?.length === 0) { - throw new VertexAIError( - VertexAIErrorCode.RESPONSE_ERROR, + throw new GenAIError( + GenAIErrorCode.RESPONSE_ERROR, 'No predictions or filtered reason received from Vertex AI. Please report this issue with the full error details at https://github.com/firebase/firebase-js-sdk/issues.' ); } @@ -237,8 +237,8 @@ export async function handlePredictResponse< gcsURI: prediction.gcsUri } as T); } else { - throw new VertexAIError( - VertexAIErrorCode.RESPONSE_ERROR, + throw new GenAIError( + GenAIErrorCode.RESPONSE_ERROR, `Predictions array in response has missing properties. Response: ${JSON.stringify( responseJson )}` diff --git a/packages/vertexai/src/requests/schema-builder.test.ts b/packages/vertexai/src/requests/schema-builder.test.ts index b95acaae9f1..8cef35ade8d 100644 --- a/packages/vertexai/src/requests/schema-builder.test.ts +++ b/packages/vertexai/src/requests/schema-builder.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import sinonChai from 'sinon-chai'; import { Schema } from './schema-builder'; -import { VertexAIErrorCode } from '../types'; +import { GenAIErrorCode } from '../types'; use(sinonChai); @@ -243,7 +243,7 @@ describe('Schema builder', () => { }, optionalProperties: ['cat'] }); - expect(() => schema.toJSON()).to.throw(VertexAIErrorCode.INVALID_SCHEMA); + expect(() => schema.toJSON()).to.throw(GenAIErrorCode.INVALID_SCHEMA); }); }); diff --git a/packages/vertexai/src/requests/schema-builder.ts b/packages/vertexai/src/requests/schema-builder.ts index 3d219d58b13..a729b0a6ebf 100644 --- a/packages/vertexai/src/requests/schema-builder.ts +++ b/packages/vertexai/src/requests/schema-builder.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { VertexAIError } from '../errors'; -import { VertexAIErrorCode } from '../types'; +import { GenAIError } from '../errors'; +import { GenAIErrorCode } from '../types'; import { SchemaInterface, SchemaType, @@ -266,8 +266,8 @@ export class ObjectSchema extends Schema { if (this.optionalProperties) { for (const propertyKey of this.optionalProperties) { if (!this.properties.hasOwnProperty(propertyKey)) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_SCHEMA, + throw new GenAIError( + GenAIErrorCode.INVALID_SCHEMA, `Property "${propertyKey}" specified in "optionalProperties" does not exist.` ); } diff --git a/packages/vertexai/src/requests/stream-reader.test.ts b/packages/vertexai/src/requests/stream-reader.test.ts index bf959276a93..2e7041f064a 100644 --- a/packages/vertexai/src/requests/stream-reader.test.ts +++ b/packages/vertexai/src/requests/stream-reader.test.ts @@ -34,9 +34,19 @@ import { HarmCategory, HarmProbability, SafetyRating, - VertexAIErrorCode + GenAIErrorCode } from '../types'; -import { VertexAIError } from '../errors'; +import { GenAIError } from '../errors'; +import { ApiSettings } from '../types/internal'; +import { vertexAIBackend } from '../api'; + +const fakeApiSettings: ApiSettings = { + apiKey: 'key', + project: 'my-project', + appId: 'my-appid', + location: 'us-central1', + backend: vertexAIBackend() +}; use(sinonChai); @@ -75,7 +85,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-success-basic-reply-short.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); for await (const response of result.stream) { expect(response.text()).to.not.be.empty; } @@ -87,7 +97,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-success-basic-reply-long.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); for await (const response of result.stream) { expect(response.text()).to.not.be.empty; } @@ -101,7 +111,7 @@ describe('processStream', () => { 'streaming-success-basic-reply-long.txt', 1e6 ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); for await (const response of result.stream) { expect(response.text()).to.not.be.empty; } @@ -114,7 +124,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-success-utf8.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); for await (const response of result.stream) { expect(response.text()).to.not.be.empty; } @@ -127,7 +137,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-success-function-call-short.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); for await (const response of result.stream) { expect(response.text()).to.be.empty; expect(response.functionCalls()).to.be.deep.equal([ @@ -151,7 +161,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-failure-finish-reason-safety.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); const aggregatedResponse = await result.response; expect(aggregatedResponse.candidates?.[0].finishReason).to.equal('SAFETY'); expect(aggregatedResponse.text).to.throw('SAFETY'); @@ -164,7 +174,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-failure-prompt-blocked-safety.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); const aggregatedResponse = await result.response; expect(aggregatedResponse.text).to.throw('SAFETY'); expect(aggregatedResponse.promptFeedback?.blockReason).to.equal('SAFETY'); @@ -177,7 +187,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-failure-empty-content.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); const aggregatedResponse = await result.response; expect(aggregatedResponse.text()).to.equal(''); for await (const response of result.stream) { @@ -189,7 +199,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-success-unknown-safety-enum.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); const aggregatedResponse = await result.response; expect(aggregatedResponse.text()).to.include('Cats'); for await (const response of result.stream) { @@ -201,7 +211,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-failure-recitation-no-content.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); const aggregatedResponse = await result.response; expect(aggregatedResponse.text).to.throw('RECITATION'); expect(aggregatedResponse.candidates?.[0].content.parts[0].text).to.include( @@ -220,7 +230,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-success-citations.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); const aggregatedResponse = await result.response; expect(aggregatedResponse.text()).to.include('Quantum mechanics is'); expect( @@ -240,7 +250,7 @@ describe('processStream', () => { 'vertexAI', 'streaming-success-empty-text-part.txt' ); - const result = processStream(fakeResponse as Response); + const result = processStream(fakeResponse as Response, fakeApiSettings); const aggregatedResponse = await result.response; expect(aggregatedResponse.text()).to.equal('1'); expect(aggregatedResponse.candidates?.length).to.equal(1); @@ -472,10 +482,8 @@ describe('aggregateResponses', () => { try { aggregateResponses(responsesToAggregate); } catch (e) { - expect((e as VertexAIError).code).includes( - VertexAIErrorCode.INVALID_CONTENT - ); - expect((e as VertexAIError).message).to.include( + expect((e as GenAIError).code).includes(GenAIErrorCode.INVALID_CONTENT); + expect((e as GenAIError).message).to.include( 'Part should have at least one property, but there are none. This is likely caused ' + 'by a malformed response from the backend.' ); diff --git a/packages/vertexai/src/requests/stream-reader.ts b/packages/vertexai/src/requests/stream-reader.ts index 5c419d114e0..db1f99d7b27 100644 --- a/packages/vertexai/src/requests/stream-reader.ts +++ b/packages/vertexai/src/requests/stream-reader.ts @@ -21,10 +21,14 @@ import { GenerateContentResponse, GenerateContentStreamResult, Part, - VertexAIErrorCode + GenAIErrorCode } from '../types'; -import { VertexAIError } from '../errors'; +import { GenAIError } from '../errors'; import { createEnhancedContentResponse } from './response-helpers'; +import * as GoogleAIMapper from '../googleAIMappers'; +import { GoogleAIGenerateContentResponse } from '../types/googleAI'; +import { ApiSettings } from '../types/internal'; +import { BackendType } from '../public-types'; const responseLineRE = /^data\: (.*)(?:\n\n|\r\r|\r\n\r\n)/; @@ -36,7 +40,10 @@ const responseLineRE = /^data\: (.*)(?:\n\n|\r\r|\r\n\r\n)/; * * @param response - Response from a fetch call */ -export function processStream(response: Response): GenerateContentStreamResult { +export function processStream( + response: Response, + apiSettings: ApiSettings +): GenerateContentStreamResult { const inputStream = response.body!.pipeThrough( new TextDecoderStream('utf8', { fatal: true }) ); @@ -44,23 +51,27 @@ export function processStream(response: Response): GenerateContentStreamResult { getResponseStream(inputStream); const [stream1, stream2] = responseStream.tee(); return { - stream: generateResponseSequence(stream1), - response: getResponsePromise(stream2) + stream: generateResponseSequence(stream1, apiSettings), + response: getResponsePromise(stream2, apiSettings) }; } async function getResponsePromise( - stream: ReadableStream + stream: ReadableStream, + apiSettings: ApiSettings ): Promise { const allResponses: GenerateContentResponse[] = []; const reader = stream.getReader(); while (true) { const { done, value } = await reader.read(); if (done) { - const enhancedResponse = createEnhancedContentResponse( - aggregateResponses(allResponses) - ); - return enhancedResponse; + let generateContentResponse = aggregateResponses(allResponses); + if (apiSettings.backend.backendType === BackendType.GOOGLE_AI) { + generateContentResponse = GoogleAIMapper.mapGenerateContentResponse( + generateContentResponse as GoogleAIGenerateContentResponse + ); + } + return createEnhancedContentResponse(generateContentResponse); } allResponses.push(value); @@ -68,7 +79,8 @@ async function getResponsePromise( } async function* generateResponseSequence( - stream: ReadableStream + stream: ReadableStream, + apiSettings: ApiSettings ): AsyncGenerator { const reader = stream.getReader(); while (true) { @@ -77,7 +89,17 @@ async function* generateResponseSequence( break; } - const enhancedResponse = createEnhancedContentResponse(value); + let enhancedResponse: EnhancedGenerateContentResponse; + if (apiSettings.backend.backendType === BackendType.GOOGLE_AI) { + enhancedResponse = createEnhancedContentResponse( + GoogleAIMapper.mapGenerateContentResponse( + value as GoogleAIGenerateContentResponse + ) + ); + } else { + enhancedResponse = createEnhancedContentResponse(value); + } + yield enhancedResponse; } } @@ -100,8 +122,8 @@ export function getResponseStream( if (done) { if (currentText.trim()) { controller.error( - new VertexAIError( - VertexAIErrorCode.PARSE_FAILED, + new GenAIError( + GenAIErrorCode.PARSE_FAILED, 'Failed to parse stream' ) ); @@ -119,8 +141,8 @@ export function getResponseStream( parsedResponse = JSON.parse(match[1]); } catch (e) { controller.error( - new VertexAIError( - VertexAIErrorCode.PARSE_FAILED, + new GenAIError( + GenAIErrorCode.PARSE_FAILED, `Error parsing JSON response: "${match[1]}` ) ); @@ -198,8 +220,8 @@ export function aggregateResponses( newPart.functionCall = part.functionCall; } if (Object.keys(newPart).length === 0) { - throw new VertexAIError( - VertexAIErrorCode.INVALID_CONTENT, + throw new GenAIError( + GenAIErrorCode.INVALID_CONTENT, 'Part should have at least one property, but there are none. This is likely caused ' + 'by a malformed response from the backend.' ); diff --git a/packages/vertexai/src/service.test.ts b/packages/vertexai/src/service.test.ts index d3487e9bdd2..e76037971e5 100644 --- a/packages/vertexai/src/service.test.ts +++ b/packages/vertexai/src/service.test.ts @@ -14,8 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { vertexAIBackend } from './api'; import { DEFAULT_LOCATION } from './constants'; -import { VertexAIService } from './service'; +import { GenAIService } from './service'; import { expect } from 'chai'; const fakeApp = { @@ -27,18 +28,19 @@ const fakeApp = { } }; -describe('VertexAIService', () => { +describe('GenAIService', () => { + // TODO (dlarocque): move some of these tests to helpers.test.ts it('uses default location if not specified', () => { - const vertexAI = new VertexAIService(fakeApp); - expect(vertexAI.location).to.equal(DEFAULT_LOCATION); + const genAI = new GenAIService(fakeApp, vertexAIBackend()); + expect(genAI.location).to.equal(DEFAULT_LOCATION); }); it('uses custom location if specified', () => { - const vertexAI = new VertexAIService( + const genAI = new GenAIService( fakeApp, + vertexAIBackend('somewhere'), /* authProvider */ undefined, - /* appCheckProvider */ undefined, - { location: 'somewhere' } + /* appCheckProvider */ undefined ); - expect(vertexAI.location).to.equal('somewhere'); + expect(genAI.location).to.equal('somewhere'); }); }); diff --git a/packages/vertexai/src/service.ts b/packages/vertexai/src/service.ts index 05b2d559e58..d793ef5acfc 100644 --- a/packages/vertexai/src/service.ts +++ b/packages/vertexai/src/service.ts @@ -16,7 +16,7 @@ */ import { FirebaseApp, _FirebaseService } from '@firebase/app'; -import { VertexAI, VertexAIOptions } from './public-types'; +import { Backend, GenAI } from './public-types'; import { AppCheckInternalComponentName, FirebaseAppCheckInternal @@ -26,24 +26,28 @@ import { FirebaseAuthInternal, FirebaseAuthInternalName } from '@firebase/auth-interop-types'; -import { DEFAULT_LOCATION } from './constants'; -export class VertexAIService implements VertexAI, _FirebaseService { +export class GenAIService implements GenAI, _FirebaseService { auth: FirebaseAuthInternal | null; appCheck: FirebaseAppCheckInternal | null; - location: string; + location: string; // This is here for backwards-compatibility constructor( public app: FirebaseApp, + public backend: Backend, authProvider?: Provider, - appCheckProvider?: Provider, - public options?: VertexAIOptions + appCheckProvider?: Provider ) { const appCheck = appCheckProvider?.getImmediate({ optional: true }); const auth = authProvider?.getImmediate({ optional: true }); this.auth = auth || null; this.appCheck = appCheck || null; - this.location = this.options?.location || DEFAULT_LOCATION; + + if (backend.backendType === 'VERTEX_AI') { + this.location = backend.location; + } else { + this.location = ''; + } } _delete(): Promise { diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index a9481d40f5f..ffa072f33d7 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -62,11 +62,13 @@ export enum HarmBlockThreshold { } /** + * This property is not supported in Google AI. + * * @public */ export enum HarmBlockMethod { /** - * The harm block method uses both probability and severity scores. + * The harm block method uses both probability and severity scores. */ SEVERITY = 'SEVERITY', /** @@ -118,7 +120,12 @@ export enum HarmSeverity { /** * High level of harm severity. */ - HARM_SEVERITY_HIGH = 'HARM_SEVERITY_HIGH' + HARM_SEVERITY_HIGH = 'HARM_SEVERITY_HIGH', + /** + * Harm severity is not supported. + * The GoogleAI backend does not support `HarmSeverity`, so this value is used as a fallback. + */ + HARM_SEVERITY_UNSUPPORTED = 'HARM_SEVERITY_UNSUPPORTED' } /** diff --git a/packages/vertexai/src/types/error.ts b/packages/vertexai/src/types/error.ts index b1f075101a6..c29bbe95284 100644 --- a/packages/vertexai/src/types/error.ts +++ b/packages/vertexai/src/types/error.ts @@ -58,11 +58,11 @@ export interface CustomErrorData { } /** - * Standardized error codes that {@link VertexAIError} can have. + * Standardized error codes that {@link GenAIError} can have. * * @public */ -export const enum VertexAIErrorCode { +export const enum GenAIErrorCode { /** A generic error occurred. */ ERROR = 'error', @@ -97,5 +97,8 @@ export const enum VertexAIErrorCode { NO_PROJECT_ID = 'no-project-id', /** An error occurred while parsing. */ - PARSE_FAILED = 'parse-failed' + PARSE_FAILED = 'parse-failed', + + /** An error occured due an attempt to use an unsupported feature. */ + UNSUPPORTED = 'unsupported' } diff --git a/packages/vertexai/src/types/googleAI/index.ts b/packages/vertexai/src/types/googleAI/index.ts new file mode 100644 index 00000000000..546c64f13b1 --- /dev/null +++ b/packages/vertexai/src/types/googleAI/index.ts @@ -0,0 +1,19 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './requests'; +export * from './responses'; diff --git a/packages/vertexai/src/types/googleAI/requests.ts b/packages/vertexai/src/types/googleAI/requests.ts new file mode 100644 index 00000000000..94dfb4c4241 --- /dev/null +++ b/packages/vertexai/src/types/googleAI/requests.ts @@ -0,0 +1,29 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Content, Part } from '../content'; +import { GenerationConfig, Tool } from '../requests'; + +export interface GoogleAICountTokensRequest { + generateContentRequest: { + model: string; // 'models/model-name' + contents: Content[]; + systemInstruction?: string | Part | Content; + tools?: Tool[]; + generationConfig?: GenerationConfig; + }; +} diff --git a/packages/vertexai/src/types/googleAI/responses.ts b/packages/vertexai/src/types/googleAI/responses.ts new file mode 100644 index 00000000000..702464cecc7 --- /dev/null +++ b/packages/vertexai/src/types/googleAI/responses.ts @@ -0,0 +1,46 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Content } from '../content'; +import { FinishReason } from '../enums'; +import { + Citation, + GroundingMetadata, + PromptFeedback, + SafetyRating, + UsageMetadata +} from '../responses'; + +export interface GoogleAIGenerateContentResponse { + candidates?: GoogleAIGenerateContentCandidate[]; + promptFeedback?: PromptFeedback; + usageMetadata?: UsageMetadata; +} + +export interface GoogleAIGenerateContentCandidate { + index: number; + content: Content; + finishReason?: FinishReason; + finishMessage?: string; + safetyRatings?: SafetyRating[]; + citationMetadata?: GoogleAICitationMetadata; + groundingMetadata?: GroundingMetadata; +} + +export interface GoogleAICitationMetadata { + citationSources: Citation[]; // Maps to `citations` +} diff --git a/packages/vertexai/src/types/imagen/requests.ts b/packages/vertexai/src/types/imagen/requests.ts index 70ae182238e..d5bc3c31223 100644 --- a/packages/vertexai/src/types/imagen/requests.ts +++ b/packages/vertexai/src/types/imagen/requests.ts @@ -88,6 +88,9 @@ export interface ImagenGenerationConfig { * * For Imagen 3 models, the default value is `true`; see the addWatermark * documentation for more details. + * + * @remarks + * In Google AI, the default value is true, and it cannot be turned off. */ addWatermark?: boolean; } diff --git a/packages/vertexai/src/types/internal.ts b/packages/vertexai/src/types/internal.ts index a3476afd028..4303d4c07d8 100644 --- a/packages/vertexai/src/types/internal.ts +++ b/packages/vertexai/src/types/internal.ts @@ -17,6 +17,7 @@ import { AppCheckTokenResult } from '@firebase/app-check-interop-types'; import { FirebaseAuthTokenData } from '@firebase/auth-interop-types'; +import { Backend } from '../public-types'; export * from './imagen/internal'; @@ -24,8 +25,14 @@ export interface ApiSettings { apiKey: string; project: string; appId: string; - location: string; automaticDataCollectionEnabled?: boolean; + /** + * @deprecated + */ + location: string; + backend: Backend; getAuthToken?: () => Promise; getAppCheckToken?: () => Promise; } + +export type InstanceIdentifier = Backend; diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index c15258b06d0..f18a0ae0c48 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -63,6 +63,11 @@ export interface GenerateContentRequest extends BaseParams { export interface SafetySetting { category: HarmCategory; threshold: HarmBlockThreshold; + /** + * This property is not supported in Google AI. + * If this is a property on a {@link GenerateContentRequest} to be sent, a {@link GenAIError} + * will be thrown. + */ method?: HarmBlockMethod; } diff --git a/packages/vertexai/src/types/responses.ts b/packages/vertexai/src/types/responses.ts index 7f68df1e679..844b0b2934b 100644 --- a/packages/vertexai/src/types/responses.ts +++ b/packages/vertexai/src/types/responses.ts @@ -108,7 +108,7 @@ export interface ModalityTokenCount { export interface PromptFeedback { blockReason?: BlockReason; safetyRatings: SafetyRating[]; - blockReasonMessage?: string; + blockReasonMessage?: string; // This will always be undefined when using Google AI. } /** @@ -142,8 +142,8 @@ export interface Citation { endIndex?: number; uri?: string; license?: string; - title?: string; - publicationDate?: Date; + title?: string; // This will always be undefined when using Google AI. + publicationDate?: Date; // This will always be undefined when using Google AI. } /** @@ -215,7 +215,7 @@ export interface SafetyRating { severity: HarmSeverity; probabilityScore: number; severityScore: number; - blocked: boolean; + blocked: boolean; // FIXME: This is only included when it's true. Either set a default of false, or make this optional. } /** @@ -231,7 +231,7 @@ export interface CountTokensResponse { * The total number of billable characters counted across all instances * from the request. */ - totalBillableCharacters?: number; + totalBillableCharacters?: number; // This will always be undefined when using Google AI. /** * The breakdown, by modality, of how many tokens are consumed by the prompt. */ diff --git a/packages/vertexai/src/types/schema.ts b/packages/vertexai/src/types/schema.ts index 5c23655be0e..c73caca9993 100644 --- a/packages/vertexai/src/types/schema.ts +++ b/packages/vertexai/src/types/schema.ts @@ -42,7 +42,10 @@ export enum SchemaType { * @public */ export interface SchemaShared { - /** Optional. The format of the property. */ + /** Optional. The format of the property. + * When using the Google AI backend, this must be either `'enum'` or `'date-time'`, otherwise + * requests will fail. + */ format?: string; /** Optional. The description of the property. */ description?: string; diff --git a/packages/vertexai/test-utils/mock-response.ts b/packages/vertexai/test-utils/mock-response.ts index 5128ddabe74..c108704d615 100644 --- a/packages/vertexai/test-utils/mock-response.ts +++ b/packages/vertexai/test-utils/mock-response.ts @@ -72,6 +72,9 @@ export function getMockResponse( filename: string ): Partial { const mocksLookup = mockSetMaps[backendName]; + if (backendName === 'googleAI') { + console.log(Object.keys(mocksLookup)); + } if (!(filename in mocksLookup)) { throw Error(`${backendName} mock response file '${filename}' not found.`); } From 4e831d1bfd7804f3da7a918aa3055b97a0e6ffeb Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Thu, 17 Apr 2025 14:50:57 -0400 Subject: [PATCH 02/32] Convert `GenAI` to new Firebase AI naming --- common/api-review/vertexai.api.md | 131 ++++++++------- docs-devsite/_toc.yaml | 16 +- docs-devsite/index.md | 2 +- docs-devsite/vertexai.ai.md | 64 +++++++ ...exai.genaierror.md => vertexai.aierror.md} | 26 +-- ...exai.genaimodel.md => vertexai.aimodel.md} | 12 +- docs-devsite/vertexai.aioptions.md | 35 ++++ docs-devsite/vertexai.genai.md | 64 ------- docs-devsite/vertexai.genaioptions.md | 35 ---- docs-devsite/vertexai.generativemodel.md | 10 +- docs-devsite/vertexai.imagenmodel.md | 12 +- docs-devsite/vertexai.md | 158 +++++++++--------- docs-devsite/vertexai.modelparams.md | 2 +- docs-devsite/vertexai.requestoptions.md | 2 +- docs-devsite/vertexai.safetysetting.md | 4 +- docs-devsite/vertexai.vertexaioptions.md | 2 +- packages/firebase/package.json | 2 +- packages/vertexai/src/api.test.ts | 100 +++++------ packages/vertexai/src/api.ts | 82 ++++----- .../src/backwards-compatbility.test.ts | 38 ++--- packages/vertexai/src/constants.ts | 4 +- packages/vertexai/src/errors.ts | 22 +-- packages/vertexai/src/googleAIMappers.test.ts | 12 +- packages/vertexai/src/googleAIMappers.ts | 12 +- packages/vertexai/src/helpers.test.ts | 56 +++---- packages/vertexai/src/helpers.ts | 30 ++-- packages/vertexai/src/index.node.ts | 16 +- packages/vertexai/src/index.ts | 24 +-- .../src/methods/chat-session-helpers.ts | 28 ++-- .../src/methods/generate-content.test.ts | 8 +- .../vertexai/src/models/genai-model.test.ts | 44 ++--- packages/vertexai/src/models/genai-model.ts | 70 ++++---- .../src/models/generative-model.test.ts | 18 +- .../vertexai/src/models/generative-model.ts | 10 +- .../vertexai/src/models/imagen-model.test.ts | 20 +-- packages/vertexai/src/models/imagen-model.ts | 14 +- packages/vertexai/src/public-types.ts | 38 ++--- .../vertexai/src/requests/request-helpers.ts | 12 +- .../vertexai/src/requests/request.test.ts | 48 +++--- packages/vertexai/src/requests/request.ts | 22 +-- .../vertexai/src/requests/response-helpers.ts | 28 ++-- .../src/requests/schema-builder.test.ts | 4 +- .../vertexai/src/requests/schema-builder.ts | 8 +- .../src/requests/stream-reader.test.ts | 8 +- .../vertexai/src/requests/stream-reader.ts | 16 +- packages/vertexai/src/service.test.ts | 12 +- packages/vertexai/src/service.ts | 4 +- packages/vertexai/src/types/error.ts | 4 +- packages/vertexai/src/types/requests.ts | 2 +- 49 files changed, 697 insertions(+), 694 deletions(-) create mode 100644 docs-devsite/vertexai.ai.md rename docs-devsite/{vertexai.genaierror.md => vertexai.aierror.md} (52%) rename docs-devsite/{vertexai.genaimodel.md => vertexai.aimodel.md} (67%) create mode 100644 docs-devsite/vertexai.aioptions.md delete mode 100644 docs-devsite/vertexai.genai.md delete mode 100644 docs-devsite/vertexai.genaioptions.md diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 66012360050..cc1a0c3269c 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -9,6 +9,62 @@ import { FirebaseApp } from '@firebase/app'; import { FirebaseAuthTokenData } from '@firebase/auth-interop-types'; import { FirebaseError } from '@firebase/util'; +// @public +export interface AI { + app: FirebaseApp; + backend: Backend; + // @deprecated + location: string; +} + +// @public +export class AIError extends FirebaseError { + constructor(code: AIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); + // (undocumented) + readonly code: AIErrorCode; + // (undocumented) + readonly customErrorData?: CustomErrorData | undefined; +} + +// @public +const enum AIErrorCode { + API_NOT_ENABLED = "api-not-enabled", + ERROR = "error", + FETCH_ERROR = "fetch-error", + INVALID_CONTENT = "invalid-content", + INVALID_SCHEMA = "invalid-schema", + NO_API_KEY = "no-api-key", + NO_APP_ID = "no-app-id", + NO_MODEL = "no-model", + NO_PROJECT_ID = "no-project-id", + PARSE_FAILED = "parse-failed", + REQUEST_ERROR = "request-error", + RESPONSE_ERROR = "response-error", + UNSUPPORTED = "unsupported" +} + +export { AIErrorCode } + +export { AIErrorCode as VertexAIErrorCode } + +// @public +export abstract class AIModel { + // @internal + protected constructor(ai: AI, modelName: string); + // Warning: (ae-forgotten-export) The symbol "ApiSettings" needs to be exported by the entry point index.d.ts + // + // @internal (undocumented) + protected _apiSettings: ApiSettings; + readonly model: string; + // @internal + static normalizeModelName(modelName: string, backendType: BackendType): string; + } + +// @public +export interface AIOptions { + backend: Backend; +} + // @public export class ArraySchema extends Schema { constructor(schemaParams: SchemaParams, items: TypedSchema); @@ -53,7 +109,6 @@ export class BooleanSchema extends Schema { // @public export class ChatSession { - // Warning: (ae-forgotten-export) The symbol "ApiSettings" needs to be exported by the entry point index.d.ts constructor(apiSettings: ApiSettings, model: string, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined); getHistory(): Promise; // (undocumented) @@ -251,60 +306,6 @@ export interface FunctionResponsePart { text?: never; } -// @public -export interface GenAI { - app: FirebaseApp; - backend: Backend; - // @deprecated - location: string; -} - -// @public -export class GenAIError extends FirebaseError { - constructor(code: GenAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); - // (undocumented) - readonly code: GenAIErrorCode; - // (undocumented) - readonly customErrorData?: CustomErrorData | undefined; -} - -// @public -const enum GenAIErrorCode { - API_NOT_ENABLED = "api-not-enabled", - ERROR = "error", - FETCH_ERROR = "fetch-error", - INVALID_CONTENT = "invalid-content", - INVALID_SCHEMA = "invalid-schema", - NO_API_KEY = "no-api-key", - NO_APP_ID = "no-app-id", - NO_MODEL = "no-model", - NO_PROJECT_ID = "no-project-id", - PARSE_FAILED = "parse-failed", - REQUEST_ERROR = "request-error", - RESPONSE_ERROR = "response-error", - UNSUPPORTED = "unsupported" -} - -export { GenAIErrorCode } - -export { GenAIErrorCode as VertexAIErrorCode } - -// @public -export abstract class GenAIModel { - // @internal - protected constructor(genAI: GenAI, modelName: string); - // @internal (undocumented) - protected _apiSettings: ApiSettings; - readonly model: string; - // @internal - static normalizeModelName(modelName: string, backendType: BackendType): string; - } - -// @public -export interface GenAIOptions { - backend: Backend; -} - // @public export interface GenerateContentCandidate { // (undocumented) @@ -389,8 +390,8 @@ export interface GenerativeContentBlob { } // @public -export class GenerativeModel extends GenAIModel { - constructor(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions); +export class GenerativeModel extends AIModel { + constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions); countTokens(request: CountTokensRequest | string | Array): Promise; generateContent(request: GenerateContentRequest | string | Array): Promise; generateContentStream(request: GenerateContentRequest | string | Array): Promise; @@ -410,13 +411,13 @@ export class GenerativeModel extends GenAIModel { } // @public -export function getGenAI(app?: FirebaseApp, options?: GenAIOptions): GenAI; +export function getAI(app?: FirebaseApp, options?: AIOptions): AI; // @public -export function getGenerativeModel(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; +export function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; // @beta -export function getImagenModel(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; +export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; // @public export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; @@ -539,8 +540,8 @@ export interface ImagenInlineImage { } // @beta -export class ImagenModel extends GenAIModel { - constructor(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); +export class ImagenModel extends AIModel { + constructor(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); generateImages(prompt: string): Promise>; // @internal generateImagesGCS(prompt: string, gcsURI: string): Promise>; @@ -856,7 +857,7 @@ export interface UsageMetadata { } // @public -export type VertexAI = GenAI; +export type VertexAI = AI; // @public export type VertexAIBackend = { @@ -868,10 +869,10 @@ export type VertexAIBackend = { export function vertexAIBackend(location?: string): VertexAIBackend; // @public -export const VertexAIError: typeof GenAIError; +export const VertexAIError: typeof AIError; // @public -export const VertexAIModel: typeof GenAIModel; +export const VertexAIModel: typeof AIModel; // @public export interface VertexAIOptions { diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index 19ed87f1e54..03d6b5f6ec7 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -472,6 +472,14 @@ toc: - title: vertexai path: /docs/reference/js/vertexai.md section: + - title: AI + path: /docs/reference/js/vertexai.ai.md + - title: AIError + path: /docs/reference/js/vertexai.aierror.md + - title: AIModel + path: /docs/reference/js/vertexai.aimodel.md + - title: AIOptions + path: /docs/reference/js/vertexai.aioptions.md - title: ArraySchema path: /docs/reference/js/vertexai.arrayschema.md - title: BaseParams @@ -516,14 +524,6 @@ toc: path: /docs/reference/js/vertexai.functionresponse.md - title: FunctionResponsePart path: /docs/reference/js/vertexai.functionresponsepart.md - - title: GenAI - path: /docs/reference/js/vertexai.genai.md - - title: GenAIError - path: /docs/reference/js/vertexai.genaierror.md - - title: GenAIModel - path: /docs/reference/js/vertexai.genaimodel.md - - title: GenAIOptions - path: /docs/reference/js/vertexai.genaioptions.md - title: GenerateContentCandidate path: /docs/reference/js/vertexai.generatecontentcandidate.md - title: GenerateContentRequest diff --git a/docs-devsite/index.md b/docs-devsite/index.md index 82fdb36f076..af34d0d0250 100644 --- a/docs-devsite/index.md +++ b/docs-devsite/index.md @@ -27,5 +27,5 @@ https://github.com/firebase/firebase-js-sdk | [@firebase/performance](./performance.md#performance_package) | The Firebase Performance Monitoring Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/remote-config](./remote-config.md#remote-config_package) | The Firebase Remote Config Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/storage](./storage.md#storage_package) | Cloud Storage for Firebase | -| [@firebase/vertexai](./vertexai.md#vertexai_package) | The Vertex AI in Firebase Web SDK. | +| [@firebase/vertexai](./vertexai.md#vertexai_package) | The Firebase AI Web SDK. | diff --git a/docs-devsite/vertexai.ai.md b/docs-devsite/vertexai.ai.md new file mode 100644 index 00000000000..2901c2ccd01 --- /dev/null +++ b/docs-devsite/vertexai.ai.md @@ -0,0 +1,64 @@ +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 %} + +# AI interface +An instance of the Firebase AI SDK. + +Do not create this instance directly. Instead, use [getAI()](./vertexai.md#getai_a94a413). + +Signature: + +```typescript +export interface AI +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [app](./vertexai.ai.md#aiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./vertexai.ai.md#ai_interface) instance is associated with. | +| [backend](./vertexai.ai.md#aibackend) | [Backend](./vertexai.md#backend) | A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. | +| [location](./vertexai.ai.md#ailocation) | string | The location configured for this AI service instance, relevant for Vertex AI backends. | + +## AI.app + +The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./vertexai.ai.md#ai_interface) instance is associated with. + +Signature: + +```typescript +app: FirebaseApp; +``` + +## AI.backend + +A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. + +Signature: + +```typescript +backend: Backend; +``` + +## AI.location + +> Warning: This API is now obsolete. +> +> use `AI.backend.location` instead. +> + +The location configured for this AI service instance, relevant for Vertex AI backends. + +Signature: + +```typescript +location: string; +``` diff --git a/docs-devsite/vertexai.genaierror.md b/docs-devsite/vertexai.aierror.md similarity index 52% rename from docs-devsite/vertexai.genaierror.md rename to docs-devsite/vertexai.aierror.md index eed0a54d264..dac50815b6a 100644 --- a/docs-devsite/vertexai.genaierror.md +++ b/docs-devsite/vertexai.aierror.md @@ -9,13 +9,13 @@ overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %} -# GenAIError class -Error class for the Vertex AI in Firebase SDK. +# AIError class +Error class for the Firebase AI SDK. Signature: ```typescript -export declare class GenAIError extends FirebaseError +export declare class AIError extends FirebaseError ``` Extends: [FirebaseError](./util.firebaseerror.md#firebaseerror_class) @@ -23,42 +23,42 @@ export declare class GenAIError extends FirebaseError | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(code, message, customErrorData)](./vertexai.genaierror.md#genaierrorconstructor) | | Constructs a new instance of the GenAIError class. | +| [(constructor)(code, message, customErrorData)](./vertexai.aierror.md#aierrorconstructor) | | Constructs a new instance of the AIError class. | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [code](./vertexai.genaierror.md#genaierrorcode) | | [GenAIErrorCode](./vertexai.md#genaierrorcode) | | -| [customErrorData](./vertexai.genaierror.md#genaierrorcustomerrordata) | | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | | +| [code](./vertexai.aierror.md#aierrorcode) | | [AIErrorCode](./vertexai.md#aierrorcode) | | +| [customErrorData](./vertexai.aierror.md#aierrorcustomerrordata) | | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | | -## GenAIError.(constructor) +## AIError.(constructor) -Constructs a new instance of the `GenAIError` class. +Constructs a new instance of the `AIError` class. Signature: ```typescript -constructor(code: GenAIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); +constructor(code: AIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| code | [GenAIErrorCode](./vertexai.md#genaierrorcode) | The error code from [GenAIErrorCode](./vertexai.md#genaierrorcode). | +| code | [AIErrorCode](./vertexai.md#aierrorcode) | The error code from [AIErrorCode](./vertexai.md#aierrorcode). | | message | string | A human-readable message describing the error. | | customErrorData | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | Optional error data. | -## GenAIError.code +## AIError.code Signature: ```typescript -readonly code: GenAIErrorCode; +readonly code: AIErrorCode; ``` -## GenAIError.customErrorData +## AIError.customErrorData Signature: diff --git a/docs-devsite/vertexai.genaimodel.md b/docs-devsite/vertexai.aimodel.md similarity index 67% rename from docs-devsite/vertexai.genaimodel.md rename to docs-devsite/vertexai.aimodel.md index 3d744a77e28..ee142d27c47 100644 --- a/docs-devsite/vertexai.genaimodel.md +++ b/docs-devsite/vertexai.aimodel.md @@ -9,24 +9,24 @@ overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %} -# GenAIModel class -Base class for Vertex AI in Firebase model APIs. +# AIModel class +Base class for Firebase AI model APIs. -The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `GenAIModel` class. +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `AIModel` class. Signature: ```typescript -export declare abstract class GenAIModel +export declare abstract class AIModel ``` ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [model](./vertexai.genaimodel.md#genaimodelmodel) | | string | The fully qualified model resource name to use for generating images (for example, publishers/google/models/imagen-3.0-generate-002). | +| [model](./vertexai.aimodel.md#aimodelmodel) | | string | The fully qualified model resource name to use for generating images (for example, publishers/google/models/imagen-3.0-generate-002). | -## GenAIModel.model +## AIModel.model The fully qualified model resource name to use for generating images (for example, `publishers/google/models/imagen-3.0-generate-002`). diff --git a/docs-devsite/vertexai.aioptions.md b/docs-devsite/vertexai.aioptions.md new file mode 100644 index 00000000000..4d5e7117740 --- /dev/null +++ b/docs-devsite/vertexai.aioptions.md @@ -0,0 +1,35 @@ +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 %} + +# AIOptions interface +Options interface for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). + +Signature: + +```typescript +export interface AIOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [backend](./vertexai.aioptions.md#aioptionsbackend) | [Backend](./vertexai.md#backend) | The backend configuration to use for the AI service instance. Use [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) to create this configuration. | + +## AIOptions.backend + +The backend configuration to use for the AI service instance. Use [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) to create this configuration. + +Signature: + +```typescript +backend: Backend; +``` diff --git a/docs-devsite/vertexai.genai.md b/docs-devsite/vertexai.genai.md deleted file mode 100644 index d8ce617941a..00000000000 --- a/docs-devsite/vertexai.genai.md +++ /dev/null @@ -1,64 +0,0 @@ -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 %} - -# GenAI interface -An instance of the Firebase GenAI SDK. - -Do not create this instance directly. Instead, use [getGenAI()](./vertexai.md#getgenai_65c48ee). - -Signature: - -```typescript -export interface GenAI -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [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. | -| [backend](./vertexai.genai.md#genaibackend) | [Backend](./vertexai.md#backend) | A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. | -| [location](./vertexai.genai.md#genailocation) | string | The location configured for this GenAI service instance, relevant for Vertex AI backends. | - -## GenAI.app - -The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [GenAI](./vertexai.genai.md#genai_interface) instance is associated with. - -Signature: - -```typescript -app: FirebaseApp; -``` - -## GenAI.backend - -A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. - -Signature: - -```typescript -backend: Backend; -``` - -## GenAI.location - -> Warning: This API is now obsolete. -> -> use `GenAI.backend.location` instead. -> - -The location configured for this GenAI service instance, relevant for Vertex AI backends. - -Signature: - -```typescript -location: string; -``` diff --git a/docs-devsite/vertexai.genaioptions.md b/docs-devsite/vertexai.genaioptions.md deleted file mode 100644 index d7f5b499f67..00000000000 --- a/docs-devsite/vertexai.genaioptions.md +++ /dev/null @@ -1,35 +0,0 @@ -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 %} - -# GenAIOptions interface -Options interface for initializing the GenAI service using [getGenAI()](./vertexai.md#getgenai_65c48ee). - -Signature: - -```typescript -export interface GenAIOptions -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [backend](./vertexai.genaioptions.md#genaioptionsbackend) | [Backend](./vertexai.md#backend) | The backend configuration to use for the GenAI service instance. Use [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) to create this configuration. | - -## GenAIOptions.backend - -The backend configuration to use for the GenAI service instance. Use [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) to create this configuration. - -Signature: - -```typescript -backend: Backend; -``` diff --git a/docs-devsite/vertexai.generativemodel.md b/docs-devsite/vertexai.generativemodel.md index 2cbb56958b1..ba82b65aceb 100644 --- a/docs-devsite/vertexai.generativemodel.md +++ b/docs-devsite/vertexai.generativemodel.md @@ -15,15 +15,15 @@ Class for generative model APIs. Signature: ```typescript -export declare class GenerativeModel extends GenAIModel +export declare class GenerativeModel extends AIModel ``` -Extends: [GenAIModel](./vertexai.genaimodel.md#genaimodel_class) +Extends: [AIModel](./vertexai.aimodel.md#aimodel_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(genAI, modelParams, requestOptions)](./vertexai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the GenerativeModel class | +| [(constructor)(ai, modelParams, requestOptions)](./vertexai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the GenerativeModel class | ## Properties @@ -52,14 +52,14 @@ Constructs a new instance of the `GenerativeModel` class Signature: ```typescript -constructor(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions); +constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions); ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| genAI | [GenAI](./vertexai.genai.md#genai_interface) | | +| ai | [AI](./vertexai.ai.md#ai_interface) | | | modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | diff --git a/docs-devsite/vertexai.imagenmodel.md b/docs-devsite/vertexai.imagenmodel.md index b6c29dc5d81..e69c49b8572 100644 --- a/docs-devsite/vertexai.imagenmodel.md +++ b/docs-devsite/vertexai.imagenmodel.md @@ -20,15 +20,15 @@ This class provides methods for generating images using the Imagen model. Signature: ```typescript -export declare class ImagenModel extends GenAIModel +export declare class ImagenModel extends AIModel ``` -Extends: [GenAIModel](./vertexai.genaimodel.md#genaimodel_class) +Extends: [AIModel](./vertexai.aimodel.md#aimodel_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(genAI, modelParams, requestOptions)](./vertexai.imagenmodel.md#imagenmodelconstructor) | | (Public Preview) Constructs a new instance of the [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class. | +| [(constructor)(ai, modelParams, requestOptions)](./vertexai.imagenmodel.md#imagenmodelconstructor) | | (Public Preview) Constructs a new instance of the [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class. | ## Properties @@ -54,14 +54,14 @@ Constructs a new instance of the [ImagenModel](./vertexai.imagenmodel.md#imagenm Signature: ```typescript -constructor(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); +constructor(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| genAI | [GenAI](./vertexai.genai.md#genai_interface) | A [GenAI](./vertexai.genai.md#genai_interface) instance. | +| ai | [AI](./vertexai.ai.md#ai_interface) | an [AI](./vertexai.ai.md#ai_interface) instance. | | modelParams | [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making requests to Imagen. | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) \| undefined | Additional options to use when making requests. | @@ -142,7 +142,7 @@ If the request to generate images fails. This happens if the prompt is blocked. ```javascript const imagen = new ImagenModel( - genAI, + ai, { model: 'imagen-3.0-generate-002' } diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index 1b93328851e..544deb2987d 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -10,20 +10,20 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # vertexai package -The Vertex AI in Firebase Web SDK. +The Firebase AI Web SDK. ## Functions | Function | Description | | --- | --- | | function(app, ...) | -| [getGenAI(app, options)](./vertexai.md#getgenai_65c48ee) | Returns the default [GenAI](./vertexai.genai.md#genai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | +| [getAI(app, options)](./vertexai.md#getai_a94a413) | Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | | [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app. | | function() | | [googleAIBackend()](./vertexai.md#googleaibackend) | Creates a [Backend](./vertexai.md#backend) instance configured to use Google AI. | -| function(genAI, ...) | -| [getGenerativeModel(genAI, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_e3ccf80) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | -| [getImagenModel(genAI, modelParams, requestOptions)](./vertexai.md#getimagenmodel_bffbd6b) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | +| function(ai, ...) | +| [getGenerativeModel(ai, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | +| [getImagenModel(ai, modelParams, requestOptions)](./vertexai.md#getimagenmodel_e1f6645) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | | function(location, ...) | | [vertexAIBackend(location)](./vertexai.md#vertexaibackend_d0a4534) | Creates a [Backend](./vertexai.md#backend) instance configured to use Vertex AI. | @@ -31,11 +31,11 @@ The Vertex AI in Firebase Web SDK. | Class | Description | | --- | --- | +| [AIError](./vertexai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. | +| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs. | | [ArraySchema](./vertexai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | | [BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | | [ChatSession](./vertexai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | -| [GenAIError](./vertexai.genaierror.md#genaierror_class) | Error class for the Vertex AI in Firebase SDK. | -| [GenAIModel](./vertexai.genaimodel.md#genaimodel_class) | Base class for Vertex AI in Firebase model APIs. | | [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) Defines the image format for images generated by Imagen.Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface). | | [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) | (Public Preview) Class for Imagen model APIs.This class provides methods for generating images using the Imagen model. | @@ -49,10 +49,10 @@ The Vertex AI in Firebase Web SDK. | Enumeration | Description | | --- | --- | +| [AIErrorCode](./vertexai.md#aierrorcode) | Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. | | [BlockReason](./vertexai.md#blockreason) | Reason that a prompt was blocked. | | [FinishReason](./vertexai.md#finishreason) | Reason that a candidate finished. | | [FunctionCallingMode](./vertexai.md#functioncallingmode) | | -| [GenAIErrorCode](./vertexai.md#genaierrorcode) | Standardized error codes that [GenAIError](./vertexai.genaierror.md#genaierror_class) can have. | | [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in Google AI. | | [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | | [HarmCategory](./vertexai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | @@ -68,6 +68,8 @@ The Vertex AI in Firebase Web SDK. | Interface | Description | | --- | --- | +| [AI](./vertexai.ai.md#ai_interface) | An instance of the Firebase AI SDK.Do not create this instance directly. Instead, use [getAI()](./vertexai.md#getai_a94a413). | +| [AIOptions](./vertexai.aioptions.md#aioptions_interface) | Options interface for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). | | [BaseParams](./vertexai.baseparams.md#baseparams_interface) | Base parameters for a number of methods. | | [Citation](./vertexai.citation.md#citation_interface) | A single citation. | | [CitationMetadata](./vertexai.citationmetadata.md#citationmetadata_interface) | Citation metadata that may be found on a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface). | @@ -87,8 +89,6 @@ The Vertex AI in Firebase Web SDK. | [FunctionDeclarationsTool](./vertexai.functiondeclarationstool.md#functiondeclarationstool_interface) | A FunctionDeclarationsTool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. | | [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface) | The result output from a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) that contains a string representing the [FunctionDeclaration.name](./vertexai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) made based on model prediction. | | [FunctionResponsePart](./vertexai.functionresponsepart.md#functionresponsepart_interface) | Content part interface if the part represents [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface). | -| [GenAI](./vertexai.genai.md#genai_interface) | An instance of the Firebase GenAI SDK.Do not create this instance directly. Instead, use [getGenAI()](./vertexai.md#getgenai_65c48ee). | -| [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) | Options interface for initializing the GenAI service using [getGenAI()](./vertexai.md#getgenai_65c48ee). | | [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | A candidate returned as part of a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | | [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) | Request sent through [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) | | [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface) | Individual response from [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) and [GenerativeModel.generateContentStream()](./vertexai.generativemodel.md#generativemodelgeneratecontentstream). generateContentStream() will return one in each chunk until the stream is done. | @@ -106,10 +106,10 @@ The Vertex AI in Firebase Web SDK. | [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Settings for controlling the aggressiveness of filtering out sensitive content.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details. | | [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. | | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. | -| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3ccf80). | +| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). | | [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. | | [PromptFeedback](./vertexai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with blockReason and the relevant safetyRatings. | -| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3ccf80). | +| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). | | [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | | | [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | | [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. | @@ -122,7 +122,7 @@ The Vertex AI in Firebase Web SDK. | [TextPart](./vertexai.textpart.md#textpart_interface) | Content part interface if the part represents a text string. | | [ToolConfig](./vertexai.toolconfig.md#toolconfig_interface) | Tool config. This config is shared for all tools provided in the request. | | [UsageMetadata](./vertexai.usagemetadata.md#usagemetadata_interface) | Usage metadata about a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | -| [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | Options when initializing the Vertex AI in Firebase SDK. | +| [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | Options when initializing the Firebase AI SDK. | | [VideoMetadata](./vertexai.videometadata.md#videometadata_interface) | Describes the input video content. | | [WebAttribution](./vertexai.webattribution.md#webattribution_interface) | | @@ -130,35 +130,35 @@ The Vertex AI in Firebase Web SDK. | Variable | Description | | --- | --- | -| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase GenAI SDK.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.md#googleaibackend) or [VertexAIBackend](./vertexai.md#vertexaibackend)) to identify which service to target. | +| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.md#googleaibackend) or [VertexAIBackend](./vertexai.md#vertexaibackend)) to identify which service to target. | | [POSSIBLE\_ROLES](./vertexai.md#possible_roles) | Possible roles. | -| [VertexAIError](./vertexai.md#vertexaierror) | Error class for the Vertex AI in Firebase SDK.For more information, refer to the documentation for the new [GenAIError](./vertexai.genaierror.md#genaierror_class). | -| [VertexAIModel](./vertexai.md#vertexaimodel) | Base class for Vertex AI in Firebase model APIs.For more information, refer to the documentation for the new [GenAIModel](./vertexai.genaimodel.md#genaimodel_class). | +| [VertexAIError](./vertexai.md#vertexaierror) | Error class for the Firebase AI SDK.For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). | +| [VertexAIModel](./vertexai.md#vertexaimodel) | Base class for Firebase AI model APIs.For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). | ## Type Aliases | Type Alias | Description | | --- | --- | -| [Backend](./vertexai.md#backend) | Union type representing the backend configuration for the GenAI service. This can be either a [GoogleAIBackend](./vertexai.md#googleaibackend) or a [VertexAIBackend](./vertexai.md#vertexaibackend) configuration object.Create instances using [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534). | +| [Backend](./vertexai.md#backend) | Union type representing the backend configuration for the AI service. This can be either a [GoogleAIBackend](./vertexai.md#googleaibackend) or a [VertexAIBackend](./vertexai.md#vertexaibackend) configuration object.Create instances using [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534). | | [BackendType](./vertexai.md#backendtype) | Type alias representing valid backend types. It can be either 'VERTEX_AI' or 'GOOGLE_AI'. | -| [GoogleAIBackend](./vertexai.md#googleaibackend) | Represents the configuration object for the Google AI backend. Use this with [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) when initializing the service with [getGenAI()](./vertexai.md#getgenai_65c48ee). Create an instance using [googleAIBackend()](./vertexai.md#googleaibackend). | +| [GoogleAIBackend](./vertexai.md#googleaibackend) | Represents the configuration object for the Google AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the service with [getAI()](./vertexai.md#getai_a94a413). Create an instance using [googleAIBackend()](./vertexai.md#googleaibackend). | | [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. | | [Role](./vertexai.md#role) | Role is the producer of the content. | | [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. | | [TypedSchema](./vertexai.md#typedschema) | A type that includes all specific Schema types. | -| [VertexAI](./vertexai.md#vertexai) | An instance of the Vertex AI in Firebase SDK.For more information, refer to the documentation for the new [GenAI](./vertexai.genai.md#genai_interface). | -| [VertexAIBackend](./vertexai.md#vertexaibackend) | Represents the configuration object for the Vertex AI backend. Use this with [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) when initializing the server with [getGenAI()](./vertexai.md#getgenai_65c48ee). Create an instance using [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) function. | +| [VertexAI](./vertexai.md#vertexai) | An instance of the Firebase AI SDK.For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface). | +| [VertexAIBackend](./vertexai.md#vertexaibackend) | Represents the configuration object for the Vertex AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the server with [getAI()](./vertexai.md#getai_a94a413). Create an instance using [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) function. | ## function(app, ...) -### getGenAI(app, options) {:#getgenai_65c48ee} +### getAI(app, options) {:#getai_a94a413} -Returns the default [GenAI](./vertexai.genai.md#genai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. +Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. Signature: ```typescript -export declare function getGenAI(app?: FirebaseApp, options?: GenAIOptions): GenAI; +export declare function getAI(app?: FirebaseApp, options?: AIOptions): AI; ``` #### Parameters @@ -166,19 +166,19 @@ export declare function getGenAI(app?: FirebaseApp, options?: GenAIOptions): Gen | Parameter | Type | Description | | --- | --- | --- | | app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | -| options | [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) | [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) that configure the GenAI instance. | +| options | [AIOptions](./vertexai.aioptions.md#aioptions_interface) | [AIOptions](./vertexai.aioptions.md#aioptions_interface) that configure the AI instance. | Returns: -[GenAI](./vertexai.genai.md#genai_interface) +[AI](./vertexai.ai.md#ai_interface) -The default [GenAI](./vertexai.genai.md#genai_interface) instance for the given [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). +The default [AI](./vertexai.ai.md#ai_interface) instance for the given [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). ### Example 1 ```javascript -const genAI = getGenAI(app); +const ai = getAI(app); ``` @@ -186,8 +186,8 @@ const genAI = getGenAI(app); ```javascript -// Get a GenAI instance configured to use Google AI. -const genAI = getGenAI(app, { backend: googleAIBackend() }); +// Get an AI instance configured to use Google AI. +const ai = getAI(app, { backend: googleAIBackend() }); ``` @@ -195,8 +195,8 @@ const genAI = getGenAI(app, { backend: googleAIBackend() }); ```javascript -// Get a GenAI instance configured to use Vertex AI. -const genAI = getGenAI(app, { backend: vertexAIBackend() }); +// Get an AI instance configured to use Vertex AI. +const ai = getAI(app, { backend: vertexAIBackend() }); ``` @@ -238,23 +238,23 @@ export declare function googleAIBackend(): GoogleAIBackend; A [GoogleAIBackend](./vertexai.md#googleaibackend) object. -## function(genAI, ...) +## function(ai, ...) -### getGenerativeModel(genAI, modelParams, requestOptions) {:#getgenerativemodel_e3ccf80} +### getGenerativeModel(ai, modelParams, requestOptions) {:#getgenerativemodel_80bd839} Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. Signature: ```typescript -export declare function getGenerativeModel(genAI: GenAI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; +export declare function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| genAI | [GenAI](./vertexai.genai.md#genai_interface) | | +| ai | [AI](./vertexai.ai.md#ai_interface) | | | modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | @@ -262,7 +262,7 @@ export declare function getGenerativeModel(genAI: GenAI, modelParams: ModelParam [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) -### getImagenModel(genAI, modelParams, requestOptions) {:#getimagenmodel_bffbd6b} +### getImagenModel(ai, modelParams, requestOptions) {:#getimagenmodel_e1f6645} > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > @@ -274,14 +274,14 @@ Only Imagen 3 models (named `imagen-3.0-*`) are supported. Signature: ```typescript -export declare function getImagenModel(genAI: GenAI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; +export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | -| genAI | [GenAI](./vertexai.genai.md#genai_interface) | A [GenAI](./vertexai.genai.md#genai_interface) instance. | +| ai | [AI](./vertexai.ai.md#ai_interface) | An [AI](./vertexai.ai.md#ai_interface) instance. | | modelParams | [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making Imagen requests. | | requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. | @@ -319,7 +319,7 @@ A [VertexAIBackend](./vertexai.md#vertexaibackend) object. ## BackendType -An enum-like object containing constants that represent the supported backends for the Firebase GenAI SDK. +An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.md#googleaibackend) or [VertexAIBackend](./vertexai.md#vertexaibackend)) to identify which service to target. @@ -344,31 +344,31 @@ POSSIBLE_ROLES: readonly ["user", "model", "function", "system"] ## VertexAIError -Error class for the Vertex AI in Firebase SDK. +Error class for the Firebase AI SDK. -For more information, refer to the documentation for the new [GenAIError](./vertexai.genaierror.md#genaierror_class). +For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). Signature: ```typescript -VertexAIError: typeof GenAIError +VertexAIError: typeof AIError ``` ## VertexAIModel -Base class for Vertex AI in Firebase model APIs. +Base class for Firebase AI model APIs. -For more information, refer to the documentation for the new [GenAIModel](./vertexai.genaimodel.md#genaimodel_class). +For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). Signature: ```typescript -VertexAIModel: typeof GenAIModel +VertexAIModel: typeof AIModel ``` ## Backend -Union type representing the backend configuration for the GenAI service. This can be either a [GoogleAIBackend](./vertexai.md#googleaibackend) or a [VertexAIBackend](./vertexai.md#vertexaibackend) configuration object. +Union type representing the backend configuration for the AI service. This can be either a [GoogleAIBackend](./vertexai.md#googleaibackend) or a [VertexAIBackend](./vertexai.md#vertexaibackend) configuration object. Create instances using [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534). @@ -390,7 +390,7 @@ export type BackendType = (typeof BackendType)[keyof typeof BackendType]; ## GoogleAIBackend -Represents the configuration object for the Google AI backend. Use this with [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) when initializing the service with [getGenAI()](./vertexai.md#getgenai_65c48ee). Create an instance using [googleAIBackend()](./vertexai.md#googleaibackend). +Represents the configuration object for the Google AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the service with [getAI()](./vertexai.md#getai_a94a413). Create an instance using [googleAIBackend()](./vertexai.md#googleaibackend). Signature: @@ -442,19 +442,19 @@ export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanS ## VertexAI -An instance of the Vertex AI in Firebase SDK. +An instance of the Firebase AI SDK. -For more information, refer to the documentation for the new [GenAI](./vertexai.genai.md#genai_interface). +For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface). Signature: ```typescript -export type VertexAI = GenAI; +export type VertexAI = AI; ``` ## VertexAIBackend -Represents the configuration object for the Vertex AI backend. Use this with [GenAIOptions](./vertexai.genaioptions.md#genaioptions_interface) when initializing the server with [getGenAI()](./vertexai.md#getgenai_65c48ee). Create an instance using [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) function. +Represents the configuration object for the Vertex AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the server with [getAI()](./vertexai.md#getai_a94a413). Create an instance using [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) function. Signature: @@ -465,6 +465,34 @@ export type VertexAIBackend = { }; ``` +## AIErrorCode + +Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. + +Signature: + +```typescript +export declare const enum AIErrorCode +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| API\_NOT\_ENABLED | "api-not-enabled" | An error due to the Firebase API not being enabled in the Console. | +| ERROR | "error" | A generic error occurred. | +| FETCH\_ERROR | "fetch-error" | An error occurred while performing a fetch. | +| INVALID\_CONTENT | "invalid-content" | An error associated with a Content object. | +| INVALID\_SCHEMA | "invalid-schema" | An error due to invalid Schema input. | +| NO\_API\_KEY | "no-api-key" | An error occurred due to a missing Firebase API key. | +| NO\_APP\_ID | "no-app-id" | An error occured due to a missing Firebase app ID. | +| NO\_MODEL | "no-model" | An error occurred due to a model name not being specified during initialization. | +| NO\_PROJECT\_ID | "no-project-id" | An error occurred due to a missing project ID. | +| PARSE\_FAILED | "parse-failed" | An error occurred while parsing. | +| REQUEST\_ERROR | "request-error" | An error occurred in a request. | +| RESPONSE\_ERROR | "response-error" | An error occurred in a response. | +| UNSUPPORTED | "unsupported" | An error occured due an attempt to use an unsupported feature. | + ## BlockReason Reason that a prompt was blocked. @@ -525,34 +553,6 @@ export declare enum FunctionCallingMode | AUTO | "AUTO" | Default model behavior; model decides to predict either a function call or a natural language response. | | NONE | "NONE" | Model will not predict any function call. Model behavior is same as when not passing any function declarations. | -## GenAIErrorCode - -Standardized error codes that [GenAIError](./vertexai.genaierror.md#genaierror_class) can have. - -Signature: - -```typescript -export declare const enum GenAIErrorCode -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| API\_NOT\_ENABLED | "api-not-enabled" | An error due to the Firebase API not being enabled in the Console. | -| ERROR | "error" | A generic error occurred. | -| FETCH\_ERROR | "fetch-error" | An error occurred while performing a fetch. | -| INVALID\_CONTENT | "invalid-content" | An error associated with a Content object. | -| INVALID\_SCHEMA | "invalid-schema" | An error due to invalid Schema input. | -| NO\_API\_KEY | "no-api-key" | An error occurred due to a missing Firebase API key. | -| NO\_APP\_ID | "no-app-id" | An error occured due to a missing Firebase app ID. | -| NO\_MODEL | "no-model" | An error occurred due to a model name not being specified during initialization. | -| NO\_PROJECT\_ID | "no-project-id" | An error occurred due to a missing project ID. | -| PARSE\_FAILED | "parse-failed" | An error occurred while parsing. | -| REQUEST\_ERROR | "request-error" | An error occurred in a request. | -| RESPONSE\_ERROR | "response-error" | An error occurred in a response. | -| UNSUPPORTED | "unsupported" | An error occured due an attempt to use an unsupported feature. | - ## HarmBlockMethod This property is not supported in Google AI. diff --git a/docs-devsite/vertexai.modelparams.md b/docs-devsite/vertexai.modelparams.md index f25f37e4dd6..bb8a87d5fb2 100644 --- a/docs-devsite/vertexai.modelparams.md +++ b/docs-devsite/vertexai.modelparams.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # ModelParams interface -Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3ccf80). +Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). Signature: diff --git a/docs-devsite/vertexai.requestoptions.md b/docs-devsite/vertexai.requestoptions.md index ffedaa69859..3c233d72b90 100644 --- a/docs-devsite/vertexai.requestoptions.md +++ b/docs-devsite/vertexai.requestoptions.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # RequestOptions interface -Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_e3ccf80). +Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). Signature: diff --git a/docs-devsite/vertexai.safetysetting.md b/docs-devsite/vertexai.safetysetting.md index 5a837e8aeff..92f98e3c02a 100644 --- a/docs-devsite/vertexai.safetysetting.md +++ b/docs-devsite/vertexai.safetysetting.md @@ -23,7 +23,7 @@ export interface SafetySetting | Property | Type | Description | | --- | --- | --- | | [category](./vertexai.safetysetting.md#safetysettingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | -| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in Google AI. If this is a property on a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) to be sent, a [GenAIError](./vertexai.genaierror.md#genaierror_class) will be thrown. | +| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in Google AI. If this is a property on a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) to be sent, an [AIError](./vertexai.aierror.md#aierror_class) will be thrown. | | [threshold](./vertexai.safetysetting.md#safetysettingthreshold) | [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | | ## SafetySetting.category @@ -36,7 +36,7 @@ category: HarmCategory; ## SafetySetting.method -This property is not supported in Google AI. If this is a property on a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) to be sent, a [GenAIError](./vertexai.genaierror.md#genaierror_class) will be thrown. +This property is not supported in Google AI. If this is a property on a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) to be sent, an [AIError](./vertexai.aierror.md#aierror_class) will be thrown. Signature: diff --git a/docs-devsite/vertexai.vertexaioptions.md b/docs-devsite/vertexai.vertexaioptions.md index e15b525bfed..776dfd29374 100644 --- a/docs-devsite/vertexai.vertexaioptions.md +++ b/docs-devsite/vertexai.vertexaioptions.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # VertexAIOptions interface -Options when initializing the Vertex AI in Firebase SDK. +Options when initializing the Firebase AI SDK. Signature: diff --git a/packages/firebase/package.json b/packages/firebase/package.json index f47e3378ee2..e1609b07176 100644 --- a/packages/firebase/package.json +++ b/packages/firebase/package.json @@ -227,7 +227,7 @@ }, "default": "./storage/dist/esm/index.esm.js" }, - "./genai": { + "./ai": { "types": "./vertexai/dist/vertexai/index.d.ts", "node": { "require": "./vertexai/dist/index.cjs.js", diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index dc04b918dd9..bf85c557b1e 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -14,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImagenModelParams, ModelParams, GenAIErrorCode } from './types'; -import { GenAIError } from './errors'; +import { ImagenModelParams, ModelParams, AIErrorCode } from './types'; +import { AIError } from './errors'; import { ImagenModel, getGenerativeModel, @@ -24,11 +24,11 @@ import { vertexAIBackend } from './api'; import { expect } from 'chai'; -import { BackendType, GenAI } from './public-types'; +import { BackendType, AI } from './public-types'; import { GenerativeModel } from './models/generative-model'; import { DEFAULT_LOCATION } from './constants'; -const fakeGenAI: GenAI = { +const fakeAI: AI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -45,129 +45,129 @@ const fakeGenAI: GenAI = { describe('Top level API', () => { it('getGenerativeModel throws if no model is provided', () => { try { - getGenerativeModel(fakeGenAI, {} as ModelParams); + getGenerativeModel(fakeAI, {} as ModelParams); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.NO_MODEL); - expect((e as GenAIError).message).includes( + expect((e as AIError).code).includes(AIErrorCode.NO_MODEL); + expect((e as AIError).message).includes( `VertexAI: Must provide a model name. Example: ` + - `getGenerativeModel({ model: 'my-model-name' }) (vertexAI/${GenAIErrorCode.NO_MODEL})` + `getGenerativeModel({ model: 'my-model-name' }) (vertexAI/${AIErrorCode.NO_MODEL})` ); } }); it('getGenerativeModel throws if no apiKey is provided', () => { const fakeVertexNoApiKey = { - ...fakeGenAI, + ...fakeAI, app: { options: { projectId: 'my-project', appId: 'my-appid' } } - } as GenAI; + } as AI; try { getGenerativeModel(fakeVertexNoApiKey, { model: 'my-model' }); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.NO_API_KEY); - expect((e as GenAIError).message).equals( + expect((e as AIError).code).includes(AIErrorCode.NO_API_KEY); + expect((e as AIError).message).equals( `VertexAI: The "apiKey" field is empty in the local ` + - `Firebase config. Firebase VertexAI requires this field to` + - ` contain a valid API key. (vertexAI/${GenAIErrorCode.NO_API_KEY})` + `Firebase config. Firebase AI requires this field to` + + ` contain a valid API key. (vertexAI/${AIErrorCode.NO_API_KEY})` ); } }); it('getGenerativeModel throws if no projectId is provided', () => { const fakeVertexNoProject = { - ...fakeGenAI, + ...fakeAI, app: { options: { apiKey: 'my-key', appId: 'my-appid' } } - } as GenAI; + } as AI; try { getGenerativeModel(fakeVertexNoProject, { model: 'my-model' }); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.NO_PROJECT_ID); - expect((e as GenAIError).message).equals( + expect((e as AIError).code).includes(AIErrorCode.NO_PROJECT_ID); + expect((e as AIError).message).equals( `VertexAI: The "projectId" field is empty in the local` + - ` Firebase config. Firebase VertexAI requires this field ` + - `to contain a valid project ID. (vertexAI/${GenAIErrorCode.NO_PROJECT_ID})` + ` Firebase config. Firebase AI requires this field ` + + `to contain a valid project ID. (vertexAI/${AIErrorCode.NO_PROJECT_ID})` ); } }); it('getGenerativeModel throws if no appId is provided', () => { const fakeVertexNoProject = { - ...fakeGenAI, + ...fakeAI, app: { options: { apiKey: 'my-key', projectId: 'my-projectid' } } - } as GenAI; + } as AI; try { getGenerativeModel(fakeVertexNoProject, { model: 'my-model' }); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.NO_APP_ID); - expect((e as GenAIError).message).equals( + expect((e as AIError).code).includes(AIErrorCode.NO_APP_ID); + expect((e as AIError).message).equals( `VertexAI: The "appId" field is empty in the local` + - ` Firebase config. Firebase VertexAI requires this field ` + - `to contain a valid app ID. (vertexAI/${GenAIErrorCode.NO_APP_ID})` + ` Firebase config. Firebase AI requires this field ` + + `to contain a valid app ID. (vertexAI/${AIErrorCode.NO_APP_ID})` ); } }); it('getGenerativeModel gets a GenerativeModel', () => { - const genModel = getGenerativeModel(fakeGenAI, { model: 'my-model' }); + const genModel = getGenerativeModel(fakeAI, { model: 'my-model' }); expect(genModel).to.be.an.instanceOf(GenerativeModel); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); it('getImagenModel throws if no model is provided', () => { try { - getImagenModel(fakeGenAI, {} as ImagenModelParams); + getImagenModel(fakeAI, {} as ImagenModelParams); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.NO_MODEL); - expect((e as GenAIError).message).includes( + expect((e as AIError).code).includes(AIErrorCode.NO_MODEL); + expect((e as AIError).message).includes( `VertexAI: Must provide a model name. Example: ` + - `getImagenModel({ model: 'my-model-name' }) (vertexAI/${GenAIErrorCode.NO_MODEL})` + `getImagenModel({ model: 'my-model-name' }) (vertexAI/${AIErrorCode.NO_MODEL})` ); } }); it('getImagenModel throws if no apiKey is provided', () => { const fakeVertexNoApiKey = { - ...fakeGenAI, + ...fakeAI, app: { options: { projectId: 'my-project', appId: 'my-appid' } } - } as GenAI; + } as AI; try { getImagenModel(fakeVertexNoApiKey, { model: 'my-model' }); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.NO_API_KEY); - expect((e as GenAIError).message).equals( + expect((e as AIError).code).includes(AIErrorCode.NO_API_KEY); + expect((e as AIError).message).equals( `VertexAI: The "apiKey" field is empty in the local ` + - `Firebase config. Firebase VertexAI requires this field to` + - ` contain a valid API key. (vertexAI/${GenAIErrorCode.NO_API_KEY})` + `Firebase config. Firebase AI requires this field to` + + ` contain a valid API key. (vertexAI/${AIErrorCode.NO_API_KEY})` ); } }); it('getImagenModel throws if no projectId is provided', () => { const fakeVertexNoProject = { - ...fakeGenAI, + ...fakeAI, app: { options: { apiKey: 'my-key', appId: 'my-appid' } } - } as GenAI; + } as AI; try { getImagenModel(fakeVertexNoProject, { model: 'my-model' }); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.NO_PROJECT_ID); - expect((e as GenAIError).message).equals( + expect((e as AIError).code).includes(AIErrorCode.NO_PROJECT_ID); + expect((e as AIError).message).equals( `VertexAI: The "projectId" field is empty in the local` + - ` Firebase config. Firebase VertexAI requires this field ` + - `to contain a valid project ID. (vertexAI/${GenAIErrorCode.NO_PROJECT_ID})` + ` Firebase config. Firebase AI requires this field ` + + `to contain a valid project ID. (vertexAI/${AIErrorCode.NO_PROJECT_ID})` ); } }); it('getImagenModel throws if no appId is provided', () => { const fakeVertexNoProject = { - ...fakeGenAI, + ...fakeAI, app: { options: { apiKey: 'my-key', projectId: 'my-project' } } - } as GenAI; + } as AI; try { getImagenModel(fakeVertexNoProject, { model: 'my-model' }); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.NO_APP_ID); - expect((e as GenAIError).message).equals( + expect((e as AIError).code).includes(AIErrorCode.NO_APP_ID); + expect((e as AIError).message).equals( `VertexAI: The "appId" field is empty in the local` + - ` Firebase config. Firebase VertexAI requires this field ` + - `to contain a valid app ID. (vertexAI/${GenAIErrorCode.NO_APP_ID})` + ` Firebase config. Firebase AI requires this field ` + + `to contain a valid app ID. (vertexAI/${AIErrorCode.NO_APP_ID})` ); } }); it('getImagenModel gets an ImagenModel', () => { - const genModel = getImagenModel(fakeGenAI, { model: 'my-model' }); + const genModel = getImagenModel(fakeAI, { model: 'my-model' }); expect(genModel).to.be.an.instanceOf(ImagenModel); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index 11f9dbcf56c..d5e641a582c 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -18,12 +18,12 @@ import { FirebaseApp, getApp, _getProvider } from '@firebase/app'; import { Provider } from '@firebase/component'; import { getModularInstance } from '@firebase/util'; -import { DEFAULT_LOCATION, GENAI_TYPE } from './constants'; -import { GenAIService } from './service'; +import { DEFAULT_LOCATION, AI_TYPE } from './constants'; +import { AIService } from './service'; import { BackendType, - GenAI, - GenAIOptions, + AI, + AIOptions, GoogleAIBackend, VertexAI, VertexAIBackend, @@ -33,44 +33,46 @@ import { ImagenModelParams, ModelParams, RequestOptions, - GenAIErrorCode + AIErrorCode } from './types'; -import { GenAIError } from './errors'; -import { GenAIModel, GenerativeModel, ImagenModel } from './models'; +import { AIError } from './errors'; +import { AIModel, GenerativeModel, ImagenModel } from './models'; import { encodeInstanceIdentifier } from './helpers'; export { ChatSession } from './methods/chat-session'; export * from './requests/schema-builder'; export { ImagenImageFormat } from './requests/imagen-image-format'; -export { GenAIModel, GenerativeModel, ImagenModel, GenAIError }; +export { AIModel, GenerativeModel, ImagenModel, AIError }; -export { GenAIErrorCode as VertexAIErrorCode }; +export { AIErrorCode as VertexAIErrorCode }; /** - * Base class for Vertex AI in Firebase model APIs. + * Base class for Firebase AI model APIs. * - * For more information, refer to the documentation for the new {@link GenAIModel}. + * For more information, refer to the documentation for the new {@link AIModel}. * * @public */ -export const VertexAIModel = GenAIModel; +export const VertexAIModel = AIModel; /** - * Error class for the Vertex AI in Firebase SDK. + * Error class for the Firebase AI SDK. * - * For more information, refer to the documentation for the new {@link GenAIError}. + * For more information, refer to the documentation for the new {@link AIError}. * * @public */ -export const VertexAIError = GenAIError; +export const VertexAIError = AIError; declare module '@firebase/component' { interface NameServiceMapping { - [GENAI_TYPE]: GenAIService; + [AI_TYPE]: AIService; } } /** + * It is recommended to use the new {@link getAI | getAI()}. + * * Returns a {@link VertexAI} instance for the given app. * * @public @@ -83,55 +85,55 @@ export function getVertexAI( ): VertexAI { app = getModularInstance(app); // Dependencies - const genAIProvider: Provider<'genAI'> = _getProvider(app, GENAI_TYPE); + const AIProvider: Provider<'AI'> = _getProvider(app, AI_TYPE); const identifier = encodeInstanceIdentifier({ backendType: BackendType.VERTEX_AI, location: options?.location ?? DEFAULT_LOCATION }); - return genAIProvider.getImmediate({ + return AIProvider.getImmediate({ identifier }); } /** - * Returns the default {@link GenAI} instance that is associated with the provided + * Returns the default {@link AI} instance that is associated with the provided * {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new instance with the * default settings. * * @example * ```javascript - * const genAI = getGenAI(app); + * const ai = getAI(app); * ``` * * @example * ```javascript - * // Get a GenAI instance configured to use Google AI. - * const genAI = getGenAI(app, { backend: googleAIBackend() }); + * // Get an AI instance configured to use Google AI. + * const ai = getAI(app, { backend: googleAIBackend() }); * ``` * * @example * ```javascript - * // Get a GenAI instance configured to use Vertex AI. - * const genAI = getGenAI(app, { backend: vertexAIBackend() }); + * // Get an AI instance configured to use Vertex AI. + * const ai = getAI(app, { backend: vertexAIBackend() }); * ``` * * @param app - The {@link @firebase/app#FirebaseApp} to use. - * @param options - {@link GenAIOptions} that configure the GenAI instance. - * @returns The default {@link GenAI} instance for the given {@link @firebase/app#FirebaseApp}. + * @param options - {@link AIOptions} that configure the AI instance. + * @returns The default {@link AI} instance for the given {@link @firebase/app#FirebaseApp}. * * @public */ -export function getGenAI( +export function getAI( app: FirebaseApp = getApp(), - options: GenAIOptions = { backend: googleAIBackend() } -): GenAI { + options: AIOptions = { backend: googleAIBackend() } +): AI { app = getModularInstance(app); // Dependencies - const genAIProvider: Provider<'genAI'> = _getProvider(app, GENAI_TYPE); + const AIProvider: Provider<'AI'> = _getProvider(app, AI_TYPE); const identifier = encodeInstanceIdentifier(options.backend); - return genAIProvider.getImmediate({ + return AIProvider.getImmediate({ identifier }); } @@ -177,17 +179,17 @@ export function vertexAIBackend(location?: string): VertexAIBackend { * @public */ export function getGenerativeModel( - genAI: GenAI, + ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions ): GenerativeModel { if (!modelParams.model) { - throw new GenAIError( - GenAIErrorCode.NO_MODEL, + throw new AIError( + AIErrorCode.NO_MODEL, `Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })` ); } - return new GenerativeModel(genAI, modelParams, requestOptions); + return new GenerativeModel(ai, modelParams, requestOptions); } /** @@ -195,7 +197,7 @@ export function getGenerativeModel( * * Only Imagen 3 models (named `imagen-3.0-*`) are supported. * - * @param genAI - A {@link GenAI} instance. + * @param ai - An {@link AI} instance. * @param modelParams - Parameters to use when making Imagen requests. * @param requestOptions - Additional options to use when making requests. * @@ -205,15 +207,15 @@ export function getGenerativeModel( * @beta */ export function getImagenModel( - genAI: GenAI, + ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions ): ImagenModel { if (!modelParams.model) { - throw new GenAIError( - GenAIErrorCode.NO_MODEL, + throw new AIError( + AIErrorCode.NO_MODEL, `Must provide a model name. Example: getImagenModel({ model: 'my-model-name' })` ); } - return new ImagenModel(genAI, modelParams, requestOptions); + return new ImagenModel(ai, modelParams, requestOptions); } diff --git a/packages/vertexai/src/backwards-compatbility.test.ts b/packages/vertexai/src/backwards-compatbility.test.ts index 23d0511445a..7f96328b305 100644 --- a/packages/vertexai/src/backwards-compatbility.test.ts +++ b/packages/vertexai/src/backwards-compatbility.test.ts @@ -17,8 +17,8 @@ import { expect } from 'chai'; import { - GenAIError, - GenAIModel, + AIError, + AIModel, GenerativeModel, VertexAIError, VertexAIErrorCode, @@ -27,11 +27,11 @@ import { getImagenModel, vertexAIBackend } from './api'; -import { GenAI, VertexAI, GenAIErrorCode } from './public-types'; +import { AI, VertexAI, AIErrorCode } from './public-types'; function assertAssignable(): void {} -const fakeGenAI: GenAI = { +const fakeAI: AI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -45,28 +45,28 @@ const fakeGenAI: GenAI = { location: 'us-central1' }; -const fakeVertexAI: VertexAI = fakeGenAI; +const fakeVertexAI: VertexAI = fakeAI; describe('backwards-compatible types', () => { - it('GenAI is backwards compatible with VertexAI', () => { - assertAssignable(); + it('AI is backwards compatible with VertexAI', () => { + assertAssignable(); }); - it('GenAIError is backwards compatible with VertexAIError', () => { - assertAssignable(); + it('AIError is backwards compatible with VertexAIError', () => { + assertAssignable(); const err = new VertexAIError(VertexAIErrorCode.ERROR, ''); - expect(err).instanceOf(GenAIError); + expect(err).instanceOf(AIError); expect(err).instanceOf(VertexAIError); }); - it('GenAIErrorCode is backwards compatible with VertexAIErrorCode', () => { - assertAssignable(); - const errCode = GenAIErrorCode.ERROR; + it('AIErrorCode is backwards compatible with VertexAIErrorCode', () => { + assertAssignable(); + const errCode = AIErrorCode.ERROR; expect(errCode).to.equal(VertexAIErrorCode.ERROR); }); - it('GenAIModel is backwards compatible with VertexAIModel', () => { - assertAssignable(); + it('AIModel is backwards compatible with VertexAIModel', () => { + assertAssignable(); - const model = new GenerativeModel(fakeGenAI, { model: 'model-name' }); - expect(model).to.be.instanceOf(GenAIModel); + const model = new GenerativeModel(fakeAI, { model: 'model-name' }); + expect(model).to.be.instanceOf(AIModel); expect(model).to.be.instanceOf(VertexAIModel); }); }); @@ -74,12 +74,12 @@ describe('backwards-compatible types', () => { describe('backward-compatible functions', () => { it('getGenerativeModel', () => { const model = getGenerativeModel(fakeVertexAI, { model: 'model-name' }); - expect(model).to.be.instanceOf(GenAIModel); + expect(model).to.be.instanceOf(AIModel); expect(model).to.be.instanceOf(VertexAIModel); }); it('getImagenModel', () => { const model = getImagenModel(fakeVertexAI, { model: 'model-name' }); - expect(model).to.be.instanceOf(GenAIModel); + expect(model).to.be.instanceOf(AIModel); expect(model).to.be.instanceOf(VertexAIModel); }); }); diff --git a/packages/vertexai/src/constants.ts b/packages/vertexai/src/constants.ts index 4034e410003..8bb46222ddd 100644 --- a/packages/vertexai/src/constants.ts +++ b/packages/vertexai/src/constants.ts @@ -22,9 +22,9 @@ import { InstanceIdentifier } from './types/internal'; // TODO (v12): Remove this export const VERTEX_TYPE = 'vertexAI'; -export const GENAI_TYPE = 'genAI'; +export const AI_TYPE = 'AI'; -export const DEFAULT_INSTANCE_IDENTIFER: InstanceIdentifier = { +export const DEFAULT_INSTANCE_IDENTIFIER: InstanceIdentifier = { backendType: BackendType.GOOGLE_AI }; diff --git a/packages/vertexai/src/errors.ts b/packages/vertexai/src/errors.ts index c836e49d51e..85180fe8381 100644 --- a/packages/vertexai/src/errors.ts +++ b/packages/vertexai/src/errors.ts @@ -16,30 +16,30 @@ */ import { FirebaseError } from '@firebase/util'; -import { GenAIErrorCode as GenAIErrorCode, CustomErrorData } from './types'; +import { AIErrorCode as AIErrorCode, CustomErrorData } from './types'; import { VERTEX_TYPE } from './constants'; /** - * Error class for the Vertex AI in Firebase SDK. + * Error class for the Firebase AI SDK. * * @public */ -export class GenAIError extends FirebaseError { +export class AIError extends FirebaseError { /** - * Constructs a new instance of the `GenAIError` class. + * Constructs a new instance of the `AIError` class. * - * @param code - The error code from {@link GenAIErrorCode}. + * @param code - The error code from {@link AIErrorCode}. * @param message - A human-readable message describing the error. * @param customErrorData - Optional error data. */ constructor( - readonly code: GenAIErrorCode, + readonly code: AIErrorCode, message: string, readonly customErrorData?: CustomErrorData ) { // Match error format used by FirebaseError from ErrorFactory - const service = VERTEX_TYPE; // TODO (v12): Rename to GENAI_TYPE - const serviceName = 'VertexAI'; // TODO (v12): Rename to GenAI on breaking release. + const service = VERTEX_TYPE; // TODO (v12): Rename to GENAI_TYPE on breaking release. + const serviceName = 'VertexAI'; // TODO (v12): Rename to AI on breaking release. const fullCode = `${service}/${code}`; const fullMessage = `${serviceName}: ${message} (${fullCode})`; super(code, fullMessage); @@ -51,14 +51,14 @@ export class GenAIError extends FirebaseError { if (Error.captureStackTrace) { // Allows us to initialize the stack trace without including the constructor itself at the // top level of the stack trace. - Error.captureStackTrace(this, GenAIError); + Error.captureStackTrace(this, AIError); } - // Allows instanceof GenAIError in ES5/ES6 + // Allows instanceof AIError in ES5/ES6 // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work // TODO(dlarocque): Replace this with `new.target`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget // which we can now use since we no longer target ES5. - Object.setPrototypeOf(this, GenAIError.prototype); + Object.setPrototypeOf(this, AIError.prototype); // Since Error is an interface, we don't inherit toString and so we define it ourselves. this.toString = () => fullMessage; diff --git a/packages/vertexai/src/googleAIMappers.test.ts b/packages/vertexai/src/googleAIMappers.test.ts index 3952cce2544..6cf7425a293 100644 --- a/packages/vertexai/src/googleAIMappers.test.ts +++ b/packages/vertexai/src/googleAIMappers.test.ts @@ -36,7 +36,7 @@ import { HarmProbability, HarmSeverity, SafetyRating, - GenAIErrorCode, + AIErrorCode, FinishReason, PromptFeedback } from './types'; @@ -46,7 +46,7 @@ import { GoogleAICountTokensRequest } from './types/googleAI'; import { logger } from './logger'; -import { GenAIError } from './errors'; +import { AIError } from './errors'; import { getMockResponse } from '../test-utils/mock-response'; use(sinonChai); @@ -79,8 +79,8 @@ describe('Google AI Mappers', () => { ] }; expect(() => mapGenerateContentRequest(request)) - .to.throw(GenAIError, /SafetySetting.method is not supported/i) - .with.property('code', GenAIErrorCode.UNSUPPORTED); + .to.throw(AIError, /SafetySetting.method is not supported/i) + .with.property('code', AIErrorCode.UNSUPPORTED); }); it('should warn and round topK if present', () => { @@ -334,8 +334,8 @@ describe('Google AI Mappers', () => { } ]; expect(() => mapGenerateContentCandidates(candidates)) - .to.throw(GenAIError, /Part.videoMetadata is not supported/i) - .with.property('code', GenAIErrorCode.UNSUPPORTED); + .to.throw(AIError, /Part.videoMetadata is not supported/i) + .with.property('code', AIErrorCode.UNSUPPORTED); }); it('should handle candidates without citation or safety ratings', () => { diff --git a/packages/vertexai/src/googleAIMappers.ts b/packages/vertexai/src/googleAIMappers.ts index e61a3532be1..af278bef782 100644 --- a/packages/vertexai/src/googleAIMappers.ts +++ b/packages/vertexai/src/googleAIMappers.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { GenAIError } from './errors'; +import { AIError } from './errors'; import { logger } from './logger'; import { CitationMetadata, @@ -27,7 +27,7 @@ import { InlineDataPart, PromptFeedback, SafetyRating, - GenAIErrorCode + AIErrorCode } from './types'; import { GoogleAIGenerateContentResponse, @@ -62,8 +62,8 @@ export function mapGenerateContentRequest( ): GenerateContentRequest { generateContentRequest.safetySettings?.forEach(safetySetting => { if (safetySetting.method) { - throw new GenAIError( - GenAIErrorCode.UNSUPPORTED, + throw new AIError( + AIErrorCode.UNSUPPORTED, 'SafetySetting.method is not supported in the Google AI. Please remove this property.' ); } @@ -185,8 +185,8 @@ export function mapGenerateContentCandidates( part => (part as InlineDataPart)?.videoMetadata ) ) { - throw new GenAIError( - GenAIErrorCode.UNSUPPORTED, + throw new AIError( + AIErrorCode.UNSUPPORTED, 'Part.videoMetadata is not supported in Google AI. Please remove this property.' ); } diff --git a/packages/vertexai/src/helpers.test.ts b/packages/vertexai/src/helpers.test.ts index f7316e3f119..7ed8f6a754a 100644 --- a/packages/vertexai/src/helpers.test.ts +++ b/packages/vertexai/src/helpers.test.ts @@ -15,12 +15,12 @@ * limitations under the License. */ import { expect } from 'chai'; -import { GENAI_TYPE } from './constants'; +import { AI_TYPE } from './constants'; import { encodeInstanceIdentifier, decodeInstanceIdentifier } from './helpers'; -import { GenAIError } from './errors'; +import { AIError } from './errors'; import { BackendType } from './public-types'; import { InstanceIdentifier } from './types/internal'; -import { GenAIErrorCode } from './types'; +import { AIErrorCode } from './types'; describe('Identifier Encoding/Decoding', () => { describe('encodeInstanceIdentifier', () => { @@ -30,7 +30,7 @@ describe('Identifier Encoding/Decoding', () => { location: 'us-central1' }; console.log(identifier); - const expected = `${GENAI_TYPE}/vertexai/us-central1`; + const expected = `${AI_TYPE}/vertexai/us-central1`; expect(encodeInstanceIdentifier(identifier)).to.equal(expected); }); @@ -39,7 +39,7 @@ describe('Identifier Encoding/Decoding', () => { backendType: BackendType.VERTEX_AI, location: '' }; - const expected = `${GENAI_TYPE}/vertexai/`; + const expected = `${AI_TYPE}/vertexai/`; expect(encodeInstanceIdentifier(identifier)).to.equal(expected); }); @@ -47,32 +47,32 @@ describe('Identifier Encoding/Decoding', () => { const identifier: InstanceIdentifier = { backendType: BackendType.GOOGLE_AI }; - const expected = `${GENAI_TYPE}/googleai`; + const expected = `${AI_TYPE}/googleai`; expect(encodeInstanceIdentifier(identifier)).to.equal(expected); }); - it('should throw GenAIError for unknown backend type', () => { + it('should throw AIError for unknown backend type', () => { const identifier = { backendType: 'some-future-backend' } as any; // bypass type checking for the test - expect(() => encodeInstanceIdentifier(identifier)).to.throw(GenAIError); + expect(() => encodeInstanceIdentifier(identifier)).to.throw(AIError); try { encodeInstanceIdentifier(identifier); expect.fail('Expected encodeInstanceIdentifier to throw'); } catch (e) { - expect(e).to.be.instanceOf(GenAIError); - const error = e as GenAIError; + expect(e).to.be.instanceOf(AIError); + const error = e as AIError; expect(error.message).to.contain(`Unknown backend`); - expect(error.code).to.equal(GenAIErrorCode.ERROR); + expect(error.code).to.equal(AIErrorCode.ERROR); } }); }); describe('decodeInstanceIdentifier', () => { it('should decode Vertex AI identifier with location', () => { - const encoded = `${GENAI_TYPE}/vertexai/europe-west1`; + const encoded = `${AI_TYPE}/vertexai/europe-west1`; const expected: InstanceIdentifier = { backendType: BackendType.VERTEX_AI, location: 'europe-west1' @@ -81,58 +81,58 @@ describe('Identifier Encoding/Decoding', () => { }); it('should throw an error if Vertex AI identifier string without explicit location part', () => { - const encoded = `${GENAI_TYPE}/vertexai`; - expect(() => decodeInstanceIdentifier(encoded)).to.throw(GenAIError); + const encoded = `${AI_TYPE}/vertexai`; + expect(() => decodeInstanceIdentifier(encoded)).to.throw(AIError); try { decodeInstanceIdentifier(encoded); expect.fail('Expected encodeInstanceIdentifier to throw'); } catch (e) { - expect(e).to.be.instanceOf(GenAIError); - const error = e as GenAIError; + expect(e).to.be.instanceOf(AIError); + const error = e as AIError; expect(error.message).to.contain( `Invalid instance identifier, unknown location` ); - expect(error.code).to.equal(GenAIErrorCode.ERROR); + expect(error.code).to.equal(AIErrorCode.ERROR); } }); it('should decode Google AI identifier', () => { - const encoded = `${GENAI_TYPE}/googleai`; + const encoded = `${AI_TYPE}/googleai`; const expected: InstanceIdentifier = { backendType: BackendType.GOOGLE_AI }; expect(decodeInstanceIdentifier(encoded)).to.deep.equal(expected); }); - it('should throw GenAIError for invalid backend string', () => { - const encoded = `${GENAI_TYPE}/someotherbackend/location`; + it('should throw AIError for invalid backend string', () => { + const encoded = `${AI_TYPE}/someotherbackend/location`; expect(() => decodeInstanceIdentifier(encoded)).to.throw( - GenAIError, + AIError, `Invalid instance identifier string: '${encoded}'` ); try { decodeInstanceIdentifier(encoded); expect.fail('Expected decodeInstanceIdentifier to throw'); } catch (e) { - expect(e).to.be.instanceOf(GenAIError); - expect((e as GenAIError).code).to.equal(GenAIErrorCode.ERROR); + expect(e).to.be.instanceOf(AIError); + expect((e as AIError).code).to.equal(AIErrorCode.ERROR); } }); - it('should throw GenAIError for malformed identifier string (too few parts)', () => { - const encoded = GENAI_TYPE; + it('should throw AIError for malformed identifier string (too few parts)', () => { + const encoded = AI_TYPE; expect(() => decodeInstanceIdentifier(encoded)).to.throw( - GenAIError, + AIError, `Invalid instance identifier string: '${encoded}'` ); }); - it('should throw GenAIError for malformed identifier string (incorrect prefix)', () => { + it('should throw AIError for malformed identifier string (incorrect prefix)', () => { const encoded = 'firebase/vertexai/location'; // This will also hit the default case in the switch statement expect(() => decodeInstanceIdentifier(encoded)).to.throw( - GenAIError, + AIError, `Invalid instance identifier, unknown prefix 'firebase'` ); }); diff --git a/packages/vertexai/src/helpers.ts b/packages/vertexai/src/helpers.ts index 28f11a4b2bd..764d06fe9f7 100644 --- a/packages/vertexai/src/helpers.ts +++ b/packages/vertexai/src/helpers.ts @@ -15,16 +15,16 @@ * limitations under the License. */ -import { GENAI_TYPE } from './constants'; -import { GenAIError } from './errors'; +import { AI_TYPE } from './constants'; +import { AIError } from './errors'; import { BackendType } from './public-types'; import { InstanceIdentifier } from './types/internal'; -import { GenAIErrorCode } from './types'; +import { AIErrorCode } from './types'; /** * Encodes an {@link InstanceIdentifier} into a string. * - * This string is used to identify unique {@link GenAI} instances by backend type. + * This string is used to identify unique {@link AI} instances by backend type. * * @internal */ @@ -33,12 +33,12 @@ export function encodeInstanceIdentifier( ): string { switch (instanceIdentifier.backendType) { case BackendType.VERTEX_AI: - return `${GENAI_TYPE}/vertexai/${instanceIdentifier.location}`; + return `${AI_TYPE}/vertexai/${instanceIdentifier.location}`; case BackendType.GOOGLE_AI: - return `${GENAI_TYPE}/googleai`; + return `${AI_TYPE}/googleai`; default: - throw new GenAIError( - GenAIErrorCode.ERROR, + throw new AIError( + AIErrorCode.ERROR, `Unknown backend '${instanceIdentifier}'` ); } @@ -53,9 +53,9 @@ export function decodeInstanceIdentifier( instanceIdentifier: string ): InstanceIdentifier { const identifierParts = instanceIdentifier.split('/'); - if (identifierParts[0] !== GENAI_TYPE) { - throw new GenAIError( - GenAIErrorCode.ERROR, + if (identifierParts[0] !== AI_TYPE) { + throw new AIError( + AIErrorCode.ERROR, `Invalid instance identifier, unknown prefix '${identifierParts[0]}'` ); } @@ -64,8 +64,8 @@ export function decodeInstanceIdentifier( case 'vertexai': const location: string | undefined = identifierParts[2]; if (!location) { - throw new GenAIError( - GenAIErrorCode.ERROR, + throw new AIError( + AIErrorCode.ERROR, `Invalid instance identifier, unknown location '${instanceIdentifier}'` ); } @@ -78,8 +78,8 @@ export function decodeInstanceIdentifier( backendType: BackendType.GOOGLE_AI }; default: - throw new GenAIError( - GenAIErrorCode.ERROR, + throw new AIError( + AIErrorCode.ERROR, `Invalid instance identifier string: '${instanceIdentifier}'` ); } diff --git a/packages/vertexai/src/index.node.ts b/packages/vertexai/src/index.node.ts index 414aefdaffb..60ed127c19d 100644 --- a/packages/vertexai/src/index.node.ts +++ b/packages/vertexai/src/index.node.ts @@ -1,5 +1,5 @@ /** - * The Vertex AI in Firebase Web SDK. + * The Firebase AI Web SDK. * * @packageDocumentation */ @@ -22,17 +22,17 @@ */ import { registerVersion, _registerComponent } from '@firebase/app'; -import { GenAIService } from './service'; -import { DEFAULT_INSTANCE_IDENTIFER, GENAI_TYPE } from './constants'; +import { AIService } from './service'; +import { DEFAULT_INSTANCE_IDENTIFIER, AI_TYPE } from './constants'; import { Component, ComponentType } from '@firebase/component'; import { name, version } from '../package.json'; import { InstanceIdentifier } from './types/internal'; import { decodeInstanceIdentifier } from './helpers'; -function registerGenAI(): void { +function registerAI(): void { _registerComponent( new Component( - GENAI_TYPE, + AI_TYPE, (container, options) => { // getImmediate for FirebaseApp will always succeed const app = container.getProvider('app').getImmediate(); @@ -45,12 +45,12 @@ function registerGenAI(): void { options.instanceIdentifier ); } else { - instanceIdentifier = DEFAULT_INSTANCE_IDENTIFER; + instanceIdentifier = DEFAULT_INSTANCE_IDENTIFIER; } const backend = instanceIdentifier; - return new GenAIService(app, backend, auth, appCheckProvider); + return new AIService(app, backend, auth, appCheckProvider); }, ComponentType.PUBLIC ).setMultipleInstances(true) @@ -61,7 +61,7 @@ function registerGenAI(): void { registerVersion(name, version, '__BUILD_TARGET__'); } -registerGenAI(); +registerAI(); export * from './api'; export * from './public-types'; diff --git a/packages/vertexai/src/index.ts b/packages/vertexai/src/index.ts index 985469c5ce1..2f275e9d903 100644 --- a/packages/vertexai/src/index.ts +++ b/packages/vertexai/src/index.ts @@ -1,5 +1,5 @@ /** - * The Vertex AI in Firebase Web SDK. + * The Firebase AI Web SDK. * * @packageDocumentation */ @@ -22,13 +22,13 @@ */ import { registerVersion, _registerComponent } from '@firebase/app'; -import { GenAIService } from './service'; -import { GENAI_TYPE } from './constants'; +import { AIService } from './service'; +import { AI_TYPE } from './constants'; import { Component, ComponentType } from '@firebase/component'; import { name, version } from '../package.json'; import { decodeInstanceIdentifier } from './helpers'; -import { GenAIError } from './api'; -import { GenAIErrorCode } from './types'; +import { AIError } from './api'; +import { AIErrorCode } from './types'; declare global { interface Window { @@ -36,15 +36,15 @@ declare global { } } -function registerGenAI(): void { +function registerAI(): void { _registerComponent( new Component( - GENAI_TYPE, + AI_TYPE, (container, { instanceIdentifier }) => { if (!instanceIdentifier) { - throw new GenAIError( - GenAIErrorCode.ERROR, - 'GenAIService instance identifier is undefined.' + throw new AIError( + AIErrorCode.ERROR, + 'AIService instance identifier is undefined.' ); } @@ -53,7 +53,7 @@ function registerGenAI(): void { const app = container.getProvider('app').getImmediate(); const auth = container.getProvider('auth-internal'); const appCheckProvider = container.getProvider('app-check-internal'); - return new GenAIService(app, backend, auth, appCheckProvider); + return new AIService(app, backend, auth, appCheckProvider); }, ComponentType.PUBLIC ).setMultipleInstances(true) @@ -64,7 +64,7 @@ function registerGenAI(): void { registerVersion(name, version, '__BUILD_TARGET__'); } -registerGenAI(); +registerAI(); export * from './api'; export * from './public-types'; diff --git a/packages/vertexai/src/methods/chat-session-helpers.ts b/packages/vertexai/src/methods/chat-session-helpers.ts index a1a1713f584..ba462386e9b 100644 --- a/packages/vertexai/src/methods/chat-session-helpers.ts +++ b/packages/vertexai/src/methods/chat-session-helpers.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { Content, POSSIBLE_ROLES, Part, Role, GenAIErrorCode } from '../types'; -import { GenAIError } from '../errors'; +import { Content, POSSIBLE_ROLES, Part, Role, AIErrorCode } from '../types'; +import { AIError } from '../errors'; // https://ai.google.dev/api/rest/v1beta/Content#part @@ -48,14 +48,14 @@ export function validateChatHistory(history: Content[]): void { for (const currContent of history) { const { role, parts } = currContent; if (!prevContent && role !== 'user') { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, `First Content should be with role 'user', got ${role}` ); } if (!POSSIBLE_ROLES.includes(role)) { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, `Each item should include role field. Got ${role} but valid roles are: ${JSON.stringify( POSSIBLE_ROLES )}` @@ -63,15 +63,15 @@ export function validateChatHistory(history: Content[]): void { } if (!Array.isArray(parts)) { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, `Content should have 'parts' but property with an array of Parts` ); } if (parts.length === 0) { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, `Each Content should have at least one part` ); } @@ -93,8 +93,8 @@ export function validateChatHistory(history: Content[]): void { const validParts = VALID_PARTS_PER_ROLE[role]; for (const key of VALID_PART_FIELDS) { if (!validParts.includes(key) && countFields[key] > 0) { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, `Content with role '${role}' can't contain '${key}' part` ); } @@ -103,8 +103,8 @@ export function validateChatHistory(history: Content[]): void { if (prevContent) { const validPreviousContentRoles = VALID_PREVIOUS_CONTENT_ROLES[role]; if (!validPreviousContentRoles.includes(prevContent.role)) { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, `Content with role '${role} can't follow '${ prevContent.role }'. Valid previous roles: ${JSON.stringify( diff --git a/packages/vertexai/src/methods/generate-content.test.ts b/packages/vertexai/src/methods/generate-content.test.ts index 181d7d45b84..b5ef144f76f 100644 --- a/packages/vertexai/src/methods/generate-content.test.ts +++ b/packages/vertexai/src/methods/generate-content.test.ts @@ -23,7 +23,7 @@ import { getMockResponse } from '../../test-utils/mock-response'; import * as request from '../requests/request'; import { generateContent } from './generate-content'; import { - GenAIErrorCode, + AIErrorCode, GenerateContentRequest, HarmBlockMethod, HarmBlockThreshold, @@ -31,7 +31,7 @@ import { } from '../types'; import { ApiSettings } from '../types/internal'; import { Task } from '../requests/request'; -import { GenAIError, googleAIBackend, vertexAIBackend } from '../api'; +import { AIError, googleAIBackend, vertexAIBackend } from '../api'; import { mapGenerateContentRequest } from '../googleAIMappers'; use(sinonChai); @@ -341,14 +341,14 @@ describe('generateContent()', () => { ] }; - // Expect generateContent to throw a GenAIError that method is not supported. + // Expect generateContent to throw a AIError that method is not supported. await expect( generateContent( fakeGoogleAIApiSettings, 'model', requestParamsWithMethod ) - ).to.be.rejectedWith(GenAIError, GenAIErrorCode.UNSUPPORTED); + ).to.be.rejectedWith(AIError, AIErrorCode.UNSUPPORTED); expect(makeRequestStub).to.not.be.called; }); it('maps request to GoogleAI format', async () => { diff --git a/packages/vertexai/src/models/genai-model.test.ts b/packages/vertexai/src/models/genai-model.test.ts index 16bd54d9f6f..d8db0bea2ec 100644 --- a/packages/vertexai/src/models/genai-model.test.ts +++ b/packages/vertexai/src/models/genai-model.test.ts @@ -15,25 +15,25 @@ * limitations under the License. */ import { use, expect } from 'chai'; -import { GenAI, GenAIErrorCode } from '../public-types'; +import { AI, AIErrorCode } from '../public-types'; import sinonChai from 'sinon-chai'; -import { GenAIModel } from './genai-model'; -import { GenAIError } from '../errors'; +import { AIModel } from './genai-model'; +import { AIError } from '../errors'; import { vertexAIBackend } from '../api'; use(sinonChai); /** - * A class that extends GenAIModel that allows us to test the protected constructor. + * A class that extends AIModel that allows us to test the protected constructor. */ -class TestModel extends GenAIModel { +class TestModel extends AIModel { /* eslint-disable @typescript-eslint/no-useless-constructor */ - constructor(genAI: GenAI, modelName: string) { - super(genAI, modelName); + constructor(ai: AI, modelName: string) { + super(ai, modelName); } } -const fakeGenAI: GenAI = { +const fakeAI: AI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -47,28 +47,28 @@ const fakeGenAI: GenAI = { location: 'us-central1' }; -describe('GenAIModel', () => { +describe('AIModel', () => { it('handles plain model name', () => { - const testModel = new TestModel(fakeGenAI, 'my-model'); + const testModel = new TestModel(fakeAI, 'my-model'); expect(testModel.model).to.equal('publishers/google/models/my-model'); }); it('handles models/ prefixed model name', () => { - const testModel = new TestModel(fakeGenAI, 'models/my-model'); + const testModel = new TestModel(fakeAI, 'models/my-model'); expect(testModel.model).to.equal('publishers/google/models/my-model'); }); it('handles full model name', () => { const testModel = new TestModel( - fakeGenAI, + fakeAI, 'publishers/google/models/my-model' ); expect(testModel.model).to.equal('publishers/google/models/my-model'); }); it('handles prefixed tuned model name', () => { - const testModel = new TestModel(fakeGenAI, 'tunedModels/my-model'); + const testModel = new TestModel(fakeAI, 'tunedModels/my-model'); expect(testModel.model).to.equal('tunedModels/my-model'); }); it('throws if not passed an api key', () => { - const fakeGenAI: GenAI = { + const fakeAI: AI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -80,13 +80,13 @@ describe('GenAIModel', () => { location: 'us-central1' }; try { - new TestModel(fakeGenAI, 'my-model'); + new TestModel(fakeAI, 'my-model'); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.NO_API_KEY); + expect((e as AIError).code).to.equal(AIErrorCode.NO_API_KEY); } }); it('throws if not passed a project ID', () => { - const fakeGenAI: GenAI = { + const fakeAI: AI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -98,13 +98,13 @@ describe('GenAIModel', () => { location: 'us-central1' }; try { - new TestModel(fakeGenAI, 'my-model'); + new TestModel(fakeAI, 'my-model'); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.NO_PROJECT_ID); + expect((e as AIError).code).to.equal(AIErrorCode.NO_PROJECT_ID); } }); it('throws if not passed an app ID', () => { - const fakeGenAI: GenAI = { + const fakeAI: AI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -117,9 +117,9 @@ describe('GenAIModel', () => { location: 'us-central1' }; try { - new TestModel(fakeGenAI, 'my-model'); + new TestModel(fakeAI, 'my-model'); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.NO_APP_ID); + expect((e as AIError).code).to.equal(AIErrorCode.NO_APP_ID); } }); }); diff --git a/packages/vertexai/src/models/genai-model.ts b/packages/vertexai/src/models/genai-model.ts index 28e67c8552d..dd3b666d555 100644 --- a/packages/vertexai/src/models/genai-model.ts +++ b/packages/vertexai/src/models/genai-model.ts @@ -15,18 +15,18 @@ * limitations under the License. */ -import { GenAIError } from '../errors'; -import { GenAIErrorCode, GenAI, BackendType } from '../public-types'; -import { GenAIService } from '../service'; +import { AIError } from '../errors'; +import { AIErrorCode, AI, BackendType } from '../public-types'; +import { AIService } from '../service'; import { ApiSettings } from '../types/internal'; import { _isFirebaseServerApp } from '@firebase/app'; /** - * Base class for Vertex AI in Firebase model APIs. + * Base class for Firebase AI model APIs. * * @public */ -export abstract class GenAIModel { +export abstract class AIModel { /** * The fully qualified model resource name to use for generating images * (for example, `publishers/google/models/imagen-3.0-generate-002`). @@ -39,12 +39,12 @@ export abstract class GenAIModel { protected _apiSettings: ApiSettings; /** - * Constructs a new instance of the {@link GenAIModel} class. + * Constructs a new instance of the {@link AIModel} class. * * This constructor should only be called from subclasses that provide * a model API. * - * @param genAI - A {@link GenAI} instance. + * @param ai - an {@link AI} instance. * @param modelName - The name of the model being used. It can be in one of the following formats: * - `my-model` (short name, will resolve to `publishers/google/models/my-model`) * - `models/my-model` (will resolve to `publishers/google/models/my-model`) @@ -55,49 +55,49 @@ export abstract class GenAIModel { * * @internal */ - protected constructor(genAI: GenAI, modelName: string) { - if (!genAI.app?.options?.apiKey) { - throw new GenAIError( - GenAIErrorCode.NO_API_KEY, - `The "apiKey" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid API key.` + protected constructor(ai: AI, modelName: string) { + if (!ai.app?.options?.apiKey) { + throw new AIError( + AIErrorCode.NO_API_KEY, + `The "apiKey" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid API key.` ); - } else if (!genAI.app?.options?.projectId) { - throw new GenAIError( - GenAIErrorCode.NO_PROJECT_ID, - `The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.` + } else if (!ai.app?.options?.projectId) { + throw new AIError( + AIErrorCode.NO_PROJECT_ID, + `The "projectId" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid project ID.` ); - } else if (!genAI.app?.options?.appId) { - throw new GenAIError( - GenAIErrorCode.NO_APP_ID, - `The "appId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid app ID.` + } else if (!ai.app?.options?.appId) { + throw new AIError( + AIErrorCode.NO_APP_ID, + `The "appId" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid app ID.` ); } else { this._apiSettings = { - apiKey: genAI.app.options.apiKey, - project: genAI.app.options.projectId, - appId: genAI.app.options.appId, + apiKey: ai.app.options.apiKey, + project: ai.app.options.projectId, + appId: ai.app.options.appId, automaticDataCollectionEnabled: - genAI.app.automaticDataCollectionEnabled, - location: genAI.location, - backend: genAI.backend + ai.app.automaticDataCollectionEnabled, + location: ai.location, + backend: ai.backend }; - if (_isFirebaseServerApp(genAI.app) && genAI.app.settings.appCheckToken) { - const token = genAI.app.settings.appCheckToken; + if (_isFirebaseServerApp(ai.app) && ai.app.settings.appCheckToken) { + const token = ai.app.settings.appCheckToken; this._apiSettings.getAppCheckToken = () => { return Promise.resolve({ token }); }; - } else if ((genAI as GenAIService).appCheck) { + } else if ((ai as AIService).appCheck) { this._apiSettings.getAppCheckToken = () => - (genAI as GenAIService).appCheck!.getToken(); + (ai as AIService).appCheck!.getToken(); } - if ((genAI as GenAIService).auth) { + if ((ai as AIService).auth) { this._apiSettings.getAuthToken = () => - (genAI as GenAIService).auth!.getToken(); + (ai as AIService).auth!.getToken(); } - this.model = GenAIModel.normalizeModelName( + this.model = AIModel.normalizeModelName( modelName, this._apiSettings.backend.backendType ); @@ -117,9 +117,9 @@ export abstract class GenAIModel { backendType: BackendType ): string { if (backendType === BackendType.GOOGLE_AI) { - return GenAIModel.normalizeGoogleAIModelName(modelName); + return AIModel.normalizeGoogleAIModelName(modelName); } else { - return GenAIModel.normalizeVertexAIModelName(modelName); + return AIModel.normalizeVertexAIModelName(modelName); } } diff --git a/packages/vertexai/src/models/generative-model.test.ts b/packages/vertexai/src/models/generative-model.test.ts index a8245fe16ef..7f61070a52a 100644 --- a/packages/vertexai/src/models/generative-model.test.ts +++ b/packages/vertexai/src/models/generative-model.test.ts @@ -16,7 +16,7 @@ */ import { use, expect } from 'chai'; import { GenerativeModel } from './generative-model'; -import { FunctionCallingMode, GenAI } from '../public-types'; +import { FunctionCallingMode, AI } from '../public-types'; import * as request from '../requests/request'; import { match, restore, stub } from 'sinon'; import { getMockResponse } from '../../test-utils/mock-response'; @@ -25,7 +25,7 @@ import { vertexAIBackend } from '../api'; use(sinonChai); -const fakeGenAI: GenAI = { +const fakeAI: AI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -41,7 +41,7 @@ const fakeGenAI: GenAI = { describe('GenerativeModel', () => { it('passes params through to generateContent', async () => { - const genModel = new GenerativeModel(fakeGenAI, { + const genModel = new GenerativeModel(fakeAI, { model: 'my-model', tools: [ { @@ -86,7 +86,7 @@ describe('GenerativeModel', () => { restore(); }); it('passes text-only systemInstruction through to generateContent', async () => { - const genModel = new GenerativeModel(fakeGenAI, { + const genModel = new GenerativeModel(fakeAI, { model: 'my-model', systemInstruction: 'be friendly' }); @@ -112,7 +112,7 @@ describe('GenerativeModel', () => { restore(); }); it('generateContent overrides model values', async () => { - const genModel = new GenerativeModel(fakeGenAI, { + const genModel = new GenerativeModel(fakeAI, { model: 'my-model', tools: [ { @@ -168,7 +168,7 @@ describe('GenerativeModel', () => { restore(); }); it('passes params through to chat.sendMessage', async () => { - const genModel = new GenerativeModel(fakeGenAI, { + const genModel = new GenerativeModel(fakeAI, { model: 'my-model', tools: [ { functionDeclarations: [{ name: 'myfunc', description: 'mydesc' }] } @@ -206,7 +206,7 @@ describe('GenerativeModel', () => { restore(); }); it('passes text-only systemInstruction through to chat.sendMessage', async () => { - const genModel = new GenerativeModel(fakeGenAI, { + const genModel = new GenerativeModel(fakeAI, { model: 'my-model', systemInstruction: 'be friendly' }); @@ -232,7 +232,7 @@ describe('GenerativeModel', () => { restore(); }); it('startChat overrides model values', async () => { - const genModel = new GenerativeModel(fakeGenAI, { + const genModel = new GenerativeModel(fakeAI, { model: 'my-model', tools: [ { functionDeclarations: [{ name: 'myfunc', description: 'mydesc' }] } @@ -284,7 +284,7 @@ describe('GenerativeModel', () => { restore(); }); it('calls countTokens', async () => { - const genModel = new GenerativeModel(fakeGenAI, { model: 'my-model' }); + const genModel = new GenerativeModel(fakeAI, { model: 'my-model' }); const mockResponse = getMockResponse( 'vertexAI', 'unary-success-total-tokens.json' diff --git a/packages/vertexai/src/models/generative-model.ts b/packages/vertexai/src/models/generative-model.ts index 37880a794b7..2e7ed93eeb8 100644 --- a/packages/vertexai/src/models/generative-model.ts +++ b/packages/vertexai/src/models/generative-model.ts @@ -41,14 +41,14 @@ import { formatGenerateContentInput, formatSystemInstruction } from '../requests/request-helpers'; -import { GenAI } from '../public-types'; -import { GenAIModel } from './genai-model'; +import { AI } from '../public-types'; +import { AIModel } from './genai-model'; /** * Class for generative model APIs. * @public */ -export class GenerativeModel extends GenAIModel { +export class GenerativeModel extends AIModel { generationConfig: GenerationConfig; safetySettings: SafetySetting[]; requestOptions?: RequestOptions; @@ -57,11 +57,11 @@ export class GenerativeModel extends GenAIModel { systemInstruction?: Content; constructor( - genAI: GenAI, + ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions ) { - super(genAI, modelParams.model); + super(ai, modelParams.model); this.generationConfig = modelParams.generationConfig || {}; this.safetySettings = modelParams.safetySettings || []; this.tools = modelParams.tools; diff --git a/packages/vertexai/src/models/imagen-model.test.ts b/packages/vertexai/src/models/imagen-model.test.ts index e2a426a2416..f7a945d212d 100644 --- a/packages/vertexai/src/models/imagen-model.test.ts +++ b/packages/vertexai/src/models/imagen-model.test.ts @@ -20,19 +20,19 @@ import { ImagenAspectRatio, ImagenPersonFilterLevel, ImagenSafetyFilterLevel, - GenAI, - GenAIErrorCode + AI, + AIErrorCode } from '../public-types'; import * as request from '../requests/request'; import sinonChai from 'sinon-chai'; -import { GenAIError } from '../errors'; +import { AIError } from '../errors'; import { getMockResponse } from '../../test-utils/mock-response'; import { match, restore, stub } from 'sinon'; import { vertexAIBackend } from '../api'; use(sinonChai); -const fakeGenAI: GenAI = { +const fakeAI: AI = { app: { name: 'DEFAULT', automaticDataCollectionEnabled: true, @@ -56,7 +56,7 @@ describe('ImagenModel', () => { mockResponse as Response ); - const imagenModel = new ImagenModel(fakeGenAI, { + const imagenModel = new ImagenModel(fakeAI, { model: 'my-model' }); const prompt = 'A photorealistic image of a toy boat at sea.'; @@ -77,7 +77,7 @@ describe('ImagenModel', () => { restore(); }); it('generateImages makes a request to predict with generation config and safety settings', async () => { - const imagenModel = new ImagenModel(fakeGenAI, { + const imagenModel = new ImagenModel(fakeAI, { model: 'my-model', generationConfig: { negativePrompt: 'do not hallucinate', @@ -148,15 +148,15 @@ describe('ImagenModel', () => { json: mockResponse.json } as Response); - const imagenModel = new ImagenModel(fakeGenAI, { + const imagenModel = new ImagenModel(fakeAI, { model: 'my-model' }); try { await imagenModel.generateImages('some inappropriate prompt.'); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); - expect((e as GenAIError).message).to.include('400'); - expect((e as GenAIError).message).to.include( + expect((e as AIError).code).to.equal(AIErrorCode.FETCH_ERROR); + expect((e as AIError).message).to.include('400'); + expect((e as AIError).message).to.include( "Image generation failed with the following error: The prompt could not be submitted. This prompt contains sensitive words that violate Google's Responsible AI practices. Try rephrasing the prompt. If you think this was an error, send feedback." ); } finally { diff --git a/packages/vertexai/src/models/imagen-model.ts b/packages/vertexai/src/models/imagen-model.ts index 9a36b3f6954..070b1d064ec 100644 --- a/packages/vertexai/src/models/imagen-model.ts +++ b/packages/vertexai/src/models/imagen-model.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { GenAI } from '../public-types'; +import { AI } from '../public-types'; import { Task, makeRequest } from '../requests/request'; import { createPredictRequestBody } from '../requests/request-helpers'; import { handlePredictResponse } from '../requests/response-helpers'; @@ -28,7 +28,7 @@ import { ImagenGenerationResponse, ImagenSafetySettings } from '../types'; -import { GenAIModel } from './genai-model'; +import { AIModel } from './genai-model'; /** * Class for Imagen model APIs. @@ -38,7 +38,7 @@ import { GenAIModel } from './genai-model'; * @example * ```javascript * const imagen = new ImagenModel( - * genAI, + * ai, * { * model: 'imagen-3.0-generate-002' * } @@ -52,7 +52,7 @@ import { GenAIModel } from './genai-model'; * * @beta */ -export class ImagenModel extends GenAIModel { +export class ImagenModel extends AIModel { /** * The Imagen generation configuration. */ @@ -65,7 +65,7 @@ export class ImagenModel extends GenAIModel { /** * Constructs a new instance of the {@link ImagenModel} class. * - * @param genAI - A {@link GenAI} instance. + * @param ai - an {@link AI} instance. * @param modelParams - Parameters to use when making requests to Imagen. * @param requestOptions - Additional options to use when making requests. * @@ -73,12 +73,12 @@ export class ImagenModel extends GenAIModel { * Firebase config. */ constructor( - genAI: GenAI, + ai: AI, modelParams: ImagenModelParams, public requestOptions?: RequestOptions ) { const { model, generationConfig, safetySettings } = modelParams; - super(genAI, model); + super(ai, model); this.generationConfig = generationConfig; this.safetySettings = safetySettings; } diff --git a/packages/vertexai/src/public-types.ts b/packages/vertexai/src/public-types.ts index 4dd7b3a53ba..3a9e62a5fa5 100644 --- a/packages/vertexai/src/public-types.ts +++ b/packages/vertexai/src/public-types.ts @@ -20,16 +20,16 @@ import { FirebaseApp } from '@firebase/app'; export * from './types'; /** - * An instance of the Vertex AI in Firebase SDK. + * An instance of the Firebase AI SDK. * - * For more information, refer to the documentation for the new {@link GenAI}. + * For more information, refer to the documentation for the new {@link AI}. * * @public */ -export type VertexAI = GenAI; +export type VertexAI = AI; /** - * Options when initializing the Vertex AI in Firebase SDK. + * Options when initializing the Firebase AI SDK. * * @public */ @@ -38,15 +38,15 @@ export interface VertexAIOptions { } /** - * An instance of the Firebase GenAI SDK. + * An instance of the Firebase AI SDK. * - * Do not create this instance directly. Instead, use {@link getGenAI | getGenAI()}. + * Do not create this instance directly. Instead, use {@link getAI | getAI()}. * * @public */ -export interface GenAI { +export interface AI { /** - * The {@link @firebase/app#FirebaseApp} this {@link GenAI} instance is associated with. + * The {@link @firebase/app#FirebaseApp} this {@link AI} instance is associated with. */ app: FirebaseApp; /** @@ -54,15 +54,15 @@ export interface GenAI { */ backend: Backend; /** - * The location configured for this GenAI service instance, relevant for Vertex AI backends. + * The location configured for this AI service instance, relevant for Vertex AI backends. * - * @deprecated use `GenAI.backend.location` instead. + * @deprecated use `AI.backend.location` instead. */ location: string; } /** - * Union type representing the backend configuration for the GenAI service. + * Union type representing the backend configuration for the AI service. * This can be either a {@link GoogleAIBackend} or a * {@link VertexAIBackend} configuration object. * @@ -75,8 +75,8 @@ export type Backend = GoogleAIBackend | VertexAIBackend; /** * Represents the configuration object for the Google AI backend. - * Use this with {@link GenAIOptions} when initializing the service with - * {@link getGenAI | getGenAI()}. + * Use this with {@link AIOptions} when initializing the service with + * {@link getAI | getAI()}. * Create an instance using {@link googleAIBackend | googleAIBackend()}. * * @public @@ -90,8 +90,8 @@ export type GoogleAIBackend = { /** * Represents the configuration object for the Vertex AI backend. - * Use this with {@link GenAIOptions} when initializing the server with - * {@link getGenAI | getGenAI() }. + * Use this with {@link AIOptions} when initializing the server with + * {@link getAI | getAI() }. * Create an instance using {@link vertexAIBackend | vertexAIBackend() } function. * * @public @@ -110,7 +110,7 @@ export type VertexAIBackend = { /** * An enum-like object containing constants that represent the supported backends - * for the Firebase GenAI SDK. + * for the Firebase AI SDK. * * These values are assigned to the `backendType` property within the specific backend * configuration objects ({@link GoogleAIBackend} or {@link VertexAIBackend}) to identify @@ -142,13 +142,13 @@ export const BackendType = { export type BackendType = (typeof BackendType)[keyof typeof BackendType]; /** - * Options interface for initializing the GenAI service using {@link getGenAI | getGenAI()}. + * Options interface for initializing the AI service using {@link getAI | getAI()}. * * @public */ -export interface GenAIOptions { +export interface AIOptions { /** - * The backend configuration to use for the GenAI service instance. + * The backend configuration to use for the AI service instance. * Use {@link googleAIBackend | googleAIBackend()} or * {@link vertexAIBackend | vertexAIBackend() } to create this configuration. */ diff --git a/packages/vertexai/src/requests/request-helpers.ts b/packages/vertexai/src/requests/request-helpers.ts index 411e61c991b..c4dd514f8a8 100644 --- a/packages/vertexai/src/requests/request-helpers.ts +++ b/packages/vertexai/src/requests/request-helpers.ts @@ -19,9 +19,9 @@ import { Content, GenerateContentRequest, Part, - GenAIErrorCode + AIErrorCode } from '../types'; -import { GenAIError } from '../errors'; +import { AIError } from '../errors'; import { ImagenGenerationParams, PredictRequestBody } from '../types/internal'; export function formatSystemInstruction( @@ -87,15 +87,15 @@ function assignRoleToPartsAndValidateSendMessageRequest( } if (hasUserContent && hasFunctionContent) { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, 'Within a single message, FunctionResponse cannot be mixed with other type of Part in the request for sending chat message.' ); } if (!hasUserContent && !hasFunctionContent) { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, 'No Content is provided for sending chat message.' ); } diff --git a/packages/vertexai/src/requests/request.test.ts b/packages/vertexai/src/requests/request.test.ts index 62c0a230944..2efe72bdc60 100644 --- a/packages/vertexai/src/requests/request.test.ts +++ b/packages/vertexai/src/requests/request.test.ts @@ -22,8 +22,8 @@ import chaiAsPromised from 'chai-as-promised'; import { RequestUrl, Task, getHeaders, makeRequest } from './request'; import { ApiSettings } from '../types/internal'; import { DEFAULT_API_VERSION } from '../constants'; -import { GenAIErrorCode } from '../types'; -import { GenAIError } from '../errors'; +import { AIErrorCode } from '../types'; +import { AIError } from '../errors'; import { getMockResponse } from '../../test-utils/mock-response'; import { vertexAIBackend } from '../api'; @@ -310,12 +310,12 @@ describe('request methods', () => { } ); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); - expect((e as GenAIError).customErrorData?.status).to.equal(500); - expect((e as GenAIError).customErrorData?.statusText).to.equal( + expect((e as AIError).code).to.equal(AIErrorCode.FETCH_ERROR); + expect((e as AIError).customErrorData?.status).to.equal(500); + expect((e as AIError).customErrorData?.statusText).to.equal( 'AbortError' ); - expect((e as GenAIError).message).to.include('500 AbortError'); + expect((e as AIError).message).to.include('500 AbortError'); } expect(fetchStub).to.be.calledOnce; @@ -335,12 +335,12 @@ describe('request methods', () => { '' ); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); - expect((e as GenAIError).customErrorData?.status).to.equal(500); - expect((e as GenAIError).customErrorData?.statusText).to.equal( + expect((e as AIError).code).to.equal(AIErrorCode.FETCH_ERROR); + expect((e as AIError).customErrorData?.status).to.equal(500); + expect((e as AIError).customErrorData?.statusText).to.equal( 'Server Error' ); - expect((e as GenAIError).message).to.include('500 Server Error'); + expect((e as AIError).message).to.include('500 Server Error'); } expect(fetchStub).to.be.calledOnce; }); @@ -360,13 +360,13 @@ describe('request methods', () => { '' ); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); - expect((e as GenAIError).customErrorData?.status).to.equal(500); - expect((e as GenAIError).customErrorData?.statusText).to.equal( + expect((e as AIError).code).to.equal(AIErrorCode.FETCH_ERROR); + expect((e as AIError).customErrorData?.status).to.equal(500); + expect((e as AIError).customErrorData?.statusText).to.equal( 'Server Error' ); - expect((e as GenAIError).message).to.include('500 Server Error'); - expect((e as GenAIError).message).to.include('extra info'); + expect((e as AIError).message).to.include('500 Server Error'); + expect((e as AIError).message).to.include('extra info'); } expect(fetchStub).to.be.calledOnce; }); @@ -398,14 +398,14 @@ describe('request methods', () => { '' ); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.FETCH_ERROR); - expect((e as GenAIError).customErrorData?.status).to.equal(500); - expect((e as GenAIError).customErrorData?.statusText).to.equal( + expect((e as AIError).code).to.equal(AIErrorCode.FETCH_ERROR); + expect((e as AIError).customErrorData?.status).to.equal(500); + expect((e as AIError).customErrorData?.statusText).to.equal( 'Server Error' ); - expect((e as GenAIError).message).to.include('500 Server Error'); - expect((e as GenAIError).message).to.include('extra info'); - expect((e as GenAIError).message).to.include( + expect((e as AIError).message).to.include('500 Server Error'); + expect((e as AIError).message).to.include('extra info'); + expect((e as AIError).message).to.include( 'generic::invalid_argument' ); } @@ -429,9 +429,9 @@ describe('request methods', () => { '' ); } catch (e) { - expect((e as GenAIError).code).to.equal(GenAIErrorCode.API_NOT_ENABLED); - expect((e as GenAIError).message).to.include('my-project'); - expect((e as GenAIError).message).to.include('googleapis.com'); + expect((e as AIError).code).to.equal(AIErrorCode.API_NOT_ENABLED); + expect((e as AIError).message).to.include('my-project'); + expect((e as AIError).message).to.include('googleapis.com'); } expect(fetchStub).to.be.calledOnce; }); diff --git a/packages/vertexai/src/requests/request.ts b/packages/vertexai/src/requests/request.ts index 64e299fc422..7b75d46a899 100644 --- a/packages/vertexai/src/requests/request.ts +++ b/packages/vertexai/src/requests/request.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { ErrorDetails, RequestOptions, GenAIErrorCode } from '../types'; -import { GenAIError } from '../errors'; +import { ErrorDetails, RequestOptions, AIErrorCode } from '../types'; +import { AIError } from '../errors'; import { ApiSettings } from '../types/internal'; import { DEFAULT_API_VERSION, @@ -191,9 +191,9 @@ export async function makeRequest( ) ) ) { - throw new GenAIError( - GenAIErrorCode.API_NOT_ENABLED, - `The Vertex AI in Firebase SDK requires the Vertex AI in Firebase ` + + throw new AIError( + AIErrorCode.API_NOT_ENABLED, + `The Firebase AI SDK requires the Firebase AI ` + `API ('firebasevertexai.googleapis.com') to be enabled in your ` + `Firebase project. Enable this API by visiting the Firebase Console ` + `at https://console.firebase.google.com/project/${url.apiSettings.project}/genai/ ` + @@ -207,8 +207,8 @@ export async function makeRequest( } ); } - throw new GenAIError( - GenAIErrorCode.FETCH_ERROR, + throw new AIError( + AIErrorCode.FETCH_ERROR, `Error fetching from ${url}: [${response.status} ${response.statusText}] ${message}`, { status: response.status, @@ -220,12 +220,12 @@ export async function makeRequest( } catch (e) { let err = e as Error; if ( - (e as GenAIError).code !== GenAIErrorCode.FETCH_ERROR && - (e as GenAIError).code !== GenAIErrorCode.API_NOT_ENABLED && + (e as AIError).code !== AIErrorCode.FETCH_ERROR && + (e as AIError).code !== AIErrorCode.API_NOT_ENABLED && e instanceof Error ) { - err = new GenAIError( - GenAIErrorCode.ERROR, + err = new AIError( + AIErrorCode.ERROR, `Error fetching from ${url.toString()}: ${e.message}` ); err.stack = e.stack; diff --git a/packages/vertexai/src/requests/response-helpers.ts b/packages/vertexai/src/requests/response-helpers.ts index db79abaf937..6a23ecb7f05 100644 --- a/packages/vertexai/src/requests/response-helpers.ts +++ b/packages/vertexai/src/requests/response-helpers.ts @@ -23,9 +23,9 @@ import { GenerateContentResponse, ImagenGCSImage, ImagenInlineImage, - GenAIErrorCode + AIErrorCode } from '../types'; -import { GenAIError } from '../errors'; +import { AIError } from '../errors'; import { logger } from '../logger'; import { ImagenResponseInternal } from '../types/internal'; @@ -67,8 +67,8 @@ export function addHelpers( ); } if (hadBadFinishReason(response.candidates[0])) { - throw new GenAIError( - GenAIErrorCode.RESPONSE_ERROR, + throw new AIError( + AIErrorCode.RESPONSE_ERROR, `Response error: ${formatBlockErrorMessage( response )}. Response body stored in error.response`, @@ -79,8 +79,8 @@ export function addHelpers( } return getText(response); } else if (response.promptFeedback) { - throw new GenAIError( - GenAIErrorCode.RESPONSE_ERROR, + throw new AIError( + AIErrorCode.RESPONSE_ERROR, `Text not available. ${formatBlockErrorMessage(response)}`, { response @@ -99,8 +99,8 @@ export function addHelpers( ); } if (hadBadFinishReason(response.candidates[0])) { - throw new GenAIError( - GenAIErrorCode.RESPONSE_ERROR, + throw new AIError( + AIErrorCode.RESPONSE_ERROR, `Response error: ${formatBlockErrorMessage( response )}. Response body stored in error.response`, @@ -111,8 +111,8 @@ export function addHelpers( } return getFunctionCalls(response); } else if (response.promptFeedback) { - throw new GenAIError( - GenAIErrorCode.RESPONSE_ERROR, + throw new AIError( + AIErrorCode.RESPONSE_ERROR, `Function call not available. ${formatBlockErrorMessage(response)}`, { response @@ -217,8 +217,8 @@ export async function handlePredictResponse< // The backend should always send a non-empty array of predictions if the response was successful. if (!responseJson.predictions || responseJson.predictions?.length === 0) { - throw new GenAIError( - GenAIErrorCode.RESPONSE_ERROR, + throw new AIError( + AIErrorCode.RESPONSE_ERROR, 'No predictions or filtered reason received from Vertex AI. Please report this issue with the full error details at https://github.com/firebase/firebase-js-sdk/issues.' ); } @@ -237,8 +237,8 @@ export async function handlePredictResponse< gcsURI: prediction.gcsUri } as T); } else { - throw new GenAIError( - GenAIErrorCode.RESPONSE_ERROR, + throw new AIError( + AIErrorCode.RESPONSE_ERROR, `Predictions array in response has missing properties. Response: ${JSON.stringify( responseJson )}` diff --git a/packages/vertexai/src/requests/schema-builder.test.ts b/packages/vertexai/src/requests/schema-builder.test.ts index 8cef35ade8d..d05b81381ea 100644 --- a/packages/vertexai/src/requests/schema-builder.test.ts +++ b/packages/vertexai/src/requests/schema-builder.test.ts @@ -18,7 +18,7 @@ import { expect, use } from 'chai'; import sinonChai from 'sinon-chai'; import { Schema } from './schema-builder'; -import { GenAIErrorCode } from '../types'; +import { AIErrorCode } from '../types'; use(sinonChai); @@ -243,7 +243,7 @@ describe('Schema builder', () => { }, optionalProperties: ['cat'] }); - expect(() => schema.toJSON()).to.throw(GenAIErrorCode.INVALID_SCHEMA); + expect(() => schema.toJSON()).to.throw(AIErrorCode.INVALID_SCHEMA); }); }); diff --git a/packages/vertexai/src/requests/schema-builder.ts b/packages/vertexai/src/requests/schema-builder.ts index a729b0a6ebf..524cfdb1c20 100644 --- a/packages/vertexai/src/requests/schema-builder.ts +++ b/packages/vertexai/src/requests/schema-builder.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { GenAIError } from '../errors'; -import { GenAIErrorCode } from '../types'; +import { AIError } from '../errors'; +import { AIErrorCode } from '../types'; import { SchemaInterface, SchemaType, @@ -266,8 +266,8 @@ export class ObjectSchema extends Schema { if (this.optionalProperties) { for (const propertyKey of this.optionalProperties) { if (!this.properties.hasOwnProperty(propertyKey)) { - throw new GenAIError( - GenAIErrorCode.INVALID_SCHEMA, + throw new AIError( + AIErrorCode.INVALID_SCHEMA, `Property "${propertyKey}" specified in "optionalProperties" does not exist.` ); } diff --git a/packages/vertexai/src/requests/stream-reader.test.ts b/packages/vertexai/src/requests/stream-reader.test.ts index 2e7041f064a..710372cef40 100644 --- a/packages/vertexai/src/requests/stream-reader.test.ts +++ b/packages/vertexai/src/requests/stream-reader.test.ts @@ -34,9 +34,9 @@ import { HarmCategory, HarmProbability, SafetyRating, - GenAIErrorCode + AIErrorCode } from '../types'; -import { GenAIError } from '../errors'; +import { AIError } from '../errors'; import { ApiSettings } from '../types/internal'; import { vertexAIBackend } from '../api'; @@ -482,8 +482,8 @@ describe('aggregateResponses', () => { try { aggregateResponses(responsesToAggregate); } catch (e) { - expect((e as GenAIError).code).includes(GenAIErrorCode.INVALID_CONTENT); - expect((e as GenAIError).message).to.include( + expect((e as AIError).code).includes(AIErrorCode.INVALID_CONTENT); + expect((e as AIError).message).to.include( 'Part should have at least one property, but there are none. This is likely caused ' + 'by a malformed response from the backend.' ); diff --git a/packages/vertexai/src/requests/stream-reader.ts b/packages/vertexai/src/requests/stream-reader.ts index db1f99d7b27..23cc52299f3 100644 --- a/packages/vertexai/src/requests/stream-reader.ts +++ b/packages/vertexai/src/requests/stream-reader.ts @@ -21,9 +21,9 @@ import { GenerateContentResponse, GenerateContentStreamResult, Part, - GenAIErrorCode + AIErrorCode } from '../types'; -import { GenAIError } from '../errors'; +import { AIError } from '../errors'; import { createEnhancedContentResponse } from './response-helpers'; import * as GoogleAIMapper from '../googleAIMappers'; import { GoogleAIGenerateContentResponse } from '../types/googleAI'; @@ -122,8 +122,8 @@ export function getResponseStream( if (done) { if (currentText.trim()) { controller.error( - new GenAIError( - GenAIErrorCode.PARSE_FAILED, + new AIError( + AIErrorCode.PARSE_FAILED, 'Failed to parse stream' ) ); @@ -141,8 +141,8 @@ export function getResponseStream( parsedResponse = JSON.parse(match[1]); } catch (e) { controller.error( - new GenAIError( - GenAIErrorCode.PARSE_FAILED, + new AIError( + AIErrorCode.PARSE_FAILED, `Error parsing JSON response: "${match[1]}` ) ); @@ -220,8 +220,8 @@ export function aggregateResponses( newPart.functionCall = part.functionCall; } if (Object.keys(newPart).length === 0) { - throw new GenAIError( - GenAIErrorCode.INVALID_CONTENT, + throw new AIError( + AIErrorCode.INVALID_CONTENT, 'Part should have at least one property, but there are none. This is likely caused ' + 'by a malformed response from the backend.' ); diff --git a/packages/vertexai/src/service.test.ts b/packages/vertexai/src/service.test.ts index e76037971e5..11c78fbf15e 100644 --- a/packages/vertexai/src/service.test.ts +++ b/packages/vertexai/src/service.test.ts @@ -16,7 +16,7 @@ */ import { vertexAIBackend } from './api'; import { DEFAULT_LOCATION } from './constants'; -import { GenAIService } from './service'; +import { AIService } from './service'; import { expect } from 'chai'; const fakeApp = { @@ -28,19 +28,19 @@ const fakeApp = { } }; -describe('GenAIService', () => { +describe('AIService', () => { // TODO (dlarocque): move some of these tests to helpers.test.ts it('uses default location if not specified', () => { - const genAI = new GenAIService(fakeApp, vertexAIBackend()); - expect(genAI.location).to.equal(DEFAULT_LOCATION); + const ai = new AIService(fakeApp, vertexAIBackend()); + expect(ai.location).to.equal(DEFAULT_LOCATION); }); it('uses custom location if specified', () => { - const genAI = new GenAIService( + const ai = new AIService( fakeApp, vertexAIBackend('somewhere'), /* authProvider */ undefined, /* appCheckProvider */ undefined ); - expect(genAI.location).to.equal('somewhere'); + expect(ai.location).to.equal('somewhere'); }); }); diff --git a/packages/vertexai/src/service.ts b/packages/vertexai/src/service.ts index d793ef5acfc..a608de384b5 100644 --- a/packages/vertexai/src/service.ts +++ b/packages/vertexai/src/service.ts @@ -16,7 +16,7 @@ */ import { FirebaseApp, _FirebaseService } from '@firebase/app'; -import { Backend, GenAI } from './public-types'; +import { Backend, AI } from './public-types'; import { AppCheckInternalComponentName, FirebaseAppCheckInternal @@ -27,7 +27,7 @@ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types'; -export class GenAIService implements GenAI, _FirebaseService { +export class AIService implements AI, _FirebaseService { auth: FirebaseAuthInternal | null; appCheck: FirebaseAppCheckInternal | null; location: string; // This is here for backwards-compatibility diff --git a/packages/vertexai/src/types/error.ts b/packages/vertexai/src/types/error.ts index c29bbe95284..ef3ad7fc30c 100644 --- a/packages/vertexai/src/types/error.ts +++ b/packages/vertexai/src/types/error.ts @@ -58,11 +58,11 @@ export interface CustomErrorData { } /** - * Standardized error codes that {@link GenAIError} can have. + * Standardized error codes that {@link AIError} can have. * * @public */ -export const enum GenAIErrorCode { +export const enum AIErrorCode { /** A generic error occurred. */ ERROR = 'error', diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index f18a0ae0c48..33ed804bb9f 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -65,7 +65,7 @@ export interface SafetySetting { threshold: HarmBlockThreshold; /** * This property is not supported in Google AI. - * If this is a property on a {@link GenerateContentRequest} to be sent, a {@link GenAIError} + * If this is a property on a {@link GenerateContentRequest} to be sent, an {@link AIError} * will be thrown. */ method?: HarmBlockMethod; From 5a78b76f9ee9bc45fd9d74f46416d144b3effc2e Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 22 Apr 2025 13:41:15 -0400 Subject: [PATCH 03/32] Convert backend types to classes --- common/api-review/vertexai.api.md | 21 +----- config/.eslintrc.js | 3 +- packages/vertexai/src/api.test.ts | 38 ++-------- packages/vertexai/src/api.ts | 62 ++++++---------- packages/vertexai/src/backend.test.ts | 35 +++++++++ packages/vertexai/src/backend.ts | 72 +++++++++++++++++++ .../src/backwards-compatbility.test.ts | 6 +- packages/vertexai/src/errors.ts | 2 +- .../vertexai/src/methods/chat-session.test.ts | 4 +- .../vertexai/src/methods/count-tokens.test.ts | 8 +-- .../src/methods/generate-content.test.ts | 7 +- .../vertexai/src/models/genai-model.test.ts | 10 +-- packages/vertexai/src/models/genai-model.ts | 3 +- .../src/models/generative-model.test.ts | 4 +- .../vertexai/src/models/imagen-model.test.ts | 4 +- packages/vertexai/src/public-types.ts | 50 +------------ .../vertexai/src/requests/request-helpers.ts | 7 +- .../vertexai/src/requests/request.test.ts | 20 +++--- packages/vertexai/src/requests/request.ts | 11 ++- .../src/requests/stream-reader.test.ts | 4 +- .../vertexai/src/requests/stream-reader.ts | 5 +- packages/vertexai/src/service.test.ts | 6 +- packages/vertexai/src/service.ts | 5 +- packages/vertexai/src/types/internal.ts | 8 ++- scripts/update_vertexai_responses.sh | 2 +- 25 files changed, 194 insertions(+), 203 deletions(-) create mode 100644 packages/vertexai/src/backend.test.ts create mode 100644 packages/vertexai/src/backend.ts diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index cc1a0c3269c..3f6fa31992f 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -12,6 +12,7 @@ import { FirebaseError } from '@firebase/util'; // @public export interface AI { app: FirebaseApp; + // Warning: (ae-forgotten-export) The symbol "Backend" needs to be exported by the entry point index.d.ts backend: Backend; // @deprecated location: string; @@ -74,9 +75,6 @@ export class ArraySchema extends Schema { toJSON(): SchemaRequest; } -// @public -export type Backend = GoogleAIBackend | VertexAIBackend; - // @public export const BackendType: { readonly VERTEX_AI: "VERTEX_AI"; @@ -422,14 +420,6 @@ export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOp // @public export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; -// @public -export type GoogleAIBackend = { - backendType: typeof BackendType.GOOGLE_AI; -}; - -// @public -export function googleAIBackend(): GoogleAIBackend; - // @public @deprecated (undocumented) export interface GroundingAttribution { // (undocumented) @@ -859,15 +849,6 @@ export interface UsageMetadata { // @public export type VertexAI = AI; -// @public -export type VertexAIBackend = { - backendType: typeof BackendType.VERTEX_AI; - location: string; -}; - -// @public -export function vertexAIBackend(location?: string): VertexAIBackend; - // @public export const VertexAIError: typeof AIError; diff --git a/config/.eslintrc.js b/config/.eslintrc.js index 57243a3e2a4..aee4a839aaf 100644 --- a/config/.eslintrc.js +++ b/config/.eslintrc.js @@ -174,7 +174,8 @@ module.exports = { } } ], - '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], + // We prefer using interfaces, but we need to use types for aliases like ' + // '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], '@typescript-eslint/explicit-member-accessibility': [ 'error', { diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index bf85c557b1e..0554ff46441 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -16,17 +16,11 @@ */ import { ImagenModelParams, ModelParams, AIErrorCode } from './types'; import { AIError } from './errors'; -import { - ImagenModel, - getGenerativeModel, - getImagenModel, - googleAIBackend, - vertexAIBackend -} from './api'; +import { ImagenModel, getGenerativeModel, getImagenModel } from './api'; import { expect } from 'chai'; -import { BackendType, AI } from './public-types'; +import { AI } from './public-types'; import { GenerativeModel } from './models/generative-model'; -import { DEFAULT_LOCATION } from './constants'; +import { VertexAIBackend } from './backend'; const fakeAI: AI = { app: { @@ -38,7 +32,7 @@ const fakeAI: AI = { appId: 'my-appid' } }, - backend: vertexAIBackend('us-central1'), + backend: new VertexAIBackend('us-central1'), location: 'us-central1' }; @@ -171,28 +165,4 @@ describe('Top level API', () => { expect(genModel).to.be.an.instanceOf(ImagenModel); expect(genModel.model).to.equal('publishers/google/models/my-model'); }); - it('googleAIBackend returns a backend with backendType GOOGLE_AI', () => { - const backend = googleAIBackend(); - expect(backend.backendType).to.equal(BackendType.GOOGLE_AI); - }); - it('vertexAIBackend returns a backend with backendType VERTEX_AI', () => { - const backend = vertexAIBackend(); - expect(backend.backendType).to.equal(BackendType.VERTEX_AI); - expect(backend.location).to.equal(DEFAULT_LOCATION); - }); - it('vertexAIBackend sets custom location', () => { - const backend = vertexAIBackend('test-location'); - expect(backend.backendType).to.equal(BackendType.VERTEX_AI); - expect(backend.location).to.equal('test-location'); - }); - it('vertexAIBackend sets custom location even if empty string', () => { - const backend = vertexAIBackend(''); - expect(backend.backendType).to.equal(BackendType.VERTEX_AI); - expect(backend.location).to.equal(''); - }); - it('vertexAIBackend uses default location if location is null', () => { - const backend = vertexAIBackend(null as any); - expect(backend.backendType).to.equal(BackendType.VERTEX_AI); - expect(backend.location).to.equal(DEFAULT_LOCATION); - }); }); diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index d5e641a582c..b1eff5c7378 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -24,9 +24,7 @@ import { BackendType, AI, AIOptions, - GoogleAIBackend, VertexAI, - VertexAIBackend, VertexAIOptions } from './public-types'; import { @@ -38,6 +36,7 @@ import { import { AIError } from './errors'; import { AIModel, GenerativeModel, ImagenModel } from './models'; import { encodeInstanceIdentifier } from './helpers'; +import { GoogleAIBackend, VertexAIBackend } from './backend'; export { ChatSession } from './methods/chat-session'; export * from './requests/schema-builder'; @@ -72,7 +71,7 @@ declare module '@firebase/component' { /** * It is recommended to use the new {@link getAI | getAI()}. - * + * * Returns a {@link VertexAI} instance for the given app. * * @public @@ -109,13 +108,13 @@ export function getVertexAI( * @example * ```javascript * // Get an AI instance configured to use Google AI. - * const ai = getAI(app, { backend: googleAIBackend() }); + * const ai = getAI(app, { backend: new GoogleAIBackend() }); * ``` * * @example * ```javascript * // Get an AI instance configured to use Vertex AI. - * const ai = getAI(app, { backend: vertexAIBackend() }); + * const ai = getAI(app, { backend: new VertexAIBackend() }); * ``` * * @param app - The {@link @firebase/app#FirebaseApp} to use. @@ -126,52 +125,33 @@ export function getVertexAI( */ export function getAI( app: FirebaseApp = getApp(), - options: AIOptions = { backend: googleAIBackend() } + options: AIOptions = { backend: new GoogleAIBackend() } ): AI { app = getModularInstance(app); // Dependencies const AIProvider: Provider<'AI'> = _getProvider(app, AI_TYPE); - const identifier = encodeInstanceIdentifier(options.backend); + let identifier: string; + if (options.backend instanceof GoogleAIBackend) { + identifier = encodeInstanceIdentifier({ + backendType: BackendType.GOOGLE_AI + }); + } else if (options.backend instanceof VertexAIBackend) { + identifier = encodeInstanceIdentifier({ + backendType: BackendType.VERTEX_AI, + location: options.backend.location ?? DEFAULT_LOCATION + }); + } else { + throw new AIError( + AIErrorCode.ERROR, + `Invalid backend type: ${options.backend.backendType}` + ); + } return AIProvider.getImmediate({ identifier }); } -/** - * Creates a {@link Backend} instance configured to use Google AI. - * - * @returns A {@link GoogleAIBackend} object. - * - * @public - */ -export function googleAIBackend(): GoogleAIBackend { - const backend: GoogleAIBackend = { - backendType: BackendType.GOOGLE_AI - }; - - return backend; -} - -/** - * Creates a {@link Backend} instance configured to use Vertex AI. - * - * @param location - The region identifier, defaulting to `us-central1`; - * see {@link https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations | Vertex AI locations} - * for a list of supported locations. - * @returns A {@link VertexAIBackend} object. - * - * @public - */ -export function vertexAIBackend(location?: string): VertexAIBackend { - const backend: VertexAIBackend = { - backendType: BackendType.VERTEX_AI, - location: location ?? DEFAULT_LOCATION - }; - - return backend; -} - /** * Returns a {@link GenerativeModel} class with methods for inference * and other functionality. diff --git a/packages/vertexai/src/backend.test.ts b/packages/vertexai/src/backend.test.ts new file mode 100644 index 00000000000..837ba04519e --- /dev/null +++ b/packages/vertexai/src/backend.test.ts @@ -0,0 +1,35 @@ +import { expect } from "chai"; +import { GoogleAIBackend, VertexAIBackend } from "./backend"; +import { BackendType } from "./public-types"; +import { DEFAULT_LOCATION } from "./constants"; + +describe('Backend', () => { + describe('GoogleAIBackend', () => { + it('sets backendType to GOOGLE_AI', () => { + const backend = new GoogleAIBackend(); + expect(backend.backendType).to.equal(BackendType.GOOGLE_AI); + }); + }); + describe('VertexAIBackend', () => { + it('set backendType to VERTEX_AI', () => { + const backend = new VertexAIBackend(); + expect(backend.backendType).to.equal(BackendType.VERTEX_AI); + expect(backend.location).to.equal(DEFAULT_LOCATION); + }); + it('sets custom location', () => { + const backend = new VertexAIBackend('test-location'); + expect(backend.backendType).to.equal(BackendType.VERTEX_AI); + expect(backend.location).to.equal('test-location'); + }); + it('sets custom location even if empty string', () => { + const backend = new VertexAIBackend(''); + expect(backend.backendType).to.equal(BackendType.VERTEX_AI); + expect(backend.location).to.equal(''); + }); + it('uses default location if location is null', () => { + const backend = new VertexAIBackend(null as any); + expect(backend.backendType).to.equal(BackendType.VERTEX_AI); + expect(backend.location).to.equal(DEFAULT_LOCATION); + }); + }); +}); \ No newline at end of file diff --git a/packages/vertexai/src/backend.ts b/packages/vertexai/src/backend.ts new file mode 100644 index 00000000000..40f0884712a --- /dev/null +++ b/packages/vertexai/src/backend.ts @@ -0,0 +1,72 @@ +import { DEFAULT_LOCATION } from "./constants"; +import { BackendType } from "./public-types"; + +/** + * Abstract base class representing the configuration for an AI service backend. + * This class should not be instantiated directly. Use its subclasses + * {@link GoogleAIBackend} or {@link VertexAIBackend}. + * + * @public + */ +export abstract class Backend { + /** + * Specifies the backend type (either 'GOOGLE_AI' or 'VERTEX_AI'). + */ + readonly backendType: BackendType; + + /** + * Protected constructor for use by subclasses. + * @param type - The specific backend type constant (e.g., BackendType.GOOGLE_AI). + */ + protected constructor(type: BackendType) { + this.backendType = type; + } +} + +/** + * Represents the configuration class for the Google AI backend. + * Use this with {@link AIOptions} when initializing the service with + * {@link getAI | getAI()}. + * + * @public + */ +export class GoogleAIBackend extends Backend { + /** + * Creates a configuration object for the Google AI backend. + */ + constructor() { + super(BackendType.GOOGLE_AI); + } +} + +/** + * Represents the configuration class for the Vertex AI backend. + * Use this with {@link AIOptions} when initializing the server with + * {@link getAI | getAI() }. + * + * @public + */ +export class VertexAIBackend extends Backend { + /** + * The region identifier. + * See {@link https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations | Vertex AI locations} + * for a list of supported locations. + */ + readonly location: string; + + /** + * Creates a configuration object for the Vertex AI backend. + * + * @param location - The region identifier, defaulting to `us-central1`; + * see {@link https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations | Vertex AI locations} + * for a list of supported locations. + */ + constructor(location: string = DEFAULT_LOCATION) { + super(BackendType.VERTEX_AI); + if (location === null) { + this.location = DEFAULT_LOCATION; + } else { + this.location = location; + } + } +} \ No newline at end of file diff --git a/packages/vertexai/src/backwards-compatbility.test.ts b/packages/vertexai/src/backwards-compatbility.test.ts index 7f96328b305..62463009b24 100644 --- a/packages/vertexai/src/backwards-compatbility.test.ts +++ b/packages/vertexai/src/backwards-compatbility.test.ts @@ -24,10 +24,10 @@ import { VertexAIErrorCode, VertexAIModel, getGenerativeModel, - getImagenModel, - vertexAIBackend + getImagenModel } from './api'; import { AI, VertexAI, AIErrorCode } from './public-types'; +import { VertexAIBackend } from './backend'; function assertAssignable(): void {} @@ -41,7 +41,7 @@ const fakeAI: AI = { appId: 'app-id' } }, - backend: vertexAIBackend('us-central1'), + backend: new VertexAIBackend('us-central1'), location: 'us-central1' }; diff --git a/packages/vertexai/src/errors.ts b/packages/vertexai/src/errors.ts index 85180fe8381..1746b815042 100644 --- a/packages/vertexai/src/errors.ts +++ b/packages/vertexai/src/errors.ts @@ -16,7 +16,7 @@ */ import { FirebaseError } from '@firebase/util'; -import { AIErrorCode as AIErrorCode, CustomErrorData } from './types'; +import { AIErrorCode, CustomErrorData } from './types'; import { VERTEX_TYPE } from './constants'; /** diff --git a/packages/vertexai/src/methods/chat-session.test.ts b/packages/vertexai/src/methods/chat-session.test.ts index cbfcd22e3e0..0564aa84ed6 100644 --- a/packages/vertexai/src/methods/chat-session.test.ts +++ b/packages/vertexai/src/methods/chat-session.test.ts @@ -23,7 +23,7 @@ import * as generateContentMethods from './generate-content'; import { GenerateContentStreamResult } from '../types'; import { ChatSession } from './chat-session'; import { ApiSettings } from '../types/internal'; -import { vertexAIBackend } from '../api'; +import { VertexAIBackend } from '../backend'; use(sinonChai); use(chaiAsPromised); @@ -33,7 +33,7 @@ const fakeApiSettings: ApiSettings = { project: 'my-project', appId: 'my-appid', location: 'us-central1', - backend: vertexAIBackend() + backend: new VertexAIBackend() }; describe('ChatSession', () => { diff --git a/packages/vertexai/src/methods/count-tokens.test.ts b/packages/vertexai/src/methods/count-tokens.test.ts index bdf99711f55..7ebaaf64683 100644 --- a/packages/vertexai/src/methods/count-tokens.test.ts +++ b/packages/vertexai/src/methods/count-tokens.test.ts @@ -25,8 +25,8 @@ import { countTokens } from './count-tokens'; import { CountTokensRequest } from '../types'; import { ApiSettings } from '../types/internal'; import { Task } from '../requests/request'; -import { googleAIBackend, vertexAIBackend } from '../api'; import { mapCountTokensRequest } from '../googleAIMappers'; +import { GoogleAIBackend, VertexAIBackend } from '../backend'; use(sinonChai); use(chaiAsPromised); @@ -36,15 +36,15 @@ const fakeApiSettings: ApiSettings = { project: 'my-project', appId: 'my-appid', location: 'us-central1', - backend: vertexAIBackend() + backend: new VertexAIBackend() }; const fakeGoogleAIApiSettings: ApiSettings = { apiKey: 'key', project: 'my-project', appId: 'my-appid', - location: 'us-central1', - backend: googleAIBackend() + location: '', + backend: new GoogleAIBackend() }; const fakeRequestParams: CountTokensRequest = { diff --git a/packages/vertexai/src/methods/generate-content.test.ts b/packages/vertexai/src/methods/generate-content.test.ts index b5ef144f76f..f796ef11676 100644 --- a/packages/vertexai/src/methods/generate-content.test.ts +++ b/packages/vertexai/src/methods/generate-content.test.ts @@ -31,8 +31,9 @@ import { } from '../types'; import { ApiSettings } from '../types/internal'; import { Task } from '../requests/request'; -import { AIError, googleAIBackend, vertexAIBackend } from '../api'; +import { AIError } from '../api'; import { mapGenerateContentRequest } from '../googleAIMappers'; +import { GoogleAIBackend, VertexAIBackend } from '../backend'; use(sinonChai); use(chaiAsPromised); @@ -42,7 +43,7 @@ const fakeApiSettings: ApiSettings = { project: 'my-project', appId: 'my-appid', location: 'us-central1', - backend: vertexAIBackend() + backend: new VertexAIBackend() }; const fakeGoogleAIApiSettings: ApiSettings = { @@ -50,7 +51,7 @@ const fakeGoogleAIApiSettings: ApiSettings = { project: 'my-project', appId: 'my-appid', location: 'us-central1', - backend: googleAIBackend() + backend: new GoogleAIBackend() }; const fakeRequestParams: GenerateContentRequest = { diff --git a/packages/vertexai/src/models/genai-model.test.ts b/packages/vertexai/src/models/genai-model.test.ts index d8db0bea2ec..229220d7a2a 100644 --- a/packages/vertexai/src/models/genai-model.test.ts +++ b/packages/vertexai/src/models/genai-model.test.ts @@ -19,7 +19,7 @@ import { AI, AIErrorCode } from '../public-types'; import sinonChai from 'sinon-chai'; import { AIModel } from './genai-model'; import { AIError } from '../errors'; -import { vertexAIBackend } from '../api'; +import { VertexAIBackend } from '../backend'; use(sinonChai); @@ -43,7 +43,7 @@ const fakeAI: AI = { appId: 'my-appid' } }, - backend: vertexAIBackend('us-central1'), + backend: new VertexAIBackend('us-central1'), location: 'us-central1' }; @@ -76,7 +76,7 @@ describe('AIModel', () => { projectId: 'my-project' } }, - backend: vertexAIBackend('us-central1'), + backend: new VertexAIBackend('us-central1'), location: 'us-central1' }; try { @@ -94,7 +94,7 @@ describe('AIModel', () => { apiKey: 'key' } }, - backend: vertexAIBackend('us-central1'), + backend: new VertexAIBackend('us-central1'), location: 'us-central1' }; try { @@ -113,7 +113,7 @@ describe('AIModel', () => { projectId: 'my-project' } }, - backend: vertexAIBackend('us-central1'), + backend: new VertexAIBackend('us-central1'), location: 'us-central1' }; try { diff --git a/packages/vertexai/src/models/genai-model.ts b/packages/vertexai/src/models/genai-model.ts index dd3b666d555..e059ff58530 100644 --- a/packages/vertexai/src/models/genai-model.ts +++ b/packages/vertexai/src/models/genai-model.ts @@ -76,8 +76,7 @@ export abstract class AIModel { apiKey: ai.app.options.apiKey, project: ai.app.options.projectId, appId: ai.app.options.appId, - automaticDataCollectionEnabled: - ai.app.automaticDataCollectionEnabled, + automaticDataCollectionEnabled: ai.app.automaticDataCollectionEnabled, location: ai.location, backend: ai.backend }; diff --git a/packages/vertexai/src/models/generative-model.test.ts b/packages/vertexai/src/models/generative-model.test.ts index 7f61070a52a..3ce7173e03e 100644 --- a/packages/vertexai/src/models/generative-model.test.ts +++ b/packages/vertexai/src/models/generative-model.test.ts @@ -21,7 +21,7 @@ import * as request from '../requests/request'; import { match, restore, stub } from 'sinon'; import { getMockResponse } from '../../test-utils/mock-response'; import sinonChai from 'sinon-chai'; -import { vertexAIBackend } from '../api'; +import { VertexAIBackend } from '../backend'; use(sinonChai); @@ -35,7 +35,7 @@ const fakeAI: AI = { appId: 'my-appid' } }, - backend: vertexAIBackend('us-central1'), + backend: new VertexAIBackend('us-central1'), location: 'us-central1' }; diff --git a/packages/vertexai/src/models/imagen-model.test.ts b/packages/vertexai/src/models/imagen-model.test.ts index f7a945d212d..f4121e18f2d 100644 --- a/packages/vertexai/src/models/imagen-model.test.ts +++ b/packages/vertexai/src/models/imagen-model.test.ts @@ -28,7 +28,7 @@ import sinonChai from 'sinon-chai'; import { AIError } from '../errors'; import { getMockResponse } from '../../test-utils/mock-response'; import { match, restore, stub } from 'sinon'; -import { vertexAIBackend } from '../api'; +import { VertexAIBackend } from '../backend'; use(sinonChai); @@ -42,7 +42,7 @@ const fakeAI: AI = { appId: 'my-appid' } }, - backend: vertexAIBackend('us-central1'), + backend: new VertexAIBackend('us-central1'), location: 'us-central1' }; diff --git a/packages/vertexai/src/public-types.ts b/packages/vertexai/src/public-types.ts index 3a9e62a5fa5..fb668a5b956 100644 --- a/packages/vertexai/src/public-types.ts +++ b/packages/vertexai/src/public-types.ts @@ -16,6 +16,7 @@ */ import { FirebaseApp } from '@firebase/app'; +import { Backend } from './backend'; export * from './types'; @@ -61,53 +62,6 @@ export interface AI { location: string; } -/** - * Union type representing the backend configuration for the AI service. - * This can be either a {@link GoogleAIBackend} or a - * {@link VertexAIBackend} configuration object. - * - * Create instances using {@link googleAIBackend | googleAIBackend() } or - * {@link vertexAIBackend | vertexAIBackend() }. - * - * @public - */ -export type Backend = GoogleAIBackend | VertexAIBackend; - -/** - * Represents the configuration object for the Google AI backend. - * Use this with {@link AIOptions} when initializing the service with - * {@link getAI | getAI()}. - * Create an instance using {@link googleAIBackend | googleAIBackend()}. - * - * @public - */ -export type GoogleAIBackend = { - /** - * Specifies the backend type as Google AI. - */ - backendType: typeof BackendType.GOOGLE_AI; -}; - -/** - * Represents the configuration object for the Vertex AI backend. - * Use this with {@link AIOptions} when initializing the server with - * {@link getAI | getAI() }. - * Create an instance using {@link vertexAIBackend | vertexAIBackend() } function. - * - * @public - */ -export type VertexAIBackend = { - /** - * Specifies the backend type as Vertex AI. - */ - backendType: typeof BackendType.VERTEX_AI; - /** - * The region identifier, defaulting to `us-central1`; see {@link https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations | Vertex AI locations} - * for a list of supported locations. - */ - location: string; -}; - /** * An enum-like object containing constants that represent the supported backends * for the Firebase AI SDK. @@ -149,8 +103,6 @@ export type BackendType = (typeof BackendType)[keyof typeof BackendType]; export interface AIOptions { /** * The backend configuration to use for the AI service instance. - * Use {@link googleAIBackend | googleAIBackend()} or - * {@link vertexAIBackend | vertexAIBackend() } to create this configuration. */ backend: Backend; } diff --git a/packages/vertexai/src/requests/request-helpers.ts b/packages/vertexai/src/requests/request-helpers.ts index c4dd514f8a8..c4cc1a20acc 100644 --- a/packages/vertexai/src/requests/request-helpers.ts +++ b/packages/vertexai/src/requests/request-helpers.ts @@ -15,12 +15,7 @@ * limitations under the License. */ -import { - Content, - GenerateContentRequest, - Part, - AIErrorCode -} from '../types'; +import { Content, GenerateContentRequest, Part, AIErrorCode } from '../types'; import { AIError } from '../errors'; import { ImagenGenerationParams, PredictRequestBody } from '../types/internal'; diff --git a/packages/vertexai/src/requests/request.test.ts b/packages/vertexai/src/requests/request.test.ts index 2efe72bdc60..0d162906fdc 100644 --- a/packages/vertexai/src/requests/request.test.ts +++ b/packages/vertexai/src/requests/request.test.ts @@ -25,7 +25,7 @@ import { DEFAULT_API_VERSION } from '../constants'; import { AIErrorCode } from '../types'; import { AIError } from '../errors'; import { getMockResponse } from '../../test-utils/mock-response'; -import { vertexAIBackend } from '../api'; +import { VertexAIBackend } from '../backend'; use(sinonChai); use(chaiAsPromised); @@ -35,7 +35,7 @@ const fakeApiSettings: ApiSettings = { project: 'my-project', appId: 'my-appid', location: 'us-central1', - backend: vertexAIBackend() + backend: new VertexAIBackend() }; describe('request methods', () => { @@ -108,7 +108,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', - backend: vertexAIBackend(), + backend: new VertexAIBackend(), getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }), getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' }) }; @@ -135,7 +135,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', - backend: vertexAIBackend(), + backend: new VertexAIBackend(), automaticDataCollectionEnabled: true, getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }), getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' }) @@ -160,7 +160,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', - backend: vertexAIBackend(), + backend: new VertexAIBackend(), automaticDataCollectionEnabled: false, getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }), getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' }) @@ -188,7 +188,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', - backend: vertexAIBackend() + backend: new VertexAIBackend() }, true, {} @@ -222,7 +222,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', - backend: vertexAIBackend(), + backend: new VertexAIBackend(), getAppCheckToken: () => Promise.resolve({ token: 'dummytoken', error: Error('oops') }) }, @@ -250,7 +250,7 @@ describe('request methods', () => { project: 'myproject', appId: 'my-appid', location: 'moon', - backend: vertexAIBackend() + backend: new VertexAIBackend() }, true, {} @@ -405,9 +405,7 @@ describe('request methods', () => { ); expect((e as AIError).message).to.include('500 Server Error'); expect((e as AIError).message).to.include('extra info'); - expect((e as AIError).message).to.include( - 'generic::invalid_argument' - ); + expect((e as AIError).message).to.include('generic::invalid_argument'); } expect(fetchStub).to.be.calledOnce; }); diff --git a/packages/vertexai/src/requests/request.ts b/packages/vertexai/src/requests/request.ts index 7b75d46a899..7ff51d71e3d 100644 --- a/packages/vertexai/src/requests/request.ts +++ b/packages/vertexai/src/requests/request.ts @@ -26,7 +26,7 @@ import { PACKAGE_VERSION } from '../constants'; import { logger } from '../logger'; -import { BackendType } from '../public-types'; +import { GoogleAIBackend, VertexAIBackend } from '../backend'; export enum Task { GENERATE_CONTENT = 'generateContent', @@ -59,10 +59,15 @@ export class RequestUrl { } private get modelPath(): string { - if (this.apiSettings.backend.backendType === BackendType.GOOGLE_AI) { + if (this.apiSettings.backend instanceof GoogleAIBackend) { return `projects/${this.apiSettings.project}/${this.model}`; - } else { + } else if (this.apiSettings.backend instanceof VertexAIBackend) { return `projects/${this.apiSettings.project}/locations/${this.apiSettings.backend.location}/${this.model}`; + } else { + throw new AIError( + AIErrorCode.ERROR, + `Invalid backend: ${this.apiSettings.backend}` + ); } } diff --git a/packages/vertexai/src/requests/stream-reader.test.ts b/packages/vertexai/src/requests/stream-reader.test.ts index 710372cef40..ea832c7816f 100644 --- a/packages/vertexai/src/requests/stream-reader.test.ts +++ b/packages/vertexai/src/requests/stream-reader.test.ts @@ -38,14 +38,14 @@ import { } from '../types'; import { AIError } from '../errors'; import { ApiSettings } from '../types/internal'; -import { vertexAIBackend } from '../api'; +import { VertexAIBackend } from '../backend'; const fakeApiSettings: ApiSettings = { apiKey: 'key', project: 'my-project', appId: 'my-appid', location: 'us-central1', - backend: vertexAIBackend() + backend: new VertexAIBackend() }; use(sinonChai); diff --git a/packages/vertexai/src/requests/stream-reader.ts b/packages/vertexai/src/requests/stream-reader.ts index 23cc52299f3..1b762947393 100644 --- a/packages/vertexai/src/requests/stream-reader.ts +++ b/packages/vertexai/src/requests/stream-reader.ts @@ -122,10 +122,7 @@ export function getResponseStream( if (done) { if (currentText.trim()) { controller.error( - new AIError( - AIErrorCode.PARSE_FAILED, - 'Failed to parse stream' - ) + new AIError(AIErrorCode.PARSE_FAILED, 'Failed to parse stream') ); return; } diff --git a/packages/vertexai/src/service.test.ts b/packages/vertexai/src/service.test.ts index 11c78fbf15e..ba4c736e810 100644 --- a/packages/vertexai/src/service.test.ts +++ b/packages/vertexai/src/service.test.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { vertexAIBackend } from './api'; +import { VertexAIBackend } from './backend'; import { DEFAULT_LOCATION } from './constants'; import { AIService } from './service'; import { expect } from 'chai'; @@ -31,13 +31,13 @@ const fakeApp = { describe('AIService', () => { // TODO (dlarocque): move some of these tests to helpers.test.ts it('uses default location if not specified', () => { - const ai = new AIService(fakeApp, vertexAIBackend()); + const ai = new AIService(fakeApp, new VertexAIBackend()); expect(ai.location).to.equal(DEFAULT_LOCATION); }); it('uses custom location if specified', () => { const ai = new AIService( fakeApp, - vertexAIBackend('somewhere'), + new VertexAIBackend('somewhere'), /* authProvider */ undefined, /* appCheckProvider */ undefined ); diff --git a/packages/vertexai/src/service.ts b/packages/vertexai/src/service.ts index a608de384b5..006cc45a94e 100644 --- a/packages/vertexai/src/service.ts +++ b/packages/vertexai/src/service.ts @@ -16,7 +16,7 @@ */ import { FirebaseApp, _FirebaseService } from '@firebase/app'; -import { Backend, AI } from './public-types'; +import { AI } from './public-types'; import { AppCheckInternalComponentName, FirebaseAppCheckInternal @@ -26,6 +26,7 @@ import { FirebaseAuthInternal, FirebaseAuthInternalName } from '@firebase/auth-interop-types'; +import { Backend, VertexAIBackend } from './backend'; export class AIService implements AI, _FirebaseService { auth: FirebaseAuthInternal | null; @@ -43,7 +44,7 @@ export class AIService implements AI, _FirebaseService { this.auth = auth || null; this.appCheck = appCheck || null; - if (backend.backendType === 'VERTEX_AI') { + if (backend instanceof VertexAIBackend) { this.location = backend.location; } else { this.location = ''; diff --git a/packages/vertexai/src/types/internal.ts b/packages/vertexai/src/types/internal.ts index 4303d4c07d8..4dde95d520e 100644 --- a/packages/vertexai/src/types/internal.ts +++ b/packages/vertexai/src/types/internal.ts @@ -17,7 +17,8 @@ import { AppCheckTokenResult } from '@firebase/app-check-interop-types'; import { FirebaseAuthTokenData } from '@firebase/auth-interop-types'; -import { Backend } from '../public-types'; +import { Backend } from '../backend'; +import { BackendType } from '../public-types'; export * from './imagen/internal'; @@ -35,4 +36,7 @@ export interface ApiSettings { getAppCheckToken?: () => Promise; } -export type InstanceIdentifier = Backend; +export interface InstanceIdentifier { + backendType: BackendType; + location?: string; +} diff --git a/scripts/update_vertexai_responses.sh b/scripts/update_vertexai_responses.sh index de55ac176ce..bf55a645a66 100755 --- a/scripts/update_vertexai_responses.sh +++ b/scripts/update_vertexai_responses.sh @@ -17,7 +17,7 @@ # This script replaces mock response files for Vertex AI unit tests with a fresh # clone of the shared repository of Vertex AI test data. -RESPONSES_VERSION='v8.*' # The major version of mock responses to use +RESPONSES_VERSION='v10.*' # The major version of mock responses to use REPO_NAME="vertexai-sdk-test-data" REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git" From 02600d0604dd5e1e85075a1b3ace6e23e6b9e23d Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 22 Apr 2025 13:53:37 -0400 Subject: [PATCH 04/32] Cleanup --- packages/vertexai/src/googleAIMappers.test.ts | 15 ++++++--------- packages/vertexai/src/googleAIMappers.ts | 7 ++----- packages/vertexai/src/helpers.test.ts | 1 - packages/vertexai/test-utils/mock-response.ts | 3 --- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/packages/vertexai/src/googleAIMappers.test.ts b/packages/vertexai/src/googleAIMappers.test.ts index 6cf7425a293..a30fcdc3e7b 100644 --- a/packages/vertexai/src/googleAIMappers.test.ts +++ b/packages/vertexai/src/googleAIMappers.test.ts @@ -92,7 +92,7 @@ describe('Google AI Mappers', () => { }; const mappedRequest = mapGenerateContentRequest(request); expect(loggerWarnStub).to.have.been.calledOnceWith( - 'topK in GenerationConfig has been rounded to the nearest integer.' + 'topK in GenerationConfig has been rounded to the nearest integer to match the format for Google AI requests.' ); expect(mappedRequest.generationConfig?.topK).to.equal(16); }); @@ -133,12 +133,8 @@ describe('Google AI Mappers', () => { const googleAIMockResponse: GoogleAIGenerateContentResponse = await ( getMockResponse('googleAI', 'unary-success-citations.txt') as Response ).json(); - console.log(JSON.stringify(googleAIMockResponse)); const mappedResponse = mapGenerateContentResponse(googleAIMockResponse); - console.log(JSON.stringify(googleAIMockResponse)); - console.log(JSON.stringify(mappedResponse)); - expect(mappedResponse.candidates).to.exist; expect(mappedResponse.candidates?.[0].content.parts[0].text).to.contain( 'quantum mechanics' @@ -242,16 +238,17 @@ describe('Google AI Mappers', () => { it('should map a minimal Vertex AI CountTokensRequest', () => { const vertexRequest: CountTokensRequest = { - contents: fakeContents + contents: fakeContents, + systemInstruction: { role: 'system', parts: [{ text: 'Be nice' }] }, + generationConfig: { temperature: 0.8 } }; const expectedGoogleAIRequest: GoogleAICountTokensRequest = { generateContentRequest: { model: fakeModel, contents: vertexRequest.contents, - systemInstruction: undefined, - tools: undefined, - generationConfig: undefined + systemInstruction: { role: 'system', parts: [{ text: 'Be nice' }] }, + generationConfig: { temperature: 0.8 } } }; diff --git a/packages/vertexai/src/googleAIMappers.ts b/packages/vertexai/src/googleAIMappers.ts index af278bef782..290659f1f8d 100644 --- a/packages/vertexai/src/googleAIMappers.ts +++ b/packages/vertexai/src/googleAIMappers.ts @@ -76,7 +76,7 @@ export function mapGenerateContentRequest( if (roundedTopK !== generateContentRequest.generationConfig.topK) { logger.warn( - 'topK in GenerationConfig has been rounded to the nearest integer.' + 'topK in GenerationConfig has been rounded to the nearest integer to match the format for Google AI requests.' ); generateContentRequest.generationConfig.topK = roundedTopK; } @@ -126,10 +126,7 @@ export function mapCountTokensRequest( const mappedCountTokensRequest: GoogleAICountTokensRequest = { generateContentRequest: { model, - contents: countTokensRequest.contents, - systemInstruction: countTokensRequest.systemInstruction, - tools: countTokensRequest.tools, - generationConfig: countTokensRequest.generationConfig + ...countTokensRequest } }; diff --git a/packages/vertexai/src/helpers.test.ts b/packages/vertexai/src/helpers.test.ts index 7ed8f6a754a..5fcf954ac37 100644 --- a/packages/vertexai/src/helpers.test.ts +++ b/packages/vertexai/src/helpers.test.ts @@ -29,7 +29,6 @@ describe('Identifier Encoding/Decoding', () => { backendType: BackendType.VERTEX_AI, location: 'us-central1' }; - console.log(identifier); const expected = `${AI_TYPE}/vertexai/us-central1`; expect(encodeInstanceIdentifier(identifier)).to.equal(expected); }); diff --git a/packages/vertexai/test-utils/mock-response.ts b/packages/vertexai/test-utils/mock-response.ts index c108704d615..5128ddabe74 100644 --- a/packages/vertexai/test-utils/mock-response.ts +++ b/packages/vertexai/test-utils/mock-response.ts @@ -72,9 +72,6 @@ export function getMockResponse( filename: string ): Partial { const mocksLookup = mockSetMaps[backendName]; - if (backendName === 'googleAI') { - console.log(Object.keys(mocksLookup)); - } if (!(filename in mocksLookup)) { throw Error(`${backendName} mock response file '${filename}' not found.`); } From ff625005d13dd91342f3e43f8ecef5c003807799 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 22 Apr 2025 14:42:10 -0400 Subject: [PATCH 05/32] Move GoogleAI types to single file --- common/api-review/vertexai.api.md | 60 +++++++++++++++++-- ...ppers.test.ts => googleai-mappers.test.ts} | 14 ++--- ...googleAIMappers.ts => googleai-mappers.ts} | 24 +++----- .../vertexai/src/methods/count-tokens.test.ts | 2 +- packages/vertexai/src/methods/count-tokens.ts | 2 +- .../src/methods/generate-content.test.ts | 2 +- .../vertexai/src/methods/generate-content.ts | 6 +- packages/vertexai/src/public-types.ts | 2 +- .../vertexai/src/requests/stream-reader.ts | 4 +- packages/vertexai/src/types/googleAI/index.ts | 19 ------ .../vertexai/src/types/googleAI/requests.ts | 29 --------- .../vertexai/src/types/googleAI/responses.ts | 46 -------------- packages/vertexai/src/types/googleai.ts | 44 ++++++++++++++ packages/vertexai/src/types/index.ts | 1 + packages/vertexai/src/types/responses.ts | 31 ++++++++-- 15 files changed, 147 insertions(+), 139 deletions(-) rename packages/vertexai/src/{googleAIMappers.test.ts => googleai-mappers.test.ts} (94%) rename packages/vertexai/src/{googleAIMappers.ts => googleai-mappers.ts} (90%) delete mode 100644 packages/vertexai/src/types/googleAI/index.ts delete mode 100644 packages/vertexai/src/types/googleAI/requests.ts delete mode 100644 packages/vertexai/src/types/googleAI/responses.ts create mode 100644 packages/vertexai/src/types/googleai.ts diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 3f6fa31992f..c4923bc52f3 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -125,11 +125,9 @@ export interface Citation { endIndex?: number; // (undocumented) license?: string; - // (undocumented) publicationDate?: Date_2; // (undocumented) startIndex?: number; - // (undocumented) title?: string; // (undocumented) uri?: string; @@ -420,6 +418,60 @@ export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOp // @public export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; +// Warning: (ae-internal-missing-underscore) The name "GoogleAICitationMetadata" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export interface GoogleAICitationMetadata { + // (undocumented) + citationSources: Citation[]; +} + +// Warning: (ae-internal-missing-underscore) The name "GoogleAICountTokensRequest" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export interface GoogleAICountTokensRequest { + // (undocumented) + generateContentRequest: { + model: string; + contents: Content[]; + systemInstruction?: string | Part | Content; + tools?: Tool[]; + generationConfig?: GenerationConfig; + }; +} + +// Warning: (ae-internal-missing-underscore) The name "GoogleAIGenerateContentCandidate" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export interface GoogleAIGenerateContentCandidate { + // (undocumented) + citationMetadata?: GoogleAICitationMetadata; + // (undocumented) + content: Content; + // (undocumented) + finishMessage?: string; + // (undocumented) + finishReason?: FinishReason; + // (undocumented) + groundingMetadata?: GroundingMetadata; + // (undocumented) + index: number; + // (undocumented) + safetyRatings?: SafetyRating[]; +} + +// Warning: (ae-internal-missing-underscore) The name "GoogleAIGenerateContentResponse" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export interface GoogleAIGenerateContentResponse { + // (undocumented) + candidates?: GoogleAIGenerateContentCandidate[]; + // (undocumented) + promptFeedback?: PromptFeedback; + // (undocumented) + usageMetadata?: UsageMetadata; +} + // @public @deprecated (undocumented) export interface GroundingAttribution { // (undocumented) @@ -653,7 +705,6 @@ export const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"]; export interface PromptFeedback { // (undocumented) blockReason?: BlockReason; - // (undocumented) blockReasonMessage?: string; // (undocumented) safetyRatings: SafetyRating[]; @@ -684,11 +735,8 @@ export interface SafetyRating { category: HarmCategory; // (undocumented) probability: HarmProbability; - // (undocumented) probabilityScore: number; - // (undocumented) severity: HarmSeverity; - // (undocumented) severityScore: number; } diff --git a/packages/vertexai/src/googleAIMappers.test.ts b/packages/vertexai/src/googleai-mappers.test.ts similarity index 94% rename from packages/vertexai/src/googleAIMappers.test.ts rename to packages/vertexai/src/googleai-mappers.test.ts index a30fcdc3e7b..9c3bb0f9241 100644 --- a/packages/vertexai/src/googleAIMappers.test.ts +++ b/packages/vertexai/src/googleai-mappers.test.ts @@ -24,7 +24,7 @@ import { mapGenerateContentRequest, mapGenerateContentResponse, mapPromptFeedback -} from './googleAIMappers'; +} from './googleai-mappers'; import { BlockReason, Content, @@ -44,7 +44,7 @@ import { GoogleAIGenerateContentResponse, GoogleAIGenerateContentCandidate, GoogleAICountTokensRequest -} from './types/googleAI'; +} from './types/googleai'; import { logger } from './logger'; import { AIError } from './errors'; import { getMockResponse } from '../test-utils/mock-response'; @@ -281,7 +281,7 @@ describe('Google AI Mappers', () => { .undefined; // Not in Google AI }); - it('should add default safety rating properties and warn', () => { + it('should add default safety rating properties', () => { const candidates: GoogleAIGenerateContentCandidate[] = [ { index: 0, @@ -297,9 +297,6 @@ describe('Google AI Mappers', () => { } ]; const mapped = mapGenerateContentCandidates(candidates); - expect(loggerWarnStub).to.have.been.calledOnceWith( - "Candidate safety rating properties 'severity', 'severityScore', and 'probabilityScore' are not included in responses from Google AI. Properties have been assigned to default values." - ); expect(mapped[0].safetyRatings).to.exist; const safetyRating = mapped[0].safetyRatings?.[0] as SafetyRating; // Type assertion expect(safetyRating.severity).to.equal( @@ -359,7 +356,7 @@ describe('Google AI Mappers', () => { }); describe('mapPromptFeedback', () => { - it('should add default safety rating properties and warn', () => { + it('should add default safety rating properties', () => { const feedback: PromptFeedback = { blockReason: BlockReason.OTHER, safetyRatings: [ @@ -373,9 +370,6 @@ describe('Google AI Mappers', () => { // Missing blockReasonMessage }; const mapped = mapPromptFeedback(feedback); - expect(loggerWarnStub).to.have.been.calledOnceWith( - "PromptFeedback safety ratings' properties severity, severityScore, and probabilityScore are not included in responses from Google AI. Properties have been assigned to default values." - ); expect(mapped.safetyRatings).to.exist; const safetyRating = mapped.safetyRatings[0] as SafetyRating; // Type assertion expect(safetyRating.severity).to.equal( diff --git a/packages/vertexai/src/googleAIMappers.ts b/packages/vertexai/src/googleai-mappers.ts similarity index 90% rename from packages/vertexai/src/googleAIMappers.ts rename to packages/vertexai/src/googleai-mappers.ts index 290659f1f8d..ede91fe5756 100644 --- a/packages/vertexai/src/googleAIMappers.ts +++ b/packages/vertexai/src/googleai-mappers.ts @@ -33,7 +33,7 @@ import { GoogleAIGenerateContentResponse, GoogleAIGenerateContentCandidate, GoogleAICountTokensRequest -} from './types/googleAI'; +} from './types/googleai'; /** * This SDK supports both Vertex AI and Google AI APIs. @@ -159,17 +159,14 @@ export function mapGenerateContentCandidates( }; } - // Assign missing candidate SafetyRatings properties to their defaults. + // Assign missing candidate SafetyRatings properties to their defaults if undefined. if (candidate.safetyRatings) { - logger.warn( - "Candidate safety rating properties 'severity', 'severityScore', and 'probabilityScore' are not included in responses from Google AI. Properties have been assigned to default values." - ); mappedSafetyRatings = candidate.safetyRatings.map(safetyRating => { return { ...safetyRating, - severity: HarmSeverity.HARM_SEVERITY_UNSUPPORTED, - probabilityScore: 0, - severityScore: 0 + severity: safetyRating.severity ?? HarmSeverity.HARM_SEVERITY_UNSUPPORTED, + probabilityScore: safetyRating.probabilityScore ?? 0, + severityScore: safetyRating.severityScore ?? 0 }; }); } @@ -207,21 +204,18 @@ export function mapGenerateContentCandidates( export function mapPromptFeedback( promptFeedback: PromptFeedback ): PromptFeedback { - // Assign missing PromptFeedback SafetyRatings properties to their defaults. + // Assign missing SafetyRating properties to their defaults if undefined. const mappedSafetyRatings: SafetyRating[] = []; promptFeedback.safetyRatings.forEach(safetyRating => { mappedSafetyRatings.push({ category: safetyRating.category, probability: safetyRating.probability, - severity: HarmSeverity.HARM_SEVERITY_UNSUPPORTED, - probabilityScore: 0, - severityScore: 0, + severity: safetyRating.severity ?? HarmSeverity.HARM_SEVERITY_UNSUPPORTED, + probabilityScore: safetyRating.probabilityScore ?? 0, + severityScore: safetyRating.severityScore ?? 0, blocked: safetyRating.blocked }); }); - logger.warn( - "PromptFeedback safety ratings' properties severity, severityScore, and probabilityScore are not included in responses from Google AI. Properties have been assigned to default values." - ); const mappedPromptFeedback: PromptFeedback = { blockReason: promptFeedback.blockReason, diff --git a/packages/vertexai/src/methods/count-tokens.test.ts b/packages/vertexai/src/methods/count-tokens.test.ts index 7ebaaf64683..7e04ddb3561 100644 --- a/packages/vertexai/src/methods/count-tokens.test.ts +++ b/packages/vertexai/src/methods/count-tokens.test.ts @@ -25,7 +25,7 @@ import { countTokens } from './count-tokens'; import { CountTokensRequest } from '../types'; import { ApiSettings } from '../types/internal'; import { Task } from '../requests/request'; -import { mapCountTokensRequest } from '../googleAIMappers'; +import { mapCountTokensRequest } from '../googleai-mappers'; import { GoogleAIBackend, VertexAIBackend } from '../backend'; use(sinonChai); diff --git a/packages/vertexai/src/methods/count-tokens.ts b/packages/vertexai/src/methods/count-tokens.ts index 3a94f181126..b1e60e3a182 100644 --- a/packages/vertexai/src/methods/count-tokens.ts +++ b/packages/vertexai/src/methods/count-tokens.ts @@ -22,7 +22,7 @@ import { } from '../types'; import { Task, makeRequest } from '../requests/request'; import { ApiSettings } from '../types/internal'; -import * as GoogleAIMapper from '../googleAIMappers'; +import * as GoogleAIMapper from '../googleai-mappers'; import { BackendType } from '../public-types'; export async function countTokens( diff --git a/packages/vertexai/src/methods/generate-content.test.ts b/packages/vertexai/src/methods/generate-content.test.ts index f796ef11676..13250fd83dd 100644 --- a/packages/vertexai/src/methods/generate-content.test.ts +++ b/packages/vertexai/src/methods/generate-content.test.ts @@ -32,7 +32,7 @@ import { import { ApiSettings } from '../types/internal'; import { Task } from '../requests/request'; import { AIError } from '../api'; -import { mapGenerateContentRequest } from '../googleAIMappers'; +import { mapGenerateContentRequest } from '../googleai-mappers'; import { GoogleAIBackend, VertexAIBackend } from '../backend'; use(sinonChai); diff --git a/packages/vertexai/src/methods/generate-content.ts b/packages/vertexai/src/methods/generate-content.ts index f05ca41c0bc..5f7902f5954 100644 --- a/packages/vertexai/src/methods/generate-content.ts +++ b/packages/vertexai/src/methods/generate-content.ts @@ -26,7 +26,7 @@ import { Task, makeRequest } from '../requests/request'; import { createEnhancedContentResponse } from '../requests/response-helpers'; import { processStream } from '../requests/stream-reader'; import { ApiSettings } from '../types/internal'; -import * as GoogleAIMapper from '../googleAIMappers'; +import * as GoogleAIMapper from '../googleai-mappers'; import { BackendType } from '../public-types'; export async function generateContentStream( @@ -66,7 +66,7 @@ export async function generateContent( JSON.stringify(params), requestOptions ); - const generateContentResponse = await handleGenerateContentResponse( + const generateContentResponse = await processGenerateContentResponse( response, apiSettings ); @@ -78,7 +78,7 @@ export async function generateContent( }; } -async function handleGenerateContentResponse( +async function processGenerateContentResponse( response: Response, apiSettings: ApiSettings ): Promise { diff --git a/packages/vertexai/src/public-types.ts b/packages/vertexai/src/public-types.ts index fb668a5b956..6d51c6d38c2 100644 --- a/packages/vertexai/src/public-types.ts +++ b/packages/vertexai/src/public-types.ts @@ -23,7 +23,7 @@ export * from './types'; /** * An instance of the Firebase AI SDK. * - * For more information, refer to the documentation for the new {@link AI}. + * For more information, refer to the documentation for the new {@link AI} interface. * * @public */ diff --git a/packages/vertexai/src/requests/stream-reader.ts b/packages/vertexai/src/requests/stream-reader.ts index 1b762947393..543d1d02266 100644 --- a/packages/vertexai/src/requests/stream-reader.ts +++ b/packages/vertexai/src/requests/stream-reader.ts @@ -25,8 +25,8 @@ import { } from '../types'; import { AIError } from '../errors'; import { createEnhancedContentResponse } from './response-helpers'; -import * as GoogleAIMapper from '../googleAIMappers'; -import { GoogleAIGenerateContentResponse } from '../types/googleAI'; +import * as GoogleAIMapper from '../googleai-mappers'; +import { GoogleAIGenerateContentResponse } from '../types/googleai'; import { ApiSettings } from '../types/internal'; import { BackendType } from '../public-types'; diff --git a/packages/vertexai/src/types/googleAI/index.ts b/packages/vertexai/src/types/googleAI/index.ts deleted file mode 100644 index 546c64f13b1..00000000000 --- a/packages/vertexai/src/types/googleAI/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export * from './requests'; -export * from './responses'; diff --git a/packages/vertexai/src/types/googleAI/requests.ts b/packages/vertexai/src/types/googleAI/requests.ts deleted file mode 100644 index 94dfb4c4241..00000000000 --- a/packages/vertexai/src/types/googleAI/requests.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Content, Part } from '../content'; -import { GenerationConfig, Tool } from '../requests'; - -export interface GoogleAICountTokensRequest { - generateContentRequest: { - model: string; // 'models/model-name' - contents: Content[]; - systemInstruction?: string | Part | Content; - tools?: Tool[]; - generationConfig?: GenerationConfig; - }; -} diff --git a/packages/vertexai/src/types/googleAI/responses.ts b/packages/vertexai/src/types/googleAI/responses.ts deleted file mode 100644 index 702464cecc7..00000000000 --- a/packages/vertexai/src/types/googleAI/responses.ts +++ /dev/null @@ -1,46 +0,0 @@ -/** - * @license - * Copyright 2025 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Content } from '../content'; -import { FinishReason } from '../enums'; -import { - Citation, - GroundingMetadata, - PromptFeedback, - SafetyRating, - UsageMetadata -} from '../responses'; - -export interface GoogleAIGenerateContentResponse { - candidates?: GoogleAIGenerateContentCandidate[]; - promptFeedback?: PromptFeedback; - usageMetadata?: UsageMetadata; -} - -export interface GoogleAIGenerateContentCandidate { - index: number; - content: Content; - finishReason?: FinishReason; - finishMessage?: string; - safetyRatings?: SafetyRating[]; - citationMetadata?: GoogleAICitationMetadata; - groundingMetadata?: GroundingMetadata; -} - -export interface GoogleAICitationMetadata { - citationSources: Citation[]; // Maps to `citations` -} diff --git a/packages/vertexai/src/types/googleai.ts b/packages/vertexai/src/types/googleai.ts new file mode 100644 index 00000000000..c4a3580c9a2 --- /dev/null +++ b/packages/vertexai/src/types/googleai.ts @@ -0,0 +1,44 @@ +import { Tool, GenerationConfig, Citation, FinishReason, GroundingMetadata, PromptFeedback, SafetyRating, UsageMetadata } from '../public-types'; +import { Content, Part } from './content'; + +/** + * @internal + */ +export interface GoogleAICountTokensRequest { + generateContentRequest: { + model: string; // 'models/model-name' + contents: Content[]; + systemInstruction?: string | Part | Content; + tools?: Tool[]; + generationConfig?: GenerationConfig; + }; +} + +/** + * @internal + */ +export interface GoogleAIGenerateContentResponse { + candidates?: GoogleAIGenerateContentCandidate[]; + promptFeedback?: PromptFeedback; + usageMetadata?: UsageMetadata; +} + +/** + * @internal + */ +export interface GoogleAIGenerateContentCandidate { + index: number; + content: Content; + finishReason?: FinishReason; + finishMessage?: string; + safetyRatings?: SafetyRating[]; + citationMetadata?: GoogleAICitationMetadata; + groundingMetadata?: GroundingMetadata; +} + +/** + * @internal + */ +export interface GoogleAICitationMetadata { + citationSources: Citation[]; // Maps to `citations` +} \ No newline at end of file diff --git a/packages/vertexai/src/types/index.ts b/packages/vertexai/src/types/index.ts index f575c5ba8e9..01f3e7a701a 100644 --- a/packages/vertexai/src/types/index.ts +++ b/packages/vertexai/src/types/index.ts @@ -22,3 +22,4 @@ export * from './responses'; export * from './error'; export * from './schema'; export * from './imagen'; +export * from './googleai'; diff --git a/packages/vertexai/src/types/responses.ts b/packages/vertexai/src/types/responses.ts index 844b0b2934b..f8132533d66 100644 --- a/packages/vertexai/src/types/responses.ts +++ b/packages/vertexai/src/types/responses.ts @@ -108,7 +108,10 @@ export interface ModalityTokenCount { export interface PromptFeedback { blockReason?: BlockReason; safetyRatings: SafetyRating[]; - blockReasonMessage?: string; // This will always be undefined when using Google AI. + /** + * This field is unsupported in Google AI. + */ + blockReasonMessage?: string; } /** @@ -142,8 +145,14 @@ export interface Citation { endIndex?: number; uri?: string; license?: string; - title?: string; // This will always be undefined when using Google AI. - publicationDate?: Date; // This will always be undefined when using Google AI. + /** + * This field is not supported in Google AI. + */ + title?: string; + /** + * This field is not supported in Google AI. + */ + publicationDate?: Date; } /** @@ -212,10 +221,20 @@ export interface Date { export interface SafetyRating { category: HarmCategory; probability: HarmProbability; + /** + * This field is not supported in Google AI, so it will default to `HarmSeverity.UNSUPPORTED` + * when using Google AI. + */ severity: HarmSeverity; + /** + * This field is not supported in Google AI, so it will default to 0 when using Google AI. + */ probabilityScore: number; + /** + * This field is not supported in Google AI, so it will default to 0 when using Google AI. + */ severityScore: number; - blocked: boolean; // FIXME: This is only included when it's true. Either set a default of false, or make this optional. + blocked: boolean; } /** @@ -230,8 +249,10 @@ export interface CountTokensResponse { /** * The total number of billable characters counted across all instances * from the request. + * + * This field is not supported in Google AI, so it will default to 0 when using Google AI. */ - totalBillableCharacters?: number; // This will always be undefined when using Google AI. + totalBillableCharacters?: number; /** * The breakdown, by modality, of how many tokens are consumed by the prompt. */ From 48fc75c6e02578133e62c5f48cb2cf23175f0579 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 22 Apr 2025 14:42:55 -0400 Subject: [PATCH 06/32] Format --- packages/vertexai/src/backend.test.ts | 29 +++++++++++++++++----- packages/vertexai/src/backend.ts | 23 ++++++++++++++--- packages/vertexai/src/googleai-mappers.ts | 3 ++- packages/vertexai/src/types/googleai.ts | 30 +++++++++++++++++++++-- packages/vertexai/src/types/responses.ts | 2 +- 5 files changed, 74 insertions(+), 13 deletions(-) diff --git a/packages/vertexai/src/backend.test.ts b/packages/vertexai/src/backend.test.ts index 837ba04519e..ec754bd41f0 100644 --- a/packages/vertexai/src/backend.test.ts +++ b/packages/vertexai/src/backend.test.ts @@ -1,11 +1,28 @@ -import { expect } from "chai"; -import { GoogleAIBackend, VertexAIBackend } from "./backend"; -import { BackendType } from "./public-types"; -import { DEFAULT_LOCATION } from "./constants"; +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; +import { GoogleAIBackend, VertexAIBackend } from './backend'; +import { BackendType } from './public-types'; +import { DEFAULT_LOCATION } from './constants'; describe('Backend', () => { describe('GoogleAIBackend', () => { - it('sets backendType to GOOGLE_AI', () => { + it('sets backendType to GOOGLE_AI', () => { const backend = new GoogleAIBackend(); expect(backend.backendType).to.equal(BackendType.GOOGLE_AI); }); @@ -32,4 +49,4 @@ describe('Backend', () => { expect(backend.location).to.equal(DEFAULT_LOCATION); }); }); -}); \ No newline at end of file +}); diff --git a/packages/vertexai/src/backend.ts b/packages/vertexai/src/backend.ts index 40f0884712a..cb80c158b8a 100644 --- a/packages/vertexai/src/backend.ts +++ b/packages/vertexai/src/backend.ts @@ -1,5 +1,22 @@ -import { DEFAULT_LOCATION } from "./constants"; -import { BackendType } from "./public-types"; +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { DEFAULT_LOCATION } from './constants'; +import { BackendType } from './public-types'; /** * Abstract base class representing the configuration for an AI service backend. @@ -69,4 +86,4 @@ export class VertexAIBackend extends Backend { this.location = location; } } -} \ No newline at end of file +} diff --git a/packages/vertexai/src/googleai-mappers.ts b/packages/vertexai/src/googleai-mappers.ts index ede91fe5756..405dbd8d8c9 100644 --- a/packages/vertexai/src/googleai-mappers.ts +++ b/packages/vertexai/src/googleai-mappers.ts @@ -164,7 +164,8 @@ export function mapGenerateContentCandidates( mappedSafetyRatings = candidate.safetyRatings.map(safetyRating => { return { ...safetyRating, - severity: safetyRating.severity ?? HarmSeverity.HARM_SEVERITY_UNSUPPORTED, + severity: + safetyRating.severity ?? HarmSeverity.HARM_SEVERITY_UNSUPPORTED, probabilityScore: safetyRating.probabilityScore ?? 0, severityScore: safetyRating.severityScore ?? 0 }; diff --git a/packages/vertexai/src/types/googleai.ts b/packages/vertexai/src/types/googleai.ts index c4a3580c9a2..38c27b3fe8b 100644 --- a/packages/vertexai/src/types/googleai.ts +++ b/packages/vertexai/src/types/googleai.ts @@ -1,4 +1,30 @@ -import { Tool, GenerationConfig, Citation, FinishReason, GroundingMetadata, PromptFeedback, SafetyRating, UsageMetadata } from '../public-types'; +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + Tool, + GenerationConfig, + Citation, + FinishReason, + GroundingMetadata, + PromptFeedback, + SafetyRating, + UsageMetadata +} from '../public-types'; import { Content, Part } from './content'; /** @@ -41,4 +67,4 @@ export interface GoogleAIGenerateContentCandidate { */ export interface GoogleAICitationMetadata { citationSources: Citation[]; // Maps to `citations` -} \ No newline at end of file +} diff --git a/packages/vertexai/src/types/responses.ts b/packages/vertexai/src/types/responses.ts index f8132533d66..1822d8ade84 100644 --- a/packages/vertexai/src/types/responses.ts +++ b/packages/vertexai/src/types/responses.ts @@ -249,7 +249,7 @@ export interface CountTokensResponse { /** * The total number of billable characters counted across all instances * from the request. - * + * * This field is not supported in Google AI, so it will default to 0 when using Google AI. */ totalBillableCharacters?: number; From cee1faefea990f32b976d5b15f5be354ca253dc2 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 22 Apr 2025 15:29:35 -0400 Subject: [PATCH 07/32] Encode/decode instance identifiers directly to/from backends --- common/api-review/vertexai.api.md | 18 +++++++- packages/vertexai/src/api.ts | 34 +++------------ packages/vertexai/src/constants.ts | 6 --- packages/vertexai/src/helpers.test.ts | 46 +++++++-------------- packages/vertexai/src/helpers.ts | 50 +++++++++-------------- packages/vertexai/src/index.node.ts | 28 ++++++------- packages/vertexai/src/index.ts | 1 + packages/vertexai/src/requests/request.ts | 2 +- packages/vertexai/src/types/internal.ts | 8 +--- 9 files changed, 72 insertions(+), 121 deletions(-) diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index c4923bc52f3..1650bf3381e 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -12,7 +12,6 @@ import { FirebaseError } from '@firebase/util'; // @public export interface AI { app: FirebaseApp; - // Warning: (ae-forgotten-export) The symbol "Backend" needs to be exported by the entry point index.d.ts backend: Backend; // @deprecated location: string; @@ -75,6 +74,12 @@ export class ArraySchema extends Schema { toJSON(): SchemaRequest; } +// @public +export abstract class Backend { + protected constructor(type: BackendType); + readonly backendType: BackendType; +} + // @public export const BackendType: { readonly VERTEX_AI: "VERTEX_AI"; @@ -418,6 +423,11 @@ export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOp // @public export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; +// @public +export class GoogleAIBackend extends Backend { + constructor(); +} + // Warning: (ae-internal-missing-underscore) The name "GoogleAICitationMetadata" should be prefixed with an underscore because the declaration is marked as @internal // // @internal (undocumented) @@ -897,6 +907,12 @@ export interface UsageMetadata { // @public export type VertexAI = AI; +// @public +export class VertexAIBackend extends Backend { + constructor(location?: string); + readonly location: string; +} + // @public export const VertexAIError: typeof AIError; diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index b1eff5c7378..4f0c407e397 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -18,15 +18,9 @@ import { FirebaseApp, getApp, _getProvider } from '@firebase/app'; import { Provider } from '@firebase/component'; import { getModularInstance } from '@firebase/util'; -import { DEFAULT_LOCATION, AI_TYPE } from './constants'; +import { AI_TYPE } from './constants'; import { AIService } from './service'; -import { - BackendType, - AI, - AIOptions, - VertexAI, - VertexAIOptions -} from './public-types'; +import { AI, AIOptions, VertexAI, VertexAIOptions } from './public-types'; import { ImagenModelParams, ModelParams, @@ -42,6 +36,7 @@ export { ChatSession } from './methods/chat-session'; export * from './requests/schema-builder'; export { ImagenImageFormat } from './requests/imagen-image-format'; export { AIModel, GenerativeModel, ImagenModel, AIError }; +export { Backend, VertexAIBackend, GoogleAIBackend } from './backend'; export { AIErrorCode as VertexAIErrorCode }; @@ -86,10 +81,8 @@ export function getVertexAI( // Dependencies const AIProvider: Provider<'AI'> = _getProvider(app, AI_TYPE); - const identifier = encodeInstanceIdentifier({ - backendType: BackendType.VERTEX_AI, - location: options?.location ?? DEFAULT_LOCATION - }); + const backend = new VertexAIBackend(options?.location); + const identifier = encodeInstanceIdentifier(backend); return AIProvider.getImmediate({ identifier }); @@ -131,22 +124,7 @@ export function getAI( // Dependencies const AIProvider: Provider<'AI'> = _getProvider(app, AI_TYPE); - let identifier: string; - if (options.backend instanceof GoogleAIBackend) { - identifier = encodeInstanceIdentifier({ - backendType: BackendType.GOOGLE_AI - }); - } else if (options.backend instanceof VertexAIBackend) { - identifier = encodeInstanceIdentifier({ - backendType: BackendType.VERTEX_AI, - location: options.backend.location ?? DEFAULT_LOCATION - }); - } else { - throw new AIError( - AIErrorCode.ERROR, - `Invalid backend type: ${options.backend.backendType}` - ); - } + const identifier = encodeInstanceIdentifier(options.backend); return AIProvider.getImmediate({ identifier }); diff --git a/packages/vertexai/src/constants.ts b/packages/vertexai/src/constants.ts index 8bb46222ddd..6339ce63017 100644 --- a/packages/vertexai/src/constants.ts +++ b/packages/vertexai/src/constants.ts @@ -16,18 +16,12 @@ */ import { version } from '../package.json'; -import { BackendType } from './public-types'; -import { InstanceIdentifier } from './types/internal'; // TODO (v12): Remove this export const VERTEX_TYPE = 'vertexAI'; export const AI_TYPE = 'AI'; -export const DEFAULT_INSTANCE_IDENTIFIER: InstanceIdentifier = { - backendType: BackendType.GOOGLE_AI -}; - export const DEFAULT_LOCATION = 'us-central1'; export const DEFAULT_BASE_URL = 'https://firebasevertexai.googleapis.com'; diff --git a/packages/vertexai/src/helpers.test.ts b/packages/vertexai/src/helpers.test.ts index 5fcf954ac37..533edf79e5f 100644 --- a/packages/vertexai/src/helpers.test.ts +++ b/packages/vertexai/src/helpers.test.ts @@ -18,52 +18,39 @@ import { expect } from 'chai'; import { AI_TYPE } from './constants'; import { encodeInstanceIdentifier, decodeInstanceIdentifier } from './helpers'; import { AIError } from './errors'; -import { BackendType } from './public-types'; -import { InstanceIdentifier } from './types/internal'; import { AIErrorCode } from './types'; +import { GoogleAIBackend, VertexAIBackend } from './backend'; describe('Identifier Encoding/Decoding', () => { describe('encodeInstanceIdentifier', () => { it('should encode Vertex AI identifier with a specific location', () => { - const identifier: InstanceIdentifier = { - backendType: BackendType.VERTEX_AI, - location: 'us-central1' - }; + const backend = new VertexAIBackend('us-central1'); const expected = `${AI_TYPE}/vertexai/us-central1`; - expect(encodeInstanceIdentifier(identifier)).to.equal(expected); + expect(encodeInstanceIdentifier(backend)).to.equal(expected); }); it('should encode Vertex AI identifier using empty location', () => { - const identifier: InstanceIdentifier = { - backendType: BackendType.VERTEX_AI, - location: '' - }; + const backend = new VertexAIBackend(''); const expected = `${AI_TYPE}/vertexai/`; - expect(encodeInstanceIdentifier(identifier)).to.equal(expected); + expect(encodeInstanceIdentifier(backend)).to.equal(expected); }); it('should encode Google AI identifier', () => { - const identifier: InstanceIdentifier = { - backendType: BackendType.GOOGLE_AI - }; + const backend = new GoogleAIBackend(); const expected = `${AI_TYPE}/googleai`; - expect(encodeInstanceIdentifier(identifier)).to.equal(expected); + expect(encodeInstanceIdentifier(backend)).to.equal(expected); }); it('should throw AIError for unknown backend type', () => { - const identifier = { - backendType: 'some-future-backend' - } as any; // bypass type checking for the test - - expect(() => encodeInstanceIdentifier(identifier)).to.throw(AIError); + expect(() => encodeInstanceIdentifier({} as any)).to.throw(AIError); try { - encodeInstanceIdentifier(identifier); + encodeInstanceIdentifier({} as any); expect.fail('Expected encodeInstanceIdentifier to throw'); } catch (e) { expect(e).to.be.instanceOf(AIError); const error = e as AIError; - expect(error.message).to.contain(`Unknown backend`); + expect(error.message).to.contain('Invalid backend'); expect(error.code).to.equal(AIErrorCode.ERROR); } }); @@ -72,11 +59,8 @@ describe('Identifier Encoding/Decoding', () => { describe('decodeInstanceIdentifier', () => { it('should decode Vertex AI identifier with location', () => { const encoded = `${AI_TYPE}/vertexai/europe-west1`; - const expected: InstanceIdentifier = { - backendType: BackendType.VERTEX_AI, - location: 'europe-west1' - }; - expect(decodeInstanceIdentifier(encoded)).to.deep.equal(expected); + const backend = new VertexAIBackend('europe-west1'); + expect(decodeInstanceIdentifier(encoded)).to.deep.equal(backend); }); it('should throw an error if Vertex AI identifier string without explicit location part', () => { @@ -98,10 +82,8 @@ describe('Identifier Encoding/Decoding', () => { it('should decode Google AI identifier', () => { const encoded = `${AI_TYPE}/googleai`; - const expected: InstanceIdentifier = { - backendType: BackendType.GOOGLE_AI - }; - expect(decodeInstanceIdentifier(encoded)).to.deep.equal(expected); + const backend = new GoogleAIBackend(); + expect(decodeInstanceIdentifier(encoded)).to.deep.equal(backend); }); it('should throw AIError for invalid backend string', () => { diff --git a/packages/vertexai/src/helpers.ts b/packages/vertexai/src/helpers.ts index 764d06fe9f7..709bf4369c5 100644 --- a/packages/vertexai/src/helpers.ts +++ b/packages/vertexai/src/helpers.ts @@ -17,41 +17,34 @@ import { AI_TYPE } from './constants'; import { AIError } from './errors'; -import { BackendType } from './public-types'; -import { InstanceIdentifier } from './types/internal'; import { AIErrorCode } from './types'; +import { Backend, GoogleAIBackend, VertexAIBackend } from './backend'; /** - * Encodes an {@link InstanceIdentifier} into a string. - * - * This string is used to identify unique {@link AI} instances by backend type. + * Encodes a {@link Backend} into a string that will be used to uniquely identify {@link AI} + * instances by backend type. * * @internal */ -export function encodeInstanceIdentifier( - instanceIdentifier: InstanceIdentifier -): string { - switch (instanceIdentifier.backendType) { - case BackendType.VERTEX_AI: - return `${AI_TYPE}/vertexai/${instanceIdentifier.location}`; - case BackendType.GOOGLE_AI: - return `${AI_TYPE}/googleai`; - default: - throw new AIError( - AIErrorCode.ERROR, - `Unknown backend '${instanceIdentifier}'` - ); +export function encodeInstanceIdentifier(backend: Backend): string { + if (backend instanceof GoogleAIBackend) { + return `${AI_TYPE}/googleai`; + } else if (backend instanceof VertexAIBackend) { + return `${AI_TYPE}/vertexai/${backend.location}`; + } else { + throw new AIError( + AIErrorCode.ERROR, + `Invalid backend: ${JSON.stringify(backend.backendType)}` + ); } } /** - * Decodes an instance identifier string into an {@link InstanceIdentifier}. + * Decodes an instance identifier string into a {@link Backend}. * * @internal */ -export function decodeInstanceIdentifier( - instanceIdentifier: string -): InstanceIdentifier { +export function decodeInstanceIdentifier(instanceIdentifier: string): Backend { const identifierParts = instanceIdentifier.split('/'); if (identifierParts[0] !== AI_TYPE) { throw new AIError( @@ -59,8 +52,8 @@ export function decodeInstanceIdentifier( `Invalid instance identifier, unknown prefix '${identifierParts[0]}'` ); } - const backend = identifierParts[1]; - switch (backend) { + const backendType = identifierParts[1]; + switch (backendType) { case 'vertexai': const location: string | undefined = identifierParts[2]; if (!location) { @@ -69,14 +62,9 @@ export function decodeInstanceIdentifier( `Invalid instance identifier, unknown location '${instanceIdentifier}'` ); } - return { - backendType: BackendType.VERTEX_AI, - location - }; + return new VertexAIBackend(location); case 'googleai': - return { - backendType: BackendType.GOOGLE_AI - }; + return new GoogleAIBackend(); default: throw new AIError( AIErrorCode.ERROR, diff --git a/packages/vertexai/src/index.node.ts b/packages/vertexai/src/index.node.ts index 60ed127c19d..1908e65b1cd 100644 --- a/packages/vertexai/src/index.node.ts +++ b/packages/vertexai/src/index.node.ts @@ -23,33 +23,31 @@ import { registerVersion, _registerComponent } from '@firebase/app'; import { AIService } from './service'; -import { DEFAULT_INSTANCE_IDENTIFIER, AI_TYPE } from './constants'; +import { AI_TYPE } from './constants'; import { Component, ComponentType } from '@firebase/component'; import { name, version } from '../package.json'; -import { InstanceIdentifier } from './types/internal'; import { decodeInstanceIdentifier } from './helpers'; +import { AIError } from './errors'; +import { AIErrorCode } from './public-types'; function registerAI(): void { _registerComponent( new Component( AI_TYPE, - (container, options) => { - // getImmediate for FirebaseApp will always succeed - const app = container.getProvider('app').getImmediate(); - const auth = container.getProvider('auth-internal'); - const appCheckProvider = container.getProvider('app-check-internal'); - - let instanceIdentifier: InstanceIdentifier; - if (options.instanceIdentifier) { - instanceIdentifier = decodeInstanceIdentifier( - options.instanceIdentifier + (container, { instanceIdentifier }) => { + if (!instanceIdentifier) { + throw new AIError( + AIErrorCode.ERROR, + 'AIService instance identifier is undefined.' ); - } else { - instanceIdentifier = DEFAULT_INSTANCE_IDENTIFIER; } - const backend = instanceIdentifier; + const backend = decodeInstanceIdentifier(instanceIdentifier); + // getImmediate for FirebaseApp will always succeed + const app = container.getProvider('app').getImmediate(); + const auth = container.getProvider('auth-internal'); + const appCheckProvider = container.getProvider('app-check-internal'); return new AIService(app, backend, auth, appCheckProvider); }, ComponentType.PUBLIC diff --git a/packages/vertexai/src/index.ts b/packages/vertexai/src/index.ts index 2f275e9d903..8451d68bbf0 100644 --- a/packages/vertexai/src/index.ts +++ b/packages/vertexai/src/index.ts @@ -49,6 +49,7 @@ function registerAI(): void { } const backend = decodeInstanceIdentifier(instanceIdentifier); + // getImmediate for FirebaseApp will always succeed const app = container.getProvider('app').getImmediate(); const auth = container.getProvider('auth-internal'); diff --git a/packages/vertexai/src/requests/request.ts b/packages/vertexai/src/requests/request.ts index 7ff51d71e3d..31c5e9b8125 100644 --- a/packages/vertexai/src/requests/request.ts +++ b/packages/vertexai/src/requests/request.ts @@ -66,7 +66,7 @@ export class RequestUrl { } else { throw new AIError( AIErrorCode.ERROR, - `Invalid backend: ${this.apiSettings.backend}` + `Invalid backend: ${JSON.stringify(this.apiSettings.backend)}` ); } } diff --git a/packages/vertexai/src/types/internal.ts b/packages/vertexai/src/types/internal.ts index 4dde95d520e..a41ec5652d3 100644 --- a/packages/vertexai/src/types/internal.ts +++ b/packages/vertexai/src/types/internal.ts @@ -18,7 +18,6 @@ import { AppCheckTokenResult } from '@firebase/app-check-interop-types'; import { FirebaseAuthTokenData } from '@firebase/auth-interop-types'; import { Backend } from '../backend'; -import { BackendType } from '../public-types'; export * from './imagen/internal'; @@ -28,15 +27,10 @@ export interface ApiSettings { appId: string; automaticDataCollectionEnabled?: boolean; /** - * @deprecated + * @deprecated Use `backend.location` instead. */ location: string; backend: Backend; getAuthToken?: () => Promise; getAppCheckToken?: () => Promise; } - -export interface InstanceIdentifier { - backendType: BackendType; - location?: string; -} From 475c81a735a30221326688b9d5081d83183eb660 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Wed, 23 Apr 2025 11:19:30 -0400 Subject: [PATCH 08/32] Update changeset --- .changeset/tall-zoos-stare.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tall-zoos-stare.md b/.changeset/tall-zoos-stare.md index f4e7601b4a4..f6bbe141228 100644 --- a/.changeset/tall-zoos-stare.md +++ b/.changeset/tall-zoos-stare.md @@ -3,4 +3,4 @@ '@firebase/vertexai': minor --- -Add support for the Google AI API, enabling usage in a free tier, and migrate from `VertexAI` naming to `GenAI`. +Add support for the Google AI API, enabling usage in a free tier, and add new `AI` API to accomodate new product naming. From 730f460262620cbd02080e0b3bb1d1fc024cf742 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Wed, 23 Apr 2025 14:24:10 -0400 Subject: [PATCH 09/32] Cleanup --- config/.eslintrc.js | 2 - docs-devsite/vertexai.ai.md | 4 +- docs-devsite/vertexai.aioptions.md | 4 +- docs-devsite/vertexai.backend.md | 57 ++++++++++ docs-devsite/vertexai.citation.md | 8 +- docs-devsite/vertexai.counttokensresponse.md | 4 +- docs-devsite/vertexai.googleaibackend.md | 36 ++++++ .../vertexai.imagengenerationconfig.md | 6 +- docs-devsite/vertexai.md | 106 +++--------------- docs-devsite/vertexai.promptfeedback.md | 4 +- docs-devsite/vertexai.safetyrating.md | 12 +- docs-devsite/vertexai.vertexaibackend.md | 58 ++++++++++ packages/vertexai/src/types/enums.ts | 2 + .../vertexai/src/types/imagen/requests.ts | 3 +- packages/vertexai/src/types/requests.ts | 5 +- packages/vertexai/src/types/responses.ts | 2 +- 16 files changed, 200 insertions(+), 113 deletions(-) create mode 100644 docs-devsite/vertexai.backend.md create mode 100644 docs-devsite/vertexai.googleaibackend.md create mode 100644 docs-devsite/vertexai.vertexaibackend.md diff --git a/config/.eslintrc.js b/config/.eslintrc.js index aee4a839aaf..d63cc9cd290 100644 --- a/config/.eslintrc.js +++ b/config/.eslintrc.js @@ -174,8 +174,6 @@ module.exports = { } } ], - // We prefer using interfaces, but we need to use types for aliases like ' - // '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], '@typescript-eslint/explicit-member-accessibility': [ 'error', { diff --git a/docs-devsite/vertexai.ai.md b/docs-devsite/vertexai.ai.md index 2901c2ccd01..3be9ea5d488 100644 --- a/docs-devsite/vertexai.ai.md +++ b/docs-devsite/vertexai.ai.md @@ -25,7 +25,7 @@ export interface AI | Property | Type | Description | | --- | --- | --- | | [app](./vertexai.ai.md#aiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./vertexai.ai.md#ai_interface) instance is associated with. | -| [backend](./vertexai.ai.md#aibackend) | [Backend](./vertexai.md#backend) | A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. | +| [backend](./vertexai.ai.md#aibackend) | [Backend](./vertexai.backend.md#backend_class) | A [Backend](./vertexai.backend.md#backend_class) instance that specifies the backend configuration. | | [location](./vertexai.ai.md#ailocation) | string | The location configured for this AI service instance, relevant for Vertex AI backends. | ## AI.app @@ -40,7 +40,7 @@ app: FirebaseApp; ## AI.backend -A [Backend](./vertexai.md#backend) instance that specifies the backend configuration. +A [Backend](./vertexai.backend.md#backend_class) instance that specifies the backend configuration. Signature: diff --git a/docs-devsite/vertexai.aioptions.md b/docs-devsite/vertexai.aioptions.md index 4d5e7117740..393a83b3f9c 100644 --- a/docs-devsite/vertexai.aioptions.md +++ b/docs-devsite/vertexai.aioptions.md @@ -22,11 +22,11 @@ export interface AIOptions | Property | Type | Description | | --- | --- | --- | -| [backend](./vertexai.aioptions.md#aioptionsbackend) | [Backend](./vertexai.md#backend) | The backend configuration to use for the AI service instance. Use [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) to create this configuration. | +| [backend](./vertexai.aioptions.md#aioptionsbackend) | [Backend](./vertexai.backend.md#backend_class) | The backend configuration to use for the AI service instance. | ## AIOptions.backend -The backend configuration to use for the AI service instance. Use [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) to create this configuration. +The backend configuration to use for the AI service instance. Signature: diff --git a/docs-devsite/vertexai.backend.md b/docs-devsite/vertexai.backend.md new file mode 100644 index 00000000000..b55224f5205 --- /dev/null +++ b/docs-devsite/vertexai.backend.md @@ -0,0 +1,57 @@ +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 %} + +# Backend class +Abstract base class representing the configuration for an AI service backend. This class should not be instantiated directly. Use its subclasses [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class). + +Signature: + +```typescript +export declare abstract class Backend +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(type)](./vertexai.backend.md#backendconstructor) | | Protected constructor for use by subclasses. | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [backendType](./vertexai.backend.md#backendbackendtype) | | [BackendType](./vertexai.md#backendtype) | Specifies the backend type (either 'GOOGLE\_AI' or 'VERTEX\_AI'). | + +## Backend.(constructor) + +Protected constructor for use by subclasses. + +Signature: + +```typescript +protected constructor(type: BackendType); +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| type | [BackendType](./vertexai.md#backendtype) | The specific backend type constant (e.g., BackendType.GOOGLE\_AI). | + +## Backend.backendType + +Specifies the backend type (either 'GOOGLE\_AI' or 'VERTEX\_AI'). + +Signature: + +```typescript +readonly backendType: BackendType; +``` diff --git a/docs-devsite/vertexai.citation.md b/docs-devsite/vertexai.citation.md index b5f5a19f231..f2e4e2581cb 100644 --- a/docs-devsite/vertexai.citation.md +++ b/docs-devsite/vertexai.citation.md @@ -24,9 +24,9 @@ export interface Citation | --- | --- | --- | | [endIndex](./vertexai.citation.md#citationendindex) | number | | | [license](./vertexai.citation.md#citationlicense) | string | | -| [publicationDate](./vertexai.citation.md#citationpublicationdate) | Date | | +| [publicationDate](./vertexai.citation.md#citationpublicationdate) | Date | This field is not supported in Google AI. | | [startIndex](./vertexai.citation.md#citationstartindex) | number | | -| [title](./vertexai.citation.md#citationtitle) | string | | +| [title](./vertexai.citation.md#citationtitle) | string | This field is not supported in Google AI. | | [uri](./vertexai.citation.md#citationuri) | string | | ## Citation.endIndex @@ -47,6 +47,8 @@ license?: string; ## Citation.publicationDate +This field is not supported in Google AI. + Signature: ```typescript @@ -63,6 +65,8 @@ startIndex?: number; ## Citation.title +This field is not supported in Google AI. + Signature: ```typescript diff --git a/docs-devsite/vertexai.counttokensresponse.md b/docs-devsite/vertexai.counttokensresponse.md index d67cc99fab2..dab373586b4 100644 --- a/docs-devsite/vertexai.counttokensresponse.md +++ b/docs-devsite/vertexai.counttokensresponse.md @@ -23,7 +23,7 @@ export interface CountTokensResponse | Property | Type | Description | | --- | --- | --- | | [promptTokensDetails](./vertexai.counttokensresponse.md#counttokensresponseprompttokensdetails) | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface)\[\] | The breakdown, by modality, of how many tokens are consumed by the prompt. | -| [totalBillableCharacters](./vertexai.counttokensresponse.md#counttokensresponsetotalbillablecharacters) | number | The total number of billable characters counted across all instances from the request. | +| [totalBillableCharacters](./vertexai.counttokensresponse.md#counttokensresponsetotalbillablecharacters) | number | The total number of billable characters counted across all instances from the request.This field is not supported in Google AI, so it will default to 0 when using Google AI. | | [totalTokens](./vertexai.counttokensresponse.md#counttokensresponsetotaltokens) | number | The total number of tokens counted across all instances from the request. | ## CountTokensResponse.promptTokensDetails @@ -40,6 +40,8 @@ promptTokensDetails?: ModalityTokenCount[]; The total number of billable characters counted across all instances from the request. +This field is not supported in Google AI, so it will default to 0 when using Google AI. + Signature: ```typescript diff --git a/docs-devsite/vertexai.googleaibackend.md b/docs-devsite/vertexai.googleaibackend.md new file mode 100644 index 00000000000..99e9bd18a14 --- /dev/null +++ b/docs-devsite/vertexai.googleaibackend.md @@ -0,0 +1,36 @@ +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 %} + +# GoogleAIBackend class +Represents the configuration class for the Google AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the service with [getAI()](./vertexai.md#getai_a94a413). + +Signature: + +```typescript +export declare class GoogleAIBackend extends Backend +``` +Extends: [Backend](./vertexai.backend.md#backend_class) + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)()](./vertexai.googleaibackend.md#googleaibackendconstructor) | | Creates a configuration object for the Google AI backend. | + +## GoogleAIBackend.(constructor) + +Creates a configuration object for the Google AI backend. + +Signature: + +```typescript +constructor(); +``` diff --git a/docs-devsite/vertexai.imagengenerationconfig.md b/docs-devsite/vertexai.imagengenerationconfig.md index 8c452bcd116..ac30cf4020a 100644 --- a/docs-devsite/vertexai.imagengenerationconfig.md +++ b/docs-devsite/vertexai.imagengenerationconfig.md @@ -27,10 +27,10 @@ export interface ImagenGenerationConfig | Property | Type | Description | | --- | --- | --- | -| [addWatermark](./vertexai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | (Public Preview) Whether to add an invisible watermark to generated images.If set to true, an invisible SynthID watermark is embedded in generated images to indicate that they are AI generated. If set to false, watermarking will be disabled.For Imagen 3 models, the default value is true; see the addWatermark documentation for more details. | +| [addWatermark](./vertexai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | (Public Preview) Whether to add an invisible watermark to generated images.If set to true, an invisible SynthID watermark is embedded in generated images to indicate that they are AI generated. If set to false, watermarking will be disabled.For Imagen 3 models, the default value is true; see the addWatermark documentation for more details.In Google AI, the default value is true, and it cannot be turned off. | | [aspectRatio](./vertexai.imagengenerationconfig.md#imagengenerationconfigaspectratio) | [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | (Public Preview) The aspect ratio of the generated images. The default value is square 1:1. Supported aspect ratios depend on the Imagen model, see [ImagenAspectRatio](./vertexai.md#imagenaspectratio) for more details. | | [imageFormat](./vertexai.imagengenerationconfig.md#imagengenerationconfigimageformat) | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) The image format of the generated images. The default is PNG.See [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) for more details. | -| [negativePrompt](./vertexai.imagengenerationconfig.md#imagengenerationconfignegativeprompt) | string | (Public Preview) A description of what should be omitted from the generated images.Support for negative prompts depends on the Imagen model.See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details. | +| [negativePrompt](./vertexai.imagengenerationconfig.md#imagengenerationconfignegativeprompt) | string | (Public Preview) A description of what should be omitted from the generated images.Support for negative prompts depends on the Imagen model.See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details.This is no longer supported in Google AI in versions greater than imagen-3.0-generate-002. | | [numberOfImages](./vertexai.imagengenerationconfig.md#imagengenerationconfignumberofimages) | number | (Public Preview) The number of images to generate. The default value is 1.The number of sample images that may be generated in each request depends on the model (typically up to 4); see the sampleCount documentation for more details. | ## ImagenGenerationConfig.addWatermark @@ -91,6 +91,8 @@ Support for negative prompts depends on the Imagen model. See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details. +This is no longer supported in Google AI in versions greater than `imagen-3.0-generate-002`. + Signature: ```typescript diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index 544deb2987d..0b17e1b2732 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -18,14 +18,10 @@ The Firebase AI Web SDK. | --- | --- | | function(app, ...) | | [getAI(app, options)](./vertexai.md#getai_a94a413) | Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | -| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app. | -| function() | -| [googleAIBackend()](./vertexai.md#googleaibackend) | Creates a [Backend](./vertexai.md#backend) instance configured to use Google AI. | +| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413).Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app. | | function(ai, ...) | | [getGenerativeModel(ai, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | | [getImagenModel(ai, modelParams, requestOptions)](./vertexai.md#getimagenmodel_e1f6645) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | -| function(location, ...) | -| [vertexAIBackend(location)](./vertexai.md#vertexaibackend_d0a4534) | Creates a [Backend](./vertexai.md#backend) instance configured to use Vertex AI. | ## Classes @@ -34,9 +30,11 @@ The Firebase AI Web SDK. | [AIError](./vertexai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. | | [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs. | | [ArraySchema](./vertexai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | +| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend. This class should not be instantiated directly. Use its subclasses [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class). | | [BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | | [ChatSession](./vertexai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | | [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | +| [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) | Represents the configuration class for the Google AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the service with [getAI()](./vertexai.md#getai_a94a413). | | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) Defines the image format for images generated by Imagen.Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface). | | [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) | (Public Preview) Class for Imagen model APIs.This class provides methods for generating images using the Imagen model. | | [IntegerSchema](./vertexai.integerschema.md#integerschema_class) | Schema class for "integer" types. | @@ -44,6 +42,7 @@ The Firebase AI Web SDK. | [ObjectSchema](./vertexai.objectschema.md#objectschema_class) | Schema class for "object" types. The properties param must be a map of Schema objects. | | [Schema](./vertexai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with JSON.stringify() into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) | | [StringSchema](./vertexai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. | +| [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) | Represents the configuration class for the Vertex AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the server with [getAI()](./vertexai.md#getai_a94a413). | ## Enumerations @@ -130,7 +129,7 @@ The Firebase AI Web SDK. | Variable | Description | | --- | --- | -| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.md#googleaibackend) or [VertexAIBackend](./vertexai.md#vertexaibackend)) to identify which service to target. | +| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | | [POSSIBLE\_ROLES](./vertexai.md#possible_roles) | Possible roles. | | [VertexAIError](./vertexai.md#vertexaierror) | Error class for the Firebase AI SDK.For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). | | [VertexAIModel](./vertexai.md#vertexaimodel) | Base class for Firebase AI model APIs.For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). | @@ -139,15 +138,12 @@ The Firebase AI Web SDK. | Type Alias | Description | | --- | --- | -| [Backend](./vertexai.md#backend) | Union type representing the backend configuration for the AI service. This can be either a [GoogleAIBackend](./vertexai.md#googleaibackend) or a [VertexAIBackend](./vertexai.md#vertexaibackend) configuration object.Create instances using [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534). | | [BackendType](./vertexai.md#backendtype) | Type alias representing valid backend types. It can be either 'VERTEX_AI' or 'GOOGLE_AI'. | -| [GoogleAIBackend](./vertexai.md#googleaibackend) | Represents the configuration object for the Google AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the service with [getAI()](./vertexai.md#getai_a94a413). Create an instance using [googleAIBackend()](./vertexai.md#googleaibackend). | | [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. | | [Role](./vertexai.md#role) | Role is the producer of the content. | | [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. | | [TypedSchema](./vertexai.md#typedschema) | A type that includes all specific Schema types. | -| [VertexAI](./vertexai.md#vertexai) | An instance of the Firebase AI SDK.For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface). | -| [VertexAIBackend](./vertexai.md#vertexaibackend) | Represents the configuration object for the Vertex AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the server with [getAI()](./vertexai.md#getai_a94a413). Create an instance using [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) function. | +| [VertexAI](./vertexai.md#vertexai) | An instance of the Firebase AI SDK.For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface) interface. | ## function(app, ...) @@ -187,7 +183,7 @@ const ai = getAI(app); ```javascript // Get an AI instance configured to use Google AI. -const ai = getAI(app, { backend: googleAIBackend() }); +const ai = getAI(app, { backend: new GoogleAIBackend() }); ``` @@ -196,12 +192,14 @@ const ai = getAI(app, { backend: googleAIBackend() }); ```javascript // Get an AI instance configured to use Vertex AI. -const ai = getAI(app, { backend: vertexAIBackend() }); +const ai = getAI(app, { backend: new VertexAIBackend() }); ``` ### getVertexAI(app, options) {:#getvertexai_04094cf} +It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413). + Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app. Signature: @@ -221,23 +219,6 @@ export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions [VertexAI](./vertexai.md#vertexai) -## function() - -### googleAIBackend() {:#googleaibackend} - -Creates a [Backend](./vertexai.md#backend) instance configured to use Google AI. - -Signature: - -```typescript -export declare function googleAIBackend(): GoogleAIBackend; -``` -Returns: - -[GoogleAIBackend](./vertexai.md#googleaibackend) - -A [GoogleAIBackend](./vertexai.md#googleaibackend) object. - ## function(ai, ...) ### getGenerativeModel(ai, modelParams, requestOptions) {:#getgenerativemodel_80bd839} @@ -293,35 +274,11 @@ export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, r If the `apiKey` or `projectId` fields are missing in your Firebase config. -## function(location, ...) - -### vertexAIBackend(location) {:#vertexaibackend_d0a4534} - -Creates a [Backend](./vertexai.md#backend) instance configured to use Vertex AI. - -Signature: - -```typescript -export declare function vertexAIBackend(location?: string): VertexAIBackend; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| location | string | The region identifier, defaulting to us-central1; see [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations) for a list of supported locations. | - -Returns: - -[VertexAIBackend](./vertexai.md#vertexaibackend) - -A [VertexAIBackend](./vertexai.md#vertexaibackend) object. - ## BackendType An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. -These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.md#googleaibackend) or [VertexAIBackend](./vertexai.md#vertexaibackend)) to identify which service to target. +These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. Signature: @@ -366,18 +323,6 @@ For more information, refer to the documentation for the new [AIModel](./vertexa VertexAIModel: typeof AIModel ``` -## Backend - -Union type representing the backend configuration for the AI service. This can be either a [GoogleAIBackend](./vertexai.md#googleaibackend) or a [VertexAIBackend](./vertexai.md#vertexaibackend) configuration object. - -Create instances using [googleAIBackend()](./vertexai.md#googleaibackend) or [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534). - -Signature: - -```typescript -export type Backend = GoogleAIBackend | VertexAIBackend; -``` - ## BackendType Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. @@ -388,18 +333,6 @@ Type alias representing valid backend types. It can be either `'VERTEX_AI'` or ` export type BackendType = (typeof BackendType)[keyof typeof BackendType]; ``` -## GoogleAIBackend - -Represents the configuration object for the Google AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the service with [getAI()](./vertexai.md#getai_a94a413). Create an instance using [googleAIBackend()](./vertexai.md#googleaibackend). - -Signature: - -```typescript -export type GoogleAIBackend = { - backendType: typeof BackendType.GOOGLE_AI; -}; -``` - ## Part Content part - includes text, image/video, or function call/response part types. @@ -444,7 +377,7 @@ export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanS An instance of the Firebase AI SDK. -For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface). +For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface) interface. Signature: @@ -452,19 +385,6 @@ For more information, refer to the documentation for the new [AI](./vertexai.ai. export type VertexAI = AI; ``` -## VertexAIBackend - -Represents the configuration object for the Vertex AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the server with [getAI()](./vertexai.md#getai_a94a413). Create an instance using [vertexAIBackend()](./vertexai.md#vertexaibackend_d0a4534) function. - -Signature: - -```typescript -export type VertexAIBackend = { - backendType: typeof BackendType.VERTEX_AI; - location: string; -}; -``` - ## AIErrorCode Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. @@ -645,7 +565,7 @@ export declare enum HarmSeverity | HARM\_SEVERITY\_LOW | "HARM_SEVERITY_LOW" | Low level of harm severity. | | HARM\_SEVERITY\_MEDIUM | "HARM_SEVERITY_MEDIUM" | Medium level of harm severity. | | HARM\_SEVERITY\_NEGLIGIBLE | "HARM_SEVERITY_NEGLIGIBLE" | Negligible level of harm severity. | -| HARM\_SEVERITY\_UNSUPPORTED | "HARM_SEVERITY_UNSUPPORTED" | Harm severity is not supported. The GoogleAI backend does not support HarmSeverity, so this value is used as a fallback. | +| HARM\_SEVERITY\_UNSUPPORTED | "HARM_SEVERITY_UNSUPPORTED" | Harm severity is not supported. | ## ImagenAspectRatio diff --git a/docs-devsite/vertexai.promptfeedback.md b/docs-devsite/vertexai.promptfeedback.md index 369ef02051d..0dca1b10072 100644 --- a/docs-devsite/vertexai.promptfeedback.md +++ b/docs-devsite/vertexai.promptfeedback.md @@ -23,7 +23,7 @@ export interface PromptFeedback | Property | Type | Description | | --- | --- | --- | | [blockReason](./vertexai.promptfeedback.md#promptfeedbackblockreason) | [BlockReason](./vertexai.md#blockreason) | | -| [blockReasonMessage](./vertexai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | | +| [blockReasonMessage](./vertexai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | This field is not supported in Google AI. | | [safetyRatings](./vertexai.promptfeedback.md#promptfeedbacksafetyratings) | [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface)\[\] | | ## PromptFeedback.blockReason @@ -36,6 +36,8 @@ blockReason?: BlockReason; ## PromptFeedback.blockReasonMessage +This field is not supported in Google AI. + Signature: ```typescript diff --git a/docs-devsite/vertexai.safetyrating.md b/docs-devsite/vertexai.safetyrating.md index 28493bafef0..34739830a60 100644 --- a/docs-devsite/vertexai.safetyrating.md +++ b/docs-devsite/vertexai.safetyrating.md @@ -25,9 +25,9 @@ export interface SafetyRating | [blocked](./vertexai.safetyrating.md#safetyratingblocked) | boolean | | | [category](./vertexai.safetyrating.md#safetyratingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | | [probability](./vertexai.safetyrating.md#safetyratingprobability) | [HarmProbability](./vertexai.md#harmprobability) | | -| [probabilityScore](./vertexai.safetyrating.md#safetyratingprobabilityscore) | number | | -| [severity](./vertexai.safetyrating.md#safetyratingseverity) | [HarmSeverity](./vertexai.md#harmseverity) | | -| [severityScore](./vertexai.safetyrating.md#safetyratingseverityscore) | number | | +| [probabilityScore](./vertexai.safetyrating.md#safetyratingprobabilityscore) | number | This field is not supported in Google AI, so it will default to 0 when using Google AI. | +| [severity](./vertexai.safetyrating.md#safetyratingseverity) | [HarmSeverity](./vertexai.md#harmseverity) | This field is not supported in Google AI, so it will default to HarmSeverity.UNSUPPORTED when using Google AI. | +| [severityScore](./vertexai.safetyrating.md#safetyratingseverityscore) | number | This field is not supported in Google AI, so it will default to 0 when using Google AI. | ## SafetyRating.blocked @@ -55,6 +55,8 @@ probability: HarmProbability; ## SafetyRating.probabilityScore +This field is not supported in Google AI, so it will default to 0 when using Google AI. + Signature: ```typescript @@ -63,6 +65,8 @@ probabilityScore: number; ## SafetyRating.severity +This field is not supported in Google AI, so it will default to `HarmSeverity.UNSUPPORTED` when using Google AI. + Signature: ```typescript @@ -71,6 +75,8 @@ severity: HarmSeverity; ## SafetyRating.severityScore +This field is not supported in Google AI, so it will default to 0 when using Google AI. + Signature: ```typescript diff --git a/docs-devsite/vertexai.vertexaibackend.md b/docs-devsite/vertexai.vertexaibackend.md new file mode 100644 index 00000000000..cd255e30034 --- /dev/null +++ b/docs-devsite/vertexai.vertexaibackend.md @@ -0,0 +1,58 @@ +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 %} + +# VertexAIBackend class +Represents the configuration class for the Vertex AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the server with [getAI()](./vertexai.md#getai_a94a413). + +Signature: + +```typescript +export declare class VertexAIBackend extends Backend +``` +Extends: [Backend](./vertexai.backend.md#backend_class) + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(location)](./vertexai.vertexaibackend.md#vertexaibackendconstructor) | | Creates a configuration object for the Vertex AI backend. | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [location](./vertexai.vertexaibackend.md#vertexaibackendlocation) | | string | The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations) for a list of supported locations. | + +## VertexAIBackend.(constructor) + +Creates a configuration object for the Vertex AI backend. + +Signature: + +```typescript +constructor(location?: string); +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| location | string | The region identifier, defaulting to us-central1; see [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations) for a list of supported locations. | + +## VertexAIBackend.location + +The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations) for a list of supported locations. + +Signature: + +```typescript +readonly location: string; +``` diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index ffa072f33d7..2dd67e0a15f 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -123,6 +123,8 @@ export enum HarmSeverity { HARM_SEVERITY_HIGH = 'HARM_SEVERITY_HIGH', /** * Harm severity is not supported. + * + * @remarks * The GoogleAI backend does not support `HarmSeverity`, so this value is used as a fallback. */ HARM_SEVERITY_UNSUPPORTED = 'HARM_SEVERITY_UNSUPPORTED' diff --git a/packages/vertexai/src/types/imagen/requests.ts b/packages/vertexai/src/types/imagen/requests.ts index d5bc3c31223..c5c54dc1e9a 100644 --- a/packages/vertexai/src/types/imagen/requests.ts +++ b/packages/vertexai/src/types/imagen/requests.ts @@ -58,6 +58,8 @@ export interface ImagenGenerationConfig { * Support for negative prompts depends on the Imagen model. * * See the {@link http://firebase.google.com/docs/vertex-ai/model-parameters#imagen | documentation} for more details. + * + * This is no longer supported in Google AI in versions greater than `imagen-3.0-generate-002`. */ negativePrompt?: string; /** @@ -89,7 +91,6 @@ export interface ImagenGenerationConfig { * For Imagen 3 models, the default value is `true`; see the addWatermark * documentation for more details. * - * @remarks * In Google AI, the default value is true, and it cannot be turned off. */ addWatermark?: boolean; diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index 33ed804bb9f..53c80efe67d 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -64,9 +64,8 @@ export interface SafetySetting { category: HarmCategory; threshold: HarmBlockThreshold; /** - * This property is not supported in Google AI. - * If this is a property on a {@link GenerateContentRequest} to be sent, an {@link AIError} - * will be thrown. + * This property is not supported in Google AI. If this is a property on a + * {@link GenerateContentRequest} to be sent, an {@link AIError} will be thrown. */ method?: HarmBlockMethod; } diff --git a/packages/vertexai/src/types/responses.ts b/packages/vertexai/src/types/responses.ts index 1822d8ade84..b6d325f47ea 100644 --- a/packages/vertexai/src/types/responses.ts +++ b/packages/vertexai/src/types/responses.ts @@ -109,7 +109,7 @@ export interface PromptFeedback { blockReason?: BlockReason; safetyRatings: SafetyRating[]; /** - * This field is unsupported in Google AI. + * This field is not supported in Google AI. */ blockReasonMessage?: string; } From 0e941107f39073927d90de0a6b82124c295fb7ed Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Thu, 24 Apr 2025 13:28:05 -0400 Subject: [PATCH 10/32] fix(vertexai): pass `GenerativeModel`'s `BaseParams` to `ChatSession` --- .../src/models/generative-model.test.ts | 29 +++++++++++++++++++ .../vertexai/src/models/generative-model.ts | 7 +++++ 2 files changed, 36 insertions(+) diff --git a/packages/vertexai/src/models/generative-model.test.ts b/packages/vertexai/src/models/generative-model.test.ts index 3ce7173e03e..2cdf108fb79 100644 --- a/packages/vertexai/src/models/generative-model.test.ts +++ b/packages/vertexai/src/models/generative-model.test.ts @@ -167,6 +167,35 @@ describe('GenerativeModel', () => { ); restore(); }); + it('passes base model params through to ChatSession when there are no startChatParams', async () => { + const genModel = new GenerativeModel(fakeVertexAI, { + model: 'my-model', + generationConfig: { + topK: 1 + } + }); + const chatSession = genModel.startChat(); + expect(chatSession.params?.generationConfig).to.deep.equal({ + topK: 1 + }); + restore(); + }); + it('overrides base model params with startChatParams', () => { + const genModel = new GenerativeModel(fakeVertexAI, { + model: 'my-model', + generationConfig: { + topK: 1 + } + }); + const chatSession = genModel.startChat({ + generationConfig: { + topK: 2 + } + }); + expect(chatSession.params?.generationConfig).to.deep.equal({ + topK: 2 + }); + }); it('passes params through to chat.sendMessage', async () => { const genModel = new GenerativeModel(fakeAI, { model: 'my-model', diff --git a/packages/vertexai/src/models/generative-model.ts b/packages/vertexai/src/models/generative-model.ts index 2e7ed93eeb8..9468cfc0745 100644 --- a/packages/vertexai/src/models/generative-model.ts +++ b/packages/vertexai/src/models/generative-model.ts @@ -132,6 +132,13 @@ export class GenerativeModel extends AIModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, + generationConfig: this.generationConfig, + safetySettings: this.safetySettings, + /** + * Overrides params inherited from GenerativeModel with those explicitly set in the + * StartChatParams. For example, if startChatParams.generationConfig is set, it'll override + * this.generationConfig. + */ ...startChatParams }, this.requestOptions From 15d969971b63a252e415741682e1ad467ef18b82 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Mon, 28 Apr 2025 12:03:10 -0400 Subject: [PATCH 11/32] Fix generative model tests to use fakeAI --- packages/vertexai/src/models/generative-model.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vertexai/src/models/generative-model.test.ts b/packages/vertexai/src/models/generative-model.test.ts index 2cdf108fb79..d5a846ceebf 100644 --- a/packages/vertexai/src/models/generative-model.test.ts +++ b/packages/vertexai/src/models/generative-model.test.ts @@ -168,7 +168,7 @@ describe('GenerativeModel', () => { restore(); }); it('passes base model params through to ChatSession when there are no startChatParams', async () => { - const genModel = new GenerativeModel(fakeVertexAI, { + const genModel = new GenerativeModel(fakeAI, { model: 'my-model', generationConfig: { topK: 1 @@ -181,7 +181,7 @@ describe('GenerativeModel', () => { restore(); }); it('overrides base model params with startChatParams', () => { - const genModel = new GenerativeModel(fakeVertexAI, { + const genModel = new GenerativeModel(fakeAI, { model: 'my-model', generationConfig: { topK: 1 From 6a1e02de315345ee1094c8050163644a2a2092cd Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 29 Apr 2025 15:06:04 -0400 Subject: [PATCH 12/32] Add `packages/firebase/ai` directory for legacy resolvers --- packages/firebase/ai/index.ts | 18 ++++++++++++++++++ packages/firebase/ai/package.json | 7 +++++++ packages/firebase/package.json | 1 + 3 files changed, 26 insertions(+) create mode 100644 packages/firebase/ai/index.ts create mode 100644 packages/firebase/ai/package.json diff --git a/packages/firebase/ai/index.ts b/packages/firebase/ai/index.ts new file mode 100644 index 00000000000..2645fd3004f --- /dev/null +++ b/packages/firebase/ai/index.ts @@ -0,0 +1,18 @@ +/** + * @license + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from '@firebase/vertexai'; diff --git a/packages/firebase/ai/package.json b/packages/firebase/ai/package.json new file mode 100644 index 00000000000..75405002478 --- /dev/null +++ b/packages/firebase/ai/package.json @@ -0,0 +1,7 @@ +{ + "name": "firebase/ai", + "main": "dist/index.cjs.js", + "browser": "dist/esm/index.esm.js", + "module": "dist/esm/index.esm.js", + "typings": "dist/vertexai/index.d.ts" +} \ No newline at end of file diff --git a/packages/firebase/package.json b/packages/firebase/package.json index e1609b07176..c874ff91f35 100644 --- a/packages/firebase/package.json +++ b/packages/firebase/package.json @@ -455,6 +455,7 @@ "rollup-plugin-license": "3.5.3" }, "components": [ + "ai", "analytics", "app", "app-check", From dbdb7626431ed72d1f0e44994d3627b119ba214d Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 29 Apr 2025 15:23:25 -0400 Subject: [PATCH 13/32] Cleanup docs --- common/api-review/firestore.api.md | 42 ++--- docs-devsite/_toc.yaml | 24 +-- docs-devsite/firestore_.md | 159 ++++++++++++++++-- .../firestore_.memorycachesettings.md | 35 ---- .../firestore_.memoryeagergarbagecollector.md | 37 ---- docs-devsite/firestore_.memorylocalcache.md | 35 ---- .../firestore_.memorylrugarbagecollector.md | 37 ---- .../firestore_.persistentcachesettings.md | 50 ------ .../firestore_.persistentlocalcache.md | 35 ---- ...firestore_.persistentmultipletabmanager.md | 33 ---- .../firestore_.persistentsingletabmanager.md | 33 ---- ...ore_.persistentsingletabmanagersettings.md | 35 ---- docs-devsite/vertexai.backend.md | 4 +- docs-devsite/vertexai.vertexaibackend.md | 6 +- packages/vertexai/.eslintrc.js | 3 +- packages/vertexai/src/backend.ts | 6 +- 16 files changed, 174 insertions(+), 400 deletions(-) delete mode 100644 docs-devsite/firestore_.memorycachesettings.md delete mode 100644 docs-devsite/firestore_.memoryeagergarbagecollector.md delete mode 100644 docs-devsite/firestore_.memorylocalcache.md delete mode 100644 docs-devsite/firestore_.memorylrugarbagecollector.md delete mode 100644 docs-devsite/firestore_.persistentcachesettings.md delete mode 100644 docs-devsite/firestore_.persistentlocalcache.md delete mode 100644 docs-devsite/firestore_.persistentmultipletabmanager.md delete mode 100644 docs-devsite/firestore_.persistentsingletabmanager.md delete mode 100644 docs-devsite/firestore_.persistentsingletabmanagersettings.md diff --git a/common/api-review/firestore.api.md b/common/api-review/firestore.api.md index 34b56b97f21..26c379a6e34 100644 --- a/common/api-review/firestore.api.md +++ b/common/api-review/firestore.api.md @@ -375,15 +375,14 @@ export interface LoadBundleTaskProgress { export { LogLevel } // @public -export interface MemoryCacheSettings { +export type MemoryCacheSettings = { garbageCollector?: MemoryGarbageCollector; -} +}; // @public -export interface MemoryEagerGarbageCollector { - // (undocumented) +export type MemoryEagerGarbageCollector = { kind: 'memoryEager'; -} +}; // @public export function memoryEagerGarbageCollector(): MemoryEagerGarbageCollector; @@ -392,19 +391,17 @@ export function memoryEagerGarbageCollector(): MemoryEagerGarbageCollector; export type MemoryGarbageCollector = MemoryEagerGarbageCollector | MemoryLruGarbageCollector; // @public -export interface MemoryLocalCache { - // (undocumented) +export type MemoryLocalCache = { kind: 'memory'; -} +}; // @public export function memoryLocalCache(settings?: MemoryCacheSettings): MemoryLocalCache; // @public -export interface MemoryLruGarbageCollector { - // (undocumented) +export type MemoryLruGarbageCollector = { kind: 'memoryLru'; -} +}; // @public export function memoryLruGarbageCollector(settings?: { @@ -494,42 +491,39 @@ export class PersistentCacheIndexManager { } // @public -export interface PersistentCacheSettings { +export type PersistentCacheSettings = { cacheSizeBytes?: number; tabManager?: PersistentTabManager; -} +}; // @public -export interface PersistentLocalCache { - // (undocumented) +export type PersistentLocalCache = { kind: 'persistent'; -} +}; // @public export function persistentLocalCache(settings?: PersistentCacheSettings): PersistentLocalCache; // @public -export interface PersistentMultipleTabManager { - // (undocumented) +export type PersistentMultipleTabManager = { kind: 'PersistentMultipleTab'; -} +}; // @public export function persistentMultipleTabManager(): PersistentMultipleTabManager; // @public -export interface PersistentSingleTabManager { - // (undocumented) +export type PersistentSingleTabManager = { kind: 'persistentSingleTab'; -} +}; // @public export function persistentSingleTabManager(settings: PersistentSingleTabManagerSettings | undefined): PersistentSingleTabManager; // @public -export interface PersistentSingleTabManagerSettings { +export type PersistentSingleTabManagerSettings = { forceOwnership?: boolean; -} +}; // @public export type PersistentTabManager = PersistentSingleTabManager | PersistentMultipleTabManager; diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index 03d6b5f6ec7..2bcb53bb047 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -245,28 +245,10 @@ toc: path: /docs/reference/js/firestore_.loadbundletask.md - title: LoadBundleTaskProgress path: /docs/reference/js/firestore_.loadbundletaskprogress.md - - title: MemoryCacheSettings - path: /docs/reference/js/firestore_.memorycachesettings.md - - title: MemoryEagerGarbageCollector - path: /docs/reference/js/firestore_.memoryeagergarbagecollector.md - - title: MemoryLocalCache - path: /docs/reference/js/firestore_.memorylocalcache.md - - title: MemoryLruGarbageCollector - path: /docs/reference/js/firestore_.memorylrugarbagecollector.md - title: PersistenceSettings path: /docs/reference/js/firestore_.persistencesettings.md - title: PersistentCacheIndexManager path: /docs/reference/js/firestore_.persistentcacheindexmanager.md - - title: PersistentCacheSettings - path: /docs/reference/js/firestore_.persistentcachesettings.md - - title: PersistentLocalCache - path: /docs/reference/js/firestore_.persistentlocalcache.md - - title: PersistentMultipleTabManager - path: /docs/reference/js/firestore_.persistentmultipletabmanager.md - - title: PersistentSingleTabManager - path: /docs/reference/js/firestore_.persistentsingletabmanager.md - - title: PersistentSingleTabManagerSettings - path: /docs/reference/js/firestore_.persistentsingletabmanagersettings.md - title: Query path: /docs/reference/js/firestore_.query.md - title: QueryCompositeFilterConstraint @@ -482,6 +464,8 @@ toc: path: /docs/reference/js/vertexai.aioptions.md - title: ArraySchema path: /docs/reference/js/vertexai.arrayschema.md + - title: Backend + path: /docs/reference/js/vertexai.backend.md - title: BaseParams path: /docs/reference/js/vertexai.baseparams.md - title: BooleanSchema @@ -540,6 +524,8 @@ toc: path: /docs/reference/js/vertexai.generativecontentblob.md - title: GenerativeModel path: /docs/reference/js/vertexai.generativemodel.md + - title: GoogleAIBackend + path: /docs/reference/js/vertexai.googleaibackend.md - title: GroundingAttribution path: /docs/reference/js/vertexai.groundingattribution.md - title: GroundingMetadata @@ -606,6 +592,8 @@ toc: path: /docs/reference/js/vertexai.toolconfig.md - title: UsageMetadata path: /docs/reference/js/vertexai.usagemetadata.md + - title: VertexAIBackend + path: /docs/reference/js/vertexai.vertexaibackend.md - title: VertexAIOptions path: /docs/reference/js/vertexai.vertexaioptions.md - title: VideoMetadata diff --git a/docs-devsite/firestore_.md b/docs-devsite/firestore_.md index 91d21e32708..7dfde135ab0 100644 --- a/docs-devsite/firestore_.md +++ b/docs-devsite/firestore_.md @@ -174,16 +174,7 @@ https://github.com/firebase/firebase-js-sdk | [IndexConfiguration](./firestore_.indexconfiguration.md#indexconfiguration_interface) | (Public Preview) A list of Firestore indexes to speed up local query execution.See [JSON Format](https://firebase.google.com/docs/reference/firestore/indexes/#json_format) for a description of the format of the index definition. | | [IndexField](./firestore_.indexfield.md#indexfield_interface) | (Public Preview) A single field element in an index configuration. | | [LoadBundleTaskProgress](./firestore_.loadbundletaskprogress.md#loadbundletaskprogress_interface) | Represents a progress update or a final state from loading bundles. | -| [MemoryCacheSettings](./firestore_.memorycachesettings.md#memorycachesettings_interface) | An settings object to configure an MemoryLocalCache instance. | -| [MemoryEagerGarbageCollector](./firestore_.memoryeagergarbagecollector.md#memoryeagergarbagecollector_interface) | A garbage collector deletes documents whenever they are not part of any active queries, and have no local mutations attached to them.This collector tries to ensure lowest memory footprints from the SDK, at the risk of documents not being cached for offline queries or for direct queries to the cache.Use factory function to create an instance of this collector. | -| [MemoryLocalCache](./firestore_.memorylocalcache.md#memorylocalcache_interface) | Provides an in-memory cache to the SDK. This is the default cache unless explicitly configured otherwise.To use, create an instance using the factory function , then set the instance to FirestoreSettings.cache and call initializeFirestore using the settings object. | -| [MemoryLruGarbageCollector](./firestore_.memorylrugarbagecollector.md#memorylrugarbagecollector_interface) | A garbage collector deletes Least-Recently-Used documents in multiple batches.This collector is configured with a target size, and will only perform collection when the cached documents exceed the target size. It avoids querying backend repeated for the same query or document, at the risk of having a larger memory footprint.Use factory function to create a instance of this collector. | | [PersistenceSettings](./firestore_.persistencesettings.md#persistencesettings_interface) | Settings that can be passed to enableIndexedDbPersistence() to configure Firestore persistence.Persistence cannot be used in a Node.js environment. | -| [PersistentCacheSettings](./firestore_.persistentcachesettings.md#persistentcachesettings_interface) | An settings object to configure an PersistentLocalCache instance.Persistent cache cannot be used in a Node.js environment. | -| [PersistentLocalCache](./firestore_.persistentlocalcache.md#persistentlocalcache_interface) | Provides a persistent cache backed by IndexedDb to the SDK.To use, create an instance using the factory function , then set the instance to FirestoreSettings.cache and call initializeFirestore using the settings object. | -| [PersistentMultipleTabManager](./firestore_.persistentmultipletabmanager.md#persistentmultipletabmanager_interface) | A tab manager supporting multiple tabs. SDK will synchronize queries and mutations done across all tabs using the SDK. | -| [PersistentSingleTabManager](./firestore_.persistentsingletabmanager.md#persistentsingletabmanager_interface) | A tab manager supporting only one tab, no synchronization will be performed across tabs. | -| [PersistentSingleTabManagerSettings](./firestore_.persistentsingletabmanagersettings.md#persistentsingletabmanagersettings_interface) | Type to configure an PersistentSingleTabManager instance. | | [SnapshotListenOptions](./firestore_.snapshotlistenoptions.md#snapshotlistenoptions_interface) | An options object that can be passed to [onSnapshot()](./firestore_.md#onsnapshot_0312fd7) and [QuerySnapshot.docChanges()](./firestore_.querysnapshot.md#querysnapshotdocchanges) to control which types of changes to include in the result set. | | [SnapshotOptions](./firestore_.snapshotoptions.md#snapshotoptions_interface) | Options that configure how data is retrieved from a DocumentSnapshot (for example the desired behavior for server timestamps that have not yet been set to their final value). | | [TransactionOptions](./firestore_.transactionoptions.md#transactionoptions_interface) | Options to customize transaction behavior. | @@ -208,10 +199,19 @@ https://github.com/firebase/firebase-js-sdk | [FirestoreErrorCode](./firestore_.md#firestoreerrorcode) | The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.mdPossible values: - 'cancelled': The operation was cancelled (typically by the caller). - 'unknown': Unknown error or an error from a different error domain. - 'invalid-argument': Client specified an invalid argument. Note that this differs from 'failed-precondition'. 'invalid-argument' indicates arguments that are problematic regardless of the state of the system (e.g. an invalid field name). - 'deadline-exceeded': Deadline expired before operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. - 'not-found': Some requested document was not found. - 'already-exists': Some document that we attempted to create already exists. - 'permission-denied': The caller does not have permission to execute the specified operation. - 'resource-exhausted': Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. - 'failed-precondition': Operation was rejected because the system is not in a state required for the operation's execution. - 'aborted': The operation was aborted, typically due to a concurrency issue like transaction aborts, etc. - 'out-of-range': Operation was attempted past the valid range. - 'unimplemented': Operation is not implemented or not supported/enabled. - 'internal': Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken. - 'unavailable': The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff. - 'data-loss': Unrecoverable data loss or corruption. - 'unauthenticated': The request does not have valid authentication credentials for the operation. | | [FirestoreLocalCache](./firestore_.md#firestorelocalcache) | Union type from all supported SDK cache layer. | | [ListenSource](./firestore_.md#listensource) | Describe the source a query listens to.Set to default to listen to both cache and server changes. Set to cache to listen to changes in cache only. | +| [MemoryCacheSettings](./firestore_.md#memorycachesettings) | An settings object to configure an MemoryLocalCache instance. | +| [MemoryEagerGarbageCollector](./firestore_.md#memoryeagergarbagecollector) | A garbage collector deletes documents whenever they are not part of any active queries, and have no local mutations attached to them.This collector tries to ensure lowest memory footprints from the SDK, at the risk of documents not being cached for offline queries or for direct queries to the cache.Use factory function to create an instance of this collector. | | [MemoryGarbageCollector](./firestore_.md#memorygarbagecollector) | Union type from all support garbage collectors for memory local cache. | +| [MemoryLocalCache](./firestore_.md#memorylocalcache) | Provides an in-memory cache to the SDK. This is the default cache unless explicitly configured otherwise.To use, create an instance using the factory function , then set the instance to FirestoreSettings.cache and call initializeFirestore using the settings object. | +| [MemoryLruGarbageCollector](./firestore_.md#memorylrugarbagecollector) | A garbage collector deletes Least-Recently-Used documents in multiple batches.This collector is configured with a target size, and will only perform collection when the cached documents exceed the target size. It avoids querying backend repeated for the same query or document, at the risk of having a larger memory footprint.Use factory function to create a instance of this collector. | | [NestedUpdateFields](./firestore_.md#nestedupdatefields) | For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1, 'bar.qux': T2}). Intersect them together to make a single map containing all possible keys that are all marked as optional | | [OrderByDirection](./firestore_.md#orderbydirection) | The direction of a [orderBy()](./firestore_.md#orderby_006d61f) clause is specified as 'desc' or 'asc' (descending or ascending). | | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue) | Similar to TypeScript's Partial<T>, but allows nested fields to be omitted and FieldValues to be passed in as property values. | +| [PersistentCacheSettings](./firestore_.md#persistentcachesettings) | An settings object to configure an PersistentLocalCache instance.Persistent cache cannot be used in a Node.js environment. | +| [PersistentLocalCache](./firestore_.md#persistentlocalcache) | Provides a persistent cache backed by IndexedDb to the SDK.To use, create an instance using the factory function , then set the instance to FirestoreSettings.cache and call initializeFirestore using the settings object. | +| [PersistentMultipleTabManager](./firestore_.md#persistentmultipletabmanager) | A tab manager supporting multiple tabs. SDK will synchronize queries and mutations done across all tabs using the SDK. | +| [PersistentSingleTabManager](./firestore_.md#persistentsingletabmanager) | A tab manager supporting only one tab, no synchronization will be performed across tabs. | +| [PersistentSingleTabManagerSettings](./firestore_.md#persistentsingletabmanagersettings) | Type to configure an PersistentSingleTabManager instance. | | [PersistentTabManager](./firestore_.md#persistenttabmanager) | A union of all available tab managers. | | [Primitive](./firestore_.md#primitive) | Primitive types. | | [QueryConstraintType](./firestore_.md#queryconstrainttype) | Describes the different query constraints available in this SDK. | @@ -924,7 +924,7 @@ export declare function memoryEagerGarbageCollector(): MemoryEagerGarbageCollect ``` Returns: -[MemoryEagerGarbageCollector](./firestore_.memoryeagergarbagecollector.md#memoryeagergarbagecollector_interface) +[MemoryEagerGarbageCollector](./firestore_.md#memoryeagergarbagecollector) ### persistentMultipleTabManager() {:#persistentmultipletabmanager} @@ -937,7 +937,7 @@ export declare function persistentMultipleTabManager(): PersistentMultipleTabMan ``` Returns: -[PersistentMultipleTabManager](./firestore_.persistentmultipletabmanager.md#persistentmultipletabmanager_interface) +[PersistentMultipleTabManager](./firestore_.md#persistentmultipletabmanager) ### serverTimestamp() {:#servertimestamp} @@ -2293,11 +2293,11 @@ export declare function memoryLocalCache(settings?: MemoryCacheSettings): Memory | Parameter | Type | Description | | --- | --- | --- | -| settings | [MemoryCacheSettings](./firestore_.memorycachesettings.md#memorycachesettings_interface) | | +| settings | [MemoryCacheSettings](./firestore_.md#memorycachesettings) | | Returns: -[MemoryLocalCache](./firestore_.memorylocalcache.md#memorylocalcache_interface) +[MemoryLocalCache](./firestore_.md#memorylocalcache) ### memoryLruGarbageCollector(settings) {:#memorylrugarbagecollector_5ee014c} @@ -2321,7 +2321,7 @@ export declare function memoryLruGarbageCollector(settings?: { Returns: -[MemoryLruGarbageCollector](./firestore_.memorylrugarbagecollector.md#memorylrugarbagecollector_interface) +[MemoryLruGarbageCollector](./firestore_.md#memorylrugarbagecollector) ### persistentLocalCache(settings) {:#persistentlocalcache_d312f71} @@ -2339,11 +2339,11 @@ export declare function persistentLocalCache(settings?: PersistentCacheSettings) | Parameter | Type | Description | | --- | --- | --- | -| settings | [PersistentCacheSettings](./firestore_.persistentcachesettings.md#persistentcachesettings_interface) | | +| settings | [PersistentCacheSettings](./firestore_.md#persistentcachesettings) | | Returns: -[PersistentLocalCache](./firestore_.persistentlocalcache.md#persistentlocalcache_interface) +[PersistentLocalCache](./firestore_.md#persistentlocalcache) ### persistentSingleTabManager(settings) {:#persistentsingletabmanager_c99c68d} @@ -2359,11 +2359,11 @@ export declare function persistentSingleTabManager(settings: PersistentSingleTab | Parameter | Type | Description | | --- | --- | --- | -| settings | [PersistentSingleTabManagerSettings](./firestore_.persistentsingletabmanagersettings.md#persistentsingletabmanagersettings_interface) \| undefined | Configures the created tab manager. | +| settings | [PersistentSingleTabManagerSettings](./firestore_.md#persistentsingletabmanagersettings) \| undefined | Configures the created tab manager. | Returns: -[PersistentSingleTabManager](./firestore_.persistentsingletabmanager.md#persistentsingletabmanager_interface) +[PersistentSingleTabManager](./firestore_.md#persistentsingletabmanager) ## function(snapshot, ...) @@ -2591,6 +2591,34 @@ Set to `default` to listen to both cache and server changes. Set to `cache` to l export declare type ListenSource = 'default' | 'cache'; ``` +## MemoryCacheSettings + +An settings object to configure an `MemoryLocalCache` instance. + +Signature: + +```typescript +export declare type MemoryCacheSettings = { + garbageCollector?: MemoryGarbageCollector; +}; +``` + +## MemoryEagerGarbageCollector + +A garbage collector deletes documents whenever they are not part of any active queries, and have no local mutations attached to them. + +This collector tries to ensure lowest memory footprints from the SDK, at the risk of documents not being cached for offline queries or for direct queries to the cache. + +Use factory function to create an instance of this collector. + +Signature: + +```typescript +export declare type MemoryEagerGarbageCollector = { + kind: 'memoryEager'; +}; +``` + ## MemoryGarbageCollector Union type from all support garbage collectors for memory local cache. @@ -2601,6 +2629,36 @@ Union type from all support garbage collectors for memory local cache. export declare type MemoryGarbageCollector = MemoryEagerGarbageCollector | MemoryLruGarbageCollector; ``` +## MemoryLocalCache + +Provides an in-memory cache to the SDK. This is the default cache unless explicitly configured otherwise. + +To use, create an instance using the factory function , then set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using the settings object. + +Signature: + +```typescript +export declare type MemoryLocalCache = { + kind: 'memory'; +}; +``` + +## MemoryLruGarbageCollector + +A garbage collector deletes Least-Recently-Used documents in multiple batches. + +This collector is configured with a target size, and will only perform collection when the cached documents exceed the target size. It avoids querying backend repeated for the same query or document, at the risk of having a larger memory footprint. + +Use factory function to create a instance of this collector. + +Signature: + +```typescript +export declare type MemoryLruGarbageCollector = { + kind: 'memoryLru'; +}; +``` + ## NestedUpdateFields For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1, 'bar.qux': T2}). Intersect them together to make a single map containing all possible keys that are all marked as optional @@ -2635,6 +2693,71 @@ export declare type PartialWithFieldValue = Partial | (T extends Primitive } : never); ``` +## PersistentCacheSettings + +An settings object to configure an `PersistentLocalCache` instance. + +Persistent cache cannot be used in a Node.js environment. + +Signature: + +```typescript +export declare type PersistentCacheSettings = { + cacheSizeBytes?: number; + tabManager?: PersistentTabManager; +}; +``` + +## PersistentLocalCache + +Provides a persistent cache backed by IndexedDb to the SDK. + +To use, create an instance using the factory function , then set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using the settings object. + +Signature: + +```typescript +export declare type PersistentLocalCache = { + kind: 'persistent'; +}; +``` + +## PersistentMultipleTabManager + +A tab manager supporting multiple tabs. SDK will synchronize queries and mutations done across all tabs using the SDK. + +Signature: + +```typescript +export declare type PersistentMultipleTabManager = { + kind: 'PersistentMultipleTab'; +}; +``` + +## PersistentSingleTabManager + +A tab manager supporting only one tab, no synchronization will be performed across tabs. + +Signature: + +```typescript +export declare type PersistentSingleTabManager = { + kind: 'persistentSingleTab'; +}; +``` + +## PersistentSingleTabManagerSettings + +Type to configure an `PersistentSingleTabManager` instance. + +Signature: + +```typescript +export declare type PersistentSingleTabManagerSettings = { + forceOwnership?: boolean; +}; +``` + ## PersistentTabManager A union of all available tab managers. diff --git a/docs-devsite/firestore_.memorycachesettings.md b/docs-devsite/firestore_.memorycachesettings.md deleted file mode 100644 index 69f46acdf7c..00000000000 --- a/docs-devsite/firestore_.memorycachesettings.md +++ /dev/null @@ -1,35 +0,0 @@ -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 %} - -# MemoryCacheSettings interface -An settings object to configure an `MemoryLocalCache` instance. - -Signature: - -```typescript -export declare interface MemoryCacheSettings -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [garbageCollector](./firestore_.memorycachesettings.md#memorycachesettingsgarbagecollector) | [MemoryGarbageCollector](./firestore_.md#memorygarbagecollector) | The garbage collector to use, for the memory cache layer. A MemoryEagerGarbageCollector is used when this is undefined. | - -## MemoryCacheSettings.garbageCollector - -The garbage collector to use, for the memory cache layer. A `MemoryEagerGarbageCollector` is used when this is undefined. - -Signature: - -```typescript -garbageCollector?: MemoryGarbageCollector; -``` diff --git a/docs-devsite/firestore_.memoryeagergarbagecollector.md b/docs-devsite/firestore_.memoryeagergarbagecollector.md deleted file mode 100644 index 01e7341611a..00000000000 --- a/docs-devsite/firestore_.memoryeagergarbagecollector.md +++ /dev/null @@ -1,37 +0,0 @@ -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 %} - -# MemoryEagerGarbageCollector interface -A garbage collector deletes documents whenever they are not part of any active queries, and have no local mutations attached to them. - -This collector tries to ensure lowest memory footprints from the SDK, at the risk of documents not being cached for offline queries or for direct queries to the cache. - -Use factory function to create an instance of this collector. - -Signature: - -```typescript -export declare interface MemoryEagerGarbageCollector -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [kind](./firestore_.memoryeagergarbagecollector.md#memoryeagergarbagecollectorkind) | 'memoryEager' | | - -## MemoryEagerGarbageCollector.kind - -Signature: - -```typescript -kind: 'memoryEager'; -``` diff --git a/docs-devsite/firestore_.memorylocalcache.md b/docs-devsite/firestore_.memorylocalcache.md deleted file mode 100644 index 92b7d3a2c72..00000000000 --- a/docs-devsite/firestore_.memorylocalcache.md +++ /dev/null @@ -1,35 +0,0 @@ -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 %} - -# MemoryLocalCache interface -Provides an in-memory cache to the SDK. This is the default cache unless explicitly configured otherwise. - -To use, create an instance using the factory function , then set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using the settings object. - -Signature: - -```typescript -export declare interface MemoryLocalCache -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [kind](./firestore_.memorylocalcache.md#memorylocalcachekind) | 'memory' | | - -## MemoryLocalCache.kind - -Signature: - -```typescript -kind: 'memory'; -``` diff --git a/docs-devsite/firestore_.memorylrugarbagecollector.md b/docs-devsite/firestore_.memorylrugarbagecollector.md deleted file mode 100644 index 6e15513934a..00000000000 --- a/docs-devsite/firestore_.memorylrugarbagecollector.md +++ /dev/null @@ -1,37 +0,0 @@ -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 %} - -# MemoryLruGarbageCollector interface -A garbage collector deletes Least-Recently-Used documents in multiple batches. - -This collector is configured with a target size, and will only perform collection when the cached documents exceed the target size. It avoids querying backend repeated for the same query or document, at the risk of having a larger memory footprint. - -Use factory function to create a instance of this collector. - -Signature: - -```typescript -export declare interface MemoryLruGarbageCollector -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [kind](./firestore_.memorylrugarbagecollector.md#memorylrugarbagecollectorkind) | 'memoryLru' | | - -## MemoryLruGarbageCollector.kind - -Signature: - -```typescript -kind: 'memoryLru'; -``` diff --git a/docs-devsite/firestore_.persistentcachesettings.md b/docs-devsite/firestore_.persistentcachesettings.md deleted file mode 100644 index a32d05e4e8e..00000000000 --- a/docs-devsite/firestore_.persistentcachesettings.md +++ /dev/null @@ -1,50 +0,0 @@ -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 %} - -# PersistentCacheSettings interface -An settings object to configure an `PersistentLocalCache` instance. - -Persistent cache cannot be used in a Node.js environment. - -Signature: - -```typescript -export declare interface PersistentCacheSettings -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [cacheSizeBytes](./firestore_.persistentcachesettings.md#persistentcachesettingscachesizebytes) | number | An approximate cache size threshold for the on-disk data. If the cache grows beyond this size, Firestore will start removing data that hasn't been recently used. The SDK does not guarantee that the cache will stay below that size, only that if the cache exceeds the given size, cleanup will be attempted.The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to CACHE_SIZE_UNLIMITED to disable garbage collection. | -| [tabManager](./firestore_.persistentcachesettings.md#persistentcachesettingstabmanager) | [PersistentTabManager](./firestore_.md#persistenttabmanager) | Specifies how multiple tabs/windows will be managed by the SDK. | - -## PersistentCacheSettings.cacheSizeBytes - -An approximate cache size threshold for the on-disk data. If the cache grows beyond this size, Firestore will start removing data that hasn't been recently used. The SDK does not guarantee that the cache will stay below that size, only that if the cache exceeds the given size, cleanup will be attempted. - -The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to `CACHE_SIZE_UNLIMITED` to disable garbage collection. - -Signature: - -```typescript -cacheSizeBytes?: number; -``` - -## PersistentCacheSettings.tabManager - -Specifies how multiple tabs/windows will be managed by the SDK. - -Signature: - -```typescript -tabManager?: PersistentTabManager; -``` diff --git a/docs-devsite/firestore_.persistentlocalcache.md b/docs-devsite/firestore_.persistentlocalcache.md deleted file mode 100644 index 48d876d15bd..00000000000 --- a/docs-devsite/firestore_.persistentlocalcache.md +++ /dev/null @@ -1,35 +0,0 @@ -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 %} - -# PersistentLocalCache interface -Provides a persistent cache backed by IndexedDb to the SDK. - -To use, create an instance using the factory function , then set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using the settings object. - -Signature: - -```typescript -export declare interface PersistentLocalCache -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [kind](./firestore_.persistentlocalcache.md#persistentlocalcachekind) | 'persistent' | | - -## PersistentLocalCache.kind - -Signature: - -```typescript -kind: 'persistent'; -``` diff --git a/docs-devsite/firestore_.persistentmultipletabmanager.md b/docs-devsite/firestore_.persistentmultipletabmanager.md deleted file mode 100644 index 20d9cc24452..00000000000 --- a/docs-devsite/firestore_.persistentmultipletabmanager.md +++ /dev/null @@ -1,33 +0,0 @@ -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 %} - -# PersistentMultipleTabManager interface -A tab manager supporting multiple tabs. SDK will synchronize queries and mutations done across all tabs using the SDK. - -Signature: - -```typescript -export declare interface PersistentMultipleTabManager -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [kind](./firestore_.persistentmultipletabmanager.md#persistentmultipletabmanagerkind) | 'PersistentMultipleTab' | | - -## PersistentMultipleTabManager.kind - -Signature: - -```typescript -kind: 'PersistentMultipleTab'; -``` diff --git a/docs-devsite/firestore_.persistentsingletabmanager.md b/docs-devsite/firestore_.persistentsingletabmanager.md deleted file mode 100644 index 22601cf31fb..00000000000 --- a/docs-devsite/firestore_.persistentsingletabmanager.md +++ /dev/null @@ -1,33 +0,0 @@ -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 %} - -# PersistentSingleTabManager interface -A tab manager supporting only one tab, no synchronization will be performed across tabs. - -Signature: - -```typescript -export declare interface PersistentSingleTabManager -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [kind](./firestore_.persistentsingletabmanager.md#persistentsingletabmanagerkind) | 'persistentSingleTab' | | - -## PersistentSingleTabManager.kind - -Signature: - -```typescript -kind: 'persistentSingleTab'; -``` diff --git a/docs-devsite/firestore_.persistentsingletabmanagersettings.md b/docs-devsite/firestore_.persistentsingletabmanagersettings.md deleted file mode 100644 index afe2842d4c4..00000000000 --- a/docs-devsite/firestore_.persistentsingletabmanagersettings.md +++ /dev/null @@ -1,35 +0,0 @@ -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 %} - -# PersistentSingleTabManagerSettings interface -Type to configure an `PersistentSingleTabManager` instance. - -Signature: - -```typescript -export declare interface PersistentSingleTabManagerSettings -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [forceOwnership](./firestore_.persistentsingletabmanagersettings.md#persistentsingletabmanagersettingsforceownership) | boolean | Whether to force-enable persistent (IndexedDB) cache for the client. This cannot be used with multi-tab synchronization and is primarily intended for use with Web Workers. Setting this to true will enable IndexedDB, but cause other tabs using IndexedDB cache to fail. | - -## PersistentSingleTabManagerSettings.forceOwnership - -Whether to force-enable persistent (IndexedDB) cache for the client. This cannot be used with multi-tab synchronization and is primarily intended for use with Web Workers. Setting this to `true` will enable IndexedDB, but cause other tabs using IndexedDB cache to fail. - -Signature: - -```typescript -forceOwnership?: boolean; -``` diff --git a/docs-devsite/vertexai.backend.md b/docs-devsite/vertexai.backend.md index b55224f5205..a1d54b5ea16 100644 --- a/docs-devsite/vertexai.backend.md +++ b/docs-devsite/vertexai.backend.md @@ -28,7 +28,7 @@ export declare abstract class Backend | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [backendType](./vertexai.backend.md#backendbackendtype) | | [BackendType](./vertexai.md#backendtype) | Specifies the backend type (either 'GOOGLE\_AI' or 'VERTEX\_AI'). | +| [backendType](./vertexai.backend.md#backendbackendtype) | | [BackendType](./vertexai.md#backendtype) | Specifies the backend type. | ## Backend.(constructor) @@ -48,7 +48,7 @@ protected constructor(type: BackendType); ## Backend.backendType -Specifies the backend type (either 'GOOGLE\_AI' or 'VERTEX\_AI'). +Specifies the backend type. Signature: diff --git a/docs-devsite/vertexai.vertexaibackend.md b/docs-devsite/vertexai.vertexaibackend.md index cd255e30034..38a369fe425 100644 --- a/docs-devsite/vertexai.vertexaibackend.md +++ b/docs-devsite/vertexai.vertexaibackend.md @@ -29,7 +29,7 @@ export declare class VertexAIBackend extends Backend | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [location](./vertexai.vertexaibackend.md#vertexaibackendlocation) | | string | The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations) for a list of supported locations. | +| [location](./vertexai.vertexaibackend.md#vertexaibackendlocation) | | string | The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations) for a list of supported locations. | ## VertexAIBackend.(constructor) @@ -45,11 +45,11 @@ constructor(location?: string); | Parameter | Type | Description | | --- | --- | --- | -| location | string | The region identifier, defaulting to us-central1; see [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations) for a list of supported locations. | +| location | string | The region identifier, defaulting to us-central1; see [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations) for a list of supported locations. | ## VertexAIBackend.location -The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations) for a list of supported locations. +The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations) for a list of supported locations. Signature: diff --git a/packages/vertexai/.eslintrc.js b/packages/vertexai/.eslintrc.js index dbc1d5aa33c..1e8712b0633 100644 --- a/packages/vertexai/.eslintrc.js +++ b/packages/vertexai/.eslintrc.js @@ -30,7 +30,6 @@ module.exports = { { 'packageDir': [path.resolve(__dirname, '../../'), __dirname] } - ], - '@typescript-eslint/consistent-type-definitions': 0 + ] } }; diff --git a/packages/vertexai/src/backend.ts b/packages/vertexai/src/backend.ts index cb80c158b8a..2e0b3bfef5e 100644 --- a/packages/vertexai/src/backend.ts +++ b/packages/vertexai/src/backend.ts @@ -27,7 +27,7 @@ import { BackendType } from './public-types'; */ export abstract class Backend { /** - * Specifies the backend type (either 'GOOGLE_AI' or 'VERTEX_AI'). + * Specifies the backend type. */ readonly backendType: BackendType; @@ -66,7 +66,7 @@ export class GoogleAIBackend extends Backend { export class VertexAIBackend extends Backend { /** * The region identifier. - * See {@link https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations | Vertex AI locations} + * See {@link https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations | Vertex AI locations} * for a list of supported locations. */ readonly location: string; @@ -75,7 +75,7 @@ export class VertexAIBackend extends Backend { * Creates a configuration object for the Vertex AI backend. * * @param location - The region identifier, defaulting to `us-central1`; - * see {@link https://firebase.google.com/docs/vertex-ai/locations?platform=ios#available-locations | Vertex AI locations} + * see {@link https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations | Vertex AI locations} * for a list of supported locations. */ constructor(location: string = DEFAULT_LOCATION) { From 41b038540a3b7bc5e39742ccc56056bcf6bcf12d Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Date: Tue, 29 Apr 2025 18:52:25 -0400 Subject: [PATCH 14/32] [vertexai] Use json of unary-success-citations (#8981) * [vertexai] Use json of unary-success-citations The test files have been updated to include `json` extension versions of the tests files. The old, `txt` extension files are deprecated and will be deleted eventually. * Update also the version used in the update script --- packages/vertexai/src/googleai-mappers.test.ts | 2 +- scripts/update_vertexai_responses.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vertexai/src/googleai-mappers.test.ts b/packages/vertexai/src/googleai-mappers.test.ts index 9c3bb0f9241..7aa30ebb73f 100644 --- a/packages/vertexai/src/googleai-mappers.test.ts +++ b/packages/vertexai/src/googleai-mappers.test.ts @@ -131,7 +131,7 @@ describe('Google AI Mappers', () => { describe('mapGenerateContentResponse', () => { it('should map a full Google AI response', async () => { const googleAIMockResponse: GoogleAIGenerateContentResponse = await ( - getMockResponse('googleAI', 'unary-success-citations.txt') as Response + getMockResponse('googleAI', 'unary-success-citations.json') as Response ).json(); const mappedResponse = mapGenerateContentResponse(googleAIMockResponse); diff --git a/scripts/update_vertexai_responses.sh b/scripts/update_vertexai_responses.sh index bf55a645a66..d80959febce 100755 --- a/scripts/update_vertexai_responses.sh +++ b/scripts/update_vertexai_responses.sh @@ -17,7 +17,7 @@ # This script replaces mock response files for Vertex AI unit tests with a fresh # clone of the shared repository of Vertex AI test data. -RESPONSES_VERSION='v10.*' # The major version of mock responses to use +RESPONSES_VERSION='v11.*' # The major version of mock responses to use REPO_NAME="vertexai-sdk-test-data" REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git" From 1d3b922e78e525fdad15bcb91d5aa8918645680f Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Wed, 30 Apr 2025 10:15:41 -0400 Subject: [PATCH 15/32] Use default location if location is empty string --- packages/vertexai/src/backend.test.ts | 4 ++-- packages/vertexai/src/backend.ts | 2 +- packages/vertexai/src/helpers.test.ts | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/vertexai/src/backend.test.ts b/packages/vertexai/src/backend.test.ts index ec754bd41f0..0c6609277e3 100644 --- a/packages/vertexai/src/backend.test.ts +++ b/packages/vertexai/src/backend.test.ts @@ -38,10 +38,10 @@ describe('Backend', () => { expect(backend.backendType).to.equal(BackendType.VERTEX_AI); expect(backend.location).to.equal('test-location'); }); - it('sets custom location even if empty string', () => { + it('uses default location if location is empty string', () => { const backend = new VertexAIBackend(''); expect(backend.backendType).to.equal(BackendType.VERTEX_AI); - expect(backend.location).to.equal(''); + expect(backend.location).to.equal(DEFAULT_LOCATION); }); it('uses default location if location is null', () => { const backend = new VertexAIBackend(null as any); diff --git a/packages/vertexai/src/backend.ts b/packages/vertexai/src/backend.ts index 2e0b3bfef5e..a1cf0214ad3 100644 --- a/packages/vertexai/src/backend.ts +++ b/packages/vertexai/src/backend.ts @@ -80,7 +80,7 @@ export class VertexAIBackend extends Backend { */ constructor(location: string = DEFAULT_LOCATION) { super(BackendType.VERTEX_AI); - if (location === null) { + if (!location) { this.location = DEFAULT_LOCATION; } else { this.location = location; diff --git a/packages/vertexai/src/helpers.test.ts b/packages/vertexai/src/helpers.test.ts index 533edf79e5f..92981911fbc 100644 --- a/packages/vertexai/src/helpers.test.ts +++ b/packages/vertexai/src/helpers.test.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { expect } from 'chai'; -import { AI_TYPE } from './constants'; +import { AI_TYPE, DEFAULT_LOCATION } from './constants'; import { encodeInstanceIdentifier, decodeInstanceIdentifier } from './helpers'; import { AIError } from './errors'; import { AIErrorCode } from './types'; @@ -24,14 +24,14 @@ import { GoogleAIBackend, VertexAIBackend } from './backend'; describe('Identifier Encoding/Decoding', () => { describe('encodeInstanceIdentifier', () => { it('should encode Vertex AI identifier with a specific location', () => { - const backend = new VertexAIBackend('us-central1'); - const expected = `${AI_TYPE}/vertexai/us-central1`; + const backend = new VertexAIBackend('us-east1'); + const expected = `${AI_TYPE}/vertexai/us-east1`; expect(encodeInstanceIdentifier(backend)).to.equal(expected); }); - it('should encode Vertex AI identifier using empty location', () => { + it('should encode Vertex AI identifier using default location if location is empty string', () => { const backend = new VertexAIBackend(''); - const expected = `${AI_TYPE}/vertexai/`; + const expected = `${AI_TYPE}/vertexai/${DEFAULT_LOCATION}`; expect(encodeInstanceIdentifier(backend)).to.equal(expected); }); From 4b6ab32891de8abc6afb913aab420486f5a6937d Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Thu, 1 May 2025 15:16:51 -0400 Subject: [PATCH 16/32] Replace 'vertexAI' error prefix with 'AI' --- packages/vertexai/src/api.test.ts | 33 ++++++++++++++------------- packages/vertexai/src/errors.ts | 7 +++--- packages/vertexai/src/helpers.test.ts | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index 0554ff46441..27237b4edd3 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -21,6 +21,7 @@ import { expect } from 'chai'; import { AI } from './public-types'; import { GenerativeModel } from './models/generative-model'; import { VertexAIBackend } from './backend'; +import { AI_TYPE } from './constants'; const fakeAI: AI = { app: { @@ -43,8 +44,8 @@ describe('Top level API', () => { } catch (e) { expect((e as AIError).code).includes(AIErrorCode.NO_MODEL); expect((e as AIError).message).includes( - `VertexAI: Must provide a model name. Example: ` + - `getGenerativeModel({ model: 'my-model-name' }) (vertexAI/${AIErrorCode.NO_MODEL})` + `AI: Must provide a model name. Example: ` + + `getGenerativeModel({ model: 'my-model-name' }) (${AI_TYPE}/${AIErrorCode.NO_MODEL})` ); } }); @@ -58,9 +59,9 @@ describe('Top level API', () => { } catch (e) { expect((e as AIError).code).includes(AIErrorCode.NO_API_KEY); expect((e as AIError).message).equals( - `VertexAI: The "apiKey" field is empty in the local ` + + `AI: The "apiKey" field is empty in the local ` + `Firebase config. Firebase AI requires this field to` + - ` contain a valid API key. (vertexAI/${AIErrorCode.NO_API_KEY})` + ` contain a valid API key. (${AI_TYPE}/${AIErrorCode.NO_API_KEY})` ); } }); @@ -74,9 +75,9 @@ describe('Top level API', () => { } catch (e) { expect((e as AIError).code).includes(AIErrorCode.NO_PROJECT_ID); expect((e as AIError).message).equals( - `VertexAI: The "projectId" field is empty in the local` + + `AI: The "projectId" field is empty in the local` + ` Firebase config. Firebase AI requires this field ` + - `to contain a valid project ID. (vertexAI/${AIErrorCode.NO_PROJECT_ID})` + `to contain a valid project ID. (${AI_TYPE}/${AIErrorCode.NO_PROJECT_ID})` ); } }); @@ -90,9 +91,9 @@ describe('Top level API', () => { } catch (e) { expect((e as AIError).code).includes(AIErrorCode.NO_APP_ID); expect((e as AIError).message).equals( - `VertexAI: The "appId" field is empty in the local` + + `AI: The "appId" field is empty in the local` + ` Firebase config. Firebase AI requires this field ` + - `to contain a valid app ID. (vertexAI/${AIErrorCode.NO_APP_ID})` + `to contain a valid app ID. (${AI_TYPE}/${AIErrorCode.NO_APP_ID})` ); } }); @@ -107,8 +108,8 @@ describe('Top level API', () => { } catch (e) { expect((e as AIError).code).includes(AIErrorCode.NO_MODEL); expect((e as AIError).message).includes( - `VertexAI: Must provide a model name. Example: ` + - `getImagenModel({ model: 'my-model-name' }) (vertexAI/${AIErrorCode.NO_MODEL})` + `AI: Must provide a model name. Example: ` + + `getImagenModel({ model: 'my-model-name' }) (${AI_TYPE}/${AIErrorCode.NO_MODEL})` ); } }); @@ -122,9 +123,9 @@ describe('Top level API', () => { } catch (e) { expect((e as AIError).code).includes(AIErrorCode.NO_API_KEY); expect((e as AIError).message).equals( - `VertexAI: The "apiKey" field is empty in the local ` + + `AI: The "apiKey" field is empty in the local ` + `Firebase config. Firebase AI requires this field to` + - ` contain a valid API key. (vertexAI/${AIErrorCode.NO_API_KEY})` + ` contain a valid API key. (${AI_TYPE}/${AIErrorCode.NO_API_KEY})` ); } }); @@ -138,9 +139,9 @@ describe('Top level API', () => { } catch (e) { expect((e as AIError).code).includes(AIErrorCode.NO_PROJECT_ID); expect((e as AIError).message).equals( - `VertexAI: The "projectId" field is empty in the local` + + `AI: The "projectId" field is empty in the local` + ` Firebase config. Firebase AI requires this field ` + - `to contain a valid project ID. (vertexAI/${AIErrorCode.NO_PROJECT_ID})` + `to contain a valid project ID. (${AI_TYPE}/${AIErrorCode.NO_PROJECT_ID})` ); } }); @@ -154,9 +155,9 @@ describe('Top level API', () => { } catch (e) { expect((e as AIError).code).includes(AIErrorCode.NO_APP_ID); expect((e as AIError).message).equals( - `VertexAI: The "appId" field is empty in the local` + + `AI: The "appId" field is empty in the local` + ` Firebase config. Firebase AI requires this field ` + - `to contain a valid app ID. (vertexAI/${AIErrorCode.NO_APP_ID})` + `to contain a valid app ID. (${AI_TYPE}/${AIErrorCode.NO_APP_ID})` ); } }); diff --git a/packages/vertexai/src/errors.ts b/packages/vertexai/src/errors.ts index 1746b815042..2e9787d0bf2 100644 --- a/packages/vertexai/src/errors.ts +++ b/packages/vertexai/src/errors.ts @@ -17,7 +17,7 @@ import { FirebaseError } from '@firebase/util'; import { AIErrorCode, CustomErrorData } from './types'; -import { VERTEX_TYPE } from './constants'; +import { AI_TYPE } from './constants'; /** * Error class for the Firebase AI SDK. @@ -38,10 +38,9 @@ export class AIError extends FirebaseError { readonly customErrorData?: CustomErrorData ) { // Match error format used by FirebaseError from ErrorFactory - const service = VERTEX_TYPE; // TODO (v12): Rename to GENAI_TYPE on breaking release. - const serviceName = 'VertexAI'; // TODO (v12): Rename to AI on breaking release. + const service = AI_TYPE; const fullCode = `${service}/${code}`; - const fullMessage = `${serviceName}: ${message} (${fullCode})`; + const fullMessage = `${service}: ${message} (${fullCode})`; super(code, fullMessage); // FirebaseError initializes a stack trace, but it assumes the error is created from the error diff --git a/packages/vertexai/src/helpers.test.ts b/packages/vertexai/src/helpers.test.ts index 92981911fbc..8f5f164d6b8 100644 --- a/packages/vertexai/src/helpers.test.ts +++ b/packages/vertexai/src/helpers.test.ts @@ -110,7 +110,7 @@ describe('Identifier Encoding/Decoding', () => { }); it('should throw AIError for malformed identifier string (incorrect prefix)', () => { - const encoded = 'firebase/vertexai/location'; + const encoded = 'firebase/AI/location'; // This will also hit the default case in the switch statement expect(() => decodeInstanceIdentifier(encoded)).to.throw( AIError, From 1a41a921d5eadf175ff029a8cde05219ea5d93e0 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 2 May 2025 14:51:02 -0400 Subject: [PATCH 17/32] Use Gemini Developer API and Gemini API in Vertex AI naming in docs --- docs-devsite/vertexai.ai.md | 4 +-- docs-devsite/vertexai.aimodel.md | 2 ++ docs-devsite/vertexai.aioptions.md | 2 +- docs-devsite/vertexai.backend.md | 2 +- docs-devsite/vertexai.citation.md | 12 ++++--- docs-devsite/vertexai.counttokensresponse.md | 4 +-- docs-devsite/vertexai.googleaibackend.md | 4 ++- .../vertexai.imagengenerationconfig.md | 8 ++--- docs-devsite/vertexai.md | 28 ++++++++--------- docs-devsite/vertexai.promptfeedback.md | 6 ++-- docs-devsite/vertexai.safetyrating.md | 18 +++++++---- docs-devsite/vertexai.safetysetting.md | 6 ++-- docs-devsite/vertexai.schemashared.md | 4 +-- docs-devsite/vertexai.vertexaibackend.md | 10 +++--- packages/vertexai/src/api.ts | 13 +++++--- packages/vertexai/src/backend.ts | 26 +++++++++------- .../vertexai/src/googleai-mappers.test.ts | 2 +- packages/vertexai/src/googleai-mappers.ts | 18 +++++------ .../{genai-model.test.ts => ai-model.test.ts} | 2 +- .../models/{genai-model.ts => ai-model.ts} | 4 +++ .../vertexai/src/models/generative-model.ts | 2 +- packages/vertexai/src/models/imagen-model.ts | 2 +- packages/vertexai/src/models/index.ts | 2 +- packages/vertexai/src/public-types.ts | 15 ++++++--- packages/vertexai/src/types/enums.ts | 2 +- .../vertexai/src/types/imagen/requests.ts | 6 ++-- packages/vertexai/src/types/requests.ts | 7 +++-- packages/vertexai/src/types/responses.ts | 31 ++++++++++++++----- packages/vertexai/src/types/schema.ts | 4 +-- 29 files changed, 151 insertions(+), 95 deletions(-) rename packages/vertexai/src/models/{genai-model.test.ts => ai-model.test.ts} (98%) rename packages/vertexai/src/models/{genai-model.ts => ai-model.ts} (95%) diff --git a/docs-devsite/vertexai.ai.md b/docs-devsite/vertexai.ai.md index 3be9ea5d488..1db78d7b7ff 100644 --- a/docs-devsite/vertexai.ai.md +++ b/docs-devsite/vertexai.ai.md @@ -25,7 +25,7 @@ export interface AI | Property | Type | Description | | --- | --- | --- | | [app](./vertexai.ai.md#aiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./vertexai.ai.md#ai_interface) instance is associated with. | -| [backend](./vertexai.ai.md#aibackend) | [Backend](./vertexai.backend.md#backend_class) | A [Backend](./vertexai.backend.md#backend_class) instance that specifies the backend configuration. | +| [backend](./vertexai.ai.md#aibackend) | [Backend](./vertexai.backend.md#backend_class) | A [Backend](./vertexai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) or the Gemini API in Vertex AI (using [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | | [location](./vertexai.ai.md#ailocation) | string | The location configured for this AI service instance, relevant for Vertex AI backends. | ## AI.app @@ -40,7 +40,7 @@ app: FirebaseApp; ## AI.backend -A [Backend](./vertexai.backend.md#backend_class) instance that specifies the backend configuration. +A [Backend](./vertexai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) or the Gemini API in Vertex AI (using [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.aimodel.md b/docs-devsite/vertexai.aimodel.md index ee142d27c47..5cea0c435bb 100644 --- a/docs-devsite/vertexai.aimodel.md +++ b/docs-devsite/vertexai.aimodel.md @@ -12,6 +12,8 @@ https://github.com/firebase/firebase-js-sdk # AIModel class Base class for Firebase AI model APIs. +Instances of this class are associated with a specific Firebase AI backend (either the Gemini API in Vertex AI or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. + The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `AIModel` class. Signature: diff --git a/docs-devsite/vertexai.aioptions.md b/docs-devsite/vertexai.aioptions.md index 393a83b3f9c..d75a4a45d10 100644 --- a/docs-devsite/vertexai.aioptions.md +++ b/docs-devsite/vertexai.aioptions.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # AIOptions interface -Options interface for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). +Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Gemini API in Vertex AI or Gemini Developer API) and configuring its specific options (like location for Vertex AI). Signature: diff --git a/docs-devsite/vertexai.backend.md b/docs-devsite/vertexai.backend.md index a1d54b5ea16..3ec2d43e565 100644 --- a/docs-devsite/vertexai.backend.md +++ b/docs-devsite/vertexai.backend.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # Backend class -Abstract base class representing the configuration for an AI service backend. This class should not be instantiated directly. Use its subclasses [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class). +Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Gemini API in Vertex AI. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Gemini API in Vertex AI. Signature: diff --git a/docs-devsite/vertexai.citation.md b/docs-devsite/vertexai.citation.md index f2e4e2581cb..36df6c91d0c 100644 --- a/docs-devsite/vertexai.citation.md +++ b/docs-devsite/vertexai.citation.md @@ -24,9 +24,9 @@ export interface Citation | --- | --- | --- | | [endIndex](./vertexai.citation.md#citationendindex) | number | | | [license](./vertexai.citation.md#citationlicense) | string | | -| [publicationDate](./vertexai.citation.md#citationpublicationdate) | Date | This field is not supported in Google AI. | +| [publicationDate](./vertexai.citation.md#citationpublicationdate) | Date | The publication date of the cited source, if available.This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | | [startIndex](./vertexai.citation.md#citationstartindex) | number | | -| [title](./vertexai.citation.md#citationtitle) | string | This field is not supported in Google AI. | +| [title](./vertexai.citation.md#citationtitle) | string | The title of the cited source, if available.This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | | [uri](./vertexai.citation.md#citationuri) | string | | ## Citation.endIndex @@ -47,7 +47,9 @@ license?: string; ## Citation.publicationDate -This field is not supported in Google AI. +The publication date of the cited source, if available. + +This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). Signature: @@ -65,7 +67,9 @@ startIndex?: number; ## Citation.title -This field is not supported in Google AI. +The title of the cited source, if available. + +This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.counttokensresponse.md b/docs-devsite/vertexai.counttokensresponse.md index dab373586b4..df32b78e231 100644 --- a/docs-devsite/vertexai.counttokensresponse.md +++ b/docs-devsite/vertexai.counttokensresponse.md @@ -23,7 +23,7 @@ export interface CountTokensResponse | Property | Type | Description | | --- | --- | --- | | [promptTokensDetails](./vertexai.counttokensresponse.md#counttokensresponseprompttokensdetails) | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface)\[\] | The breakdown, by modality, of how many tokens are consumed by the prompt. | -| [totalBillableCharacters](./vertexai.counttokensresponse.md#counttokensresponsetotalbillablecharacters) | number | The total number of billable characters counted across all instances from the request.This field is not supported in Google AI, so it will default to 0 when using Google AI. | +| [totalBillableCharacters](./vertexai.counttokensresponse.md#counttokensresponsetotalbillablecharacters) | number | The total number of billable characters counted across all instances from the request.This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | | [totalTokens](./vertexai.counttokensresponse.md#counttokensresponsetotaltokens) | number | The total number of tokens counted across all instances from the request. | ## CountTokensResponse.promptTokensDetails @@ -40,7 +40,7 @@ promptTokensDetails?: ModalityTokenCount[]; The total number of billable characters counted across all instances from the request. -This field is not supported in Google AI, so it will default to 0 when using Google AI. +This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. Signature: diff --git a/docs-devsite/vertexai.googleaibackend.md b/docs-devsite/vertexai.googleaibackend.md index 99e9bd18a14..79b115f78cd 100644 --- a/docs-devsite/vertexai.googleaibackend.md +++ b/docs-devsite/vertexai.googleaibackend.md @@ -10,7 +10,9 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # GoogleAIBackend class -Represents the configuration class for the Google AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the service with [getAI()](./vertexai.md#getai_a94a413). +Configuration class for the Gemini Developer API (using Google AI). + +Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini Developer API as the backend. Signature: diff --git a/docs-devsite/vertexai.imagengenerationconfig.md b/docs-devsite/vertexai.imagengenerationconfig.md index ac30cf4020a..51a66b147dc 100644 --- a/docs-devsite/vertexai.imagengenerationconfig.md +++ b/docs-devsite/vertexai.imagengenerationconfig.md @@ -27,10 +27,10 @@ export interface ImagenGenerationConfig | Property | Type | Description | | --- | --- | --- | -| [addWatermark](./vertexai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | (Public Preview) Whether to add an invisible watermark to generated images.If set to true, an invisible SynthID watermark is embedded in generated images to indicate that they are AI generated. If set to false, watermarking will be disabled.For Imagen 3 models, the default value is true; see the addWatermark documentation for more details.In Google AI, the default value is true, and it cannot be turned off. | +| [addWatermark](./vertexai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | (Public Preview) Whether to add an invisible watermark to generated images.If set to true, an invisible SynthID watermark is embedded in generated images to indicate that they are AI generated. If set to false, watermarking will be disabled.For Imagen 3 models, the default value is true; see the addWatermark documentation for more details.When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this will default to true, and cannot be turned off. | | [aspectRatio](./vertexai.imagengenerationconfig.md#imagengenerationconfigaspectratio) | [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | (Public Preview) The aspect ratio of the generated images. The default value is square 1:1. Supported aspect ratios depend on the Imagen model, see [ImagenAspectRatio](./vertexai.md#imagenaspectratio) for more details. | | [imageFormat](./vertexai.imagengenerationconfig.md#imagengenerationconfigimageformat) | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) The image format of the generated images. The default is PNG.See [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) for more details. | -| [negativePrompt](./vertexai.imagengenerationconfig.md#imagengenerationconfignegativeprompt) | string | (Public Preview) A description of what should be omitted from the generated images.Support for negative prompts depends on the Imagen model.See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details.This is no longer supported in Google AI in versions greater than imagen-3.0-generate-002. | +| [negativePrompt](./vertexai.imagengenerationconfig.md#imagengenerationconfignegativeprompt) | string | (Public Preview) A description of what should be omitted from the generated images.Support for negative prompts depends on the Imagen model.See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details.This is no longer supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) in versions greater than imagen-3.0-generate-002. | | [numberOfImages](./vertexai.imagengenerationconfig.md#imagengenerationconfignumberofimages) | number | (Public Preview) The number of images to generate. The default value is 1.The number of sample images that may be generated in each request depends on the model (typically up to 4); see the sampleCount documentation for more details. | ## ImagenGenerationConfig.addWatermark @@ -44,7 +44,7 @@ If set to `true`, an invisible SynthID watermark is embedded in generate For Imagen 3 models, the default value is `true`; see the addWatermark documentation for more details. -In Google AI, the default value is true, and it cannot be turned off. +When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this will default to true, and cannot be turned off. Signature: @@ -91,7 +91,7 @@ Support for negative prompts depends on the Imagen model. See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details. -This is no longer supported in Google AI in versions greater than `imagen-3.0-generate-002`. +This is no longer supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) in versions greater than `imagen-3.0-generate-002`. Signature: diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index 0b17e1b2732..bb6863ce5f0 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -18,7 +18,7 @@ The Firebase AI Web SDK. | --- | --- | | function(app, ...) | | [getAI(app, options)](./vertexai.md#getai_a94a413) | Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | -| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413).Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app. | +| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413).Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Gemini API in Vertex AI. This instance will be configured to use the Gemini API in Vertex AI. | | function(ai, ...) | | [getGenerativeModel(ai, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | | [getImagenModel(ai, modelParams, requestOptions)](./vertexai.md#getimagenmodel_e1f6645) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | @@ -28,13 +28,13 @@ The Firebase AI Web SDK. | Class | Description | | --- | --- | | [AIError](./vertexai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. | -| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs. | +| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.Instances of this class are associated with a specific Firebase AI backend (either the Gemini API in Vertex AI or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. | | [ArraySchema](./vertexai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | -| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend. This class should not be instantiated directly. Use its subclasses [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class). | +| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Gemini API in Vertex AI. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Gemini API in Vertex AI. | | [BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | | [ChatSession](./vertexai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | | [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | -| [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) | Represents the configuration class for the Google AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the service with [getAI()](./vertexai.md#getai_a94a413). | +| [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) | Configuration class for the Gemini Developer API (using Google AI).Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini Developer API as the backend. | | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) Defines the image format for images generated by Imagen.Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface). | | [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) | (Public Preview) Class for Imagen model APIs.This class provides methods for generating images using the Imagen model. | | [IntegerSchema](./vertexai.integerschema.md#integerschema_class) | Schema class for "integer" types. | @@ -42,7 +42,7 @@ The Firebase AI Web SDK. | [ObjectSchema](./vertexai.objectschema.md#objectschema_class) | Schema class for "object" types. The properties param must be a map of Schema objects. | | [Schema](./vertexai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with JSON.stringify() into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) | | [StringSchema](./vertexai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. | -| [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) | Represents the configuration class for the Vertex AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the server with [getAI()](./vertexai.md#getai_a94a413). | +| [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Gemini API in Vertex AI.Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini API in Vertex AI as the backend. | ## Enumerations @@ -52,7 +52,7 @@ The Firebase AI Web SDK. | [BlockReason](./vertexai.md#blockreason) | Reason that a prompt was blocked. | | [FinishReason](./vertexai.md#finishreason) | Reason that a candidate finished. | | [FunctionCallingMode](./vertexai.md#functioncallingmode) | | -| [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in Google AI. | +| [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)). | | [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | | [HarmCategory](./vertexai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | | [HarmProbability](./vertexai.md#harmprobability) | Probability that a prompt or candidate matches a harm category. | @@ -68,7 +68,7 @@ The Firebase AI Web SDK. | Interface | Description | | --- | --- | | [AI](./vertexai.ai.md#ai_interface) | An instance of the Firebase AI SDK.Do not create this instance directly. Instead, use [getAI()](./vertexai.md#getai_a94a413). | -| [AIOptions](./vertexai.aioptions.md#aioptions_interface) | Options interface for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). | +| [AIOptions](./vertexai.aioptions.md#aioptions_interface) | Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Gemini API in Vertex AI or Gemini Developer API) and configuring its specific options (like location for Vertex AI). | | [BaseParams](./vertexai.baseparams.md#baseparams_interface) | Base parameters for a number of methods. | | [Citation](./vertexai.citation.md#citation_interface) | A single citation. | | [CitationMetadata](./vertexai.citationmetadata.md#citationmetadata_interface) | Citation metadata that may be found on a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface). | @@ -129,7 +129,7 @@ The Firebase AI Web SDK. | Variable | Description | | --- | --- | -| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | +| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Gemini API in Vertex AI or Gemini Developer API) the SDK will communicate with.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | | [POSSIBLE\_ROLES](./vertexai.md#possible_roles) | Possible roles. | | [VertexAIError](./vertexai.md#vertexaierror) | Error class for the Firebase AI SDK.For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). | | [VertexAIModel](./vertexai.md#vertexaimodel) | Base class for Firebase AI model APIs.For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). | @@ -182,7 +182,7 @@ const ai = getAI(app); ```javascript -// Get an AI instance configured to use Google AI. +// Get an AI instance configured to use the Gemini Developer API (via Google AI). const ai = getAI(app, { backend: new GoogleAIBackend() }); ``` @@ -191,7 +191,7 @@ const ai = getAI(app, { backend: new GoogleAIBackend() }); ```javascript -// Get an AI instance configured to use Vertex AI. +// Get an AI instance configured to use the Gemini API in Vertex AI. const ai = getAI(app, { backend: new VertexAIBackend() }); ``` @@ -200,7 +200,7 @@ const ai = getAI(app, { backend: new VertexAIBackend() }); It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413). -Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app. +Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Gemini API in Vertex AI. This instance will be configured to use the Gemini API in Vertex AI. Signature: @@ -213,7 +213,7 @@ export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions | Parameter | Type | Description | | --- | --- | --- | | app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | -| options | [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | | +| options | [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | Options to configure the Vertex AI instance, including the location. | Returns: @@ -276,7 +276,7 @@ If the `apiKey` or `projectId` fields are missing in your Firebase config. ## BackendType -An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. +An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Gemini API in Vertex AI or Gemini Developer API) the SDK will communicate with. These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. @@ -475,7 +475,7 @@ export declare enum FunctionCallingMode ## HarmBlockMethod -This property is not supported in Google AI. +This property is not supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.promptfeedback.md b/docs-devsite/vertexai.promptfeedback.md index 0dca1b10072..574c30a8306 100644 --- a/docs-devsite/vertexai.promptfeedback.md +++ b/docs-devsite/vertexai.promptfeedback.md @@ -23,7 +23,7 @@ export interface PromptFeedback | Property | Type | Description | | --- | --- | --- | | [blockReason](./vertexai.promptfeedback.md#promptfeedbackblockreason) | [BlockReason](./vertexai.md#blockreason) | | -| [blockReasonMessage](./vertexai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | This field is not supported in Google AI. | +| [blockReasonMessage](./vertexai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | A human-readable description of the blockReason.This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | | [safetyRatings](./vertexai.promptfeedback.md#promptfeedbacksafetyratings) | [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface)\[\] | | ## PromptFeedback.blockReason @@ -36,7 +36,9 @@ blockReason?: BlockReason; ## PromptFeedback.blockReasonMessage -This field is not supported in Google AI. +A human-readable description of the `blockReason`. + +This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.safetyrating.md b/docs-devsite/vertexai.safetyrating.md index 34739830a60..d8f762c977d 100644 --- a/docs-devsite/vertexai.safetyrating.md +++ b/docs-devsite/vertexai.safetyrating.md @@ -25,9 +25,9 @@ export interface SafetyRating | [blocked](./vertexai.safetyrating.md#safetyratingblocked) | boolean | | | [category](./vertexai.safetyrating.md#safetyratingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | | [probability](./vertexai.safetyrating.md#safetyratingprobability) | [HarmProbability](./vertexai.md#harmprobability) | | -| [probabilityScore](./vertexai.safetyrating.md#safetyratingprobabilityscore) | number | This field is not supported in Google AI, so it will default to 0 when using Google AI. | -| [severity](./vertexai.safetyrating.md#safetyratingseverity) | [HarmSeverity](./vertexai.md#harmseverity) | This field is not supported in Google AI, so it will default to HarmSeverity.UNSUPPORTED when using Google AI. | -| [severityScore](./vertexai.safetyrating.md#safetyratingseverityscore) | number | This field is not supported in Google AI, so it will default to 0 when using Google AI. | +| [probabilityScore](./vertexai.safetyrating.md#safetyratingprobabilityscore) | number | The probability score of the harm category.This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | +| [severity](./vertexai.safetyrating.md#safetyratingseverity) | [HarmSeverity](./vertexai.md#harmseverity) | The harm severity level.This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to HarmSeverity.UNSUPPORTED. | +| [severityScore](./vertexai.safetyrating.md#safetyratingseverityscore) | number | The severity score of the harm category.This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | ## SafetyRating.blocked @@ -55,7 +55,9 @@ probability: HarmProbability; ## SafetyRating.probabilityScore -This field is not supported in Google AI, so it will default to 0 when using Google AI. +The probability score of the harm category. + +This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. Signature: @@ -65,7 +67,9 @@ probabilityScore: number; ## SafetyRating.severity -This field is not supported in Google AI, so it will default to `HarmSeverity.UNSUPPORTED` when using Google AI. +The harm severity level. + +This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`. Signature: @@ -75,7 +79,9 @@ severity: HarmSeverity; ## SafetyRating.severityScore -This field is not supported in Google AI, so it will default to 0 when using Google AI. +The severity score of the harm category. + +This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. Signature: diff --git a/docs-devsite/vertexai.safetysetting.md b/docs-devsite/vertexai.safetysetting.md index 92f98e3c02a..c4589d5c526 100644 --- a/docs-devsite/vertexai.safetysetting.md +++ b/docs-devsite/vertexai.safetysetting.md @@ -23,7 +23,7 @@ export interface SafetySetting | Property | Type | Description | | --- | --- | --- | | [category](./vertexai.safetysetting.md#safetysettingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | -| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in Google AI. If this is a property on a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) to be sent, an [AIError](./vertexai.aierror.md#aierror_class) will be thrown. | +| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | The harm block method.This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), an [AIError](./vertexai.aierror.md#aierror_class) will be thrown if this property is defined. | | [threshold](./vertexai.safetysetting.md#safetysettingthreshold) | [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | | ## SafetySetting.category @@ -36,7 +36,9 @@ category: HarmCategory; ## SafetySetting.method -This property is not supported in Google AI. If this is a property on a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) to be sent, an [AIError](./vertexai.aierror.md#aierror_class) will be thrown. +The harm block method. + +This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), an [AIError](./vertexai.aierror.md#aierror_class) will be thrown if this property is defined. Signature: diff --git a/docs-devsite/vertexai.schemashared.md b/docs-devsite/vertexai.schemashared.md index 90956b93606..4fdf8941438 100644 --- a/docs-devsite/vertexai.schemashared.md +++ b/docs-devsite/vertexai.schemashared.md @@ -25,7 +25,7 @@ export interface SchemaShared | [description](./vertexai.schemashared.md#schemashareddescription) | string | Optional. The description of the property. | | [enum](./vertexai.schemashared.md#schemasharedenum) | string\[\] | Optional. The enum of the property. | | [example](./vertexai.schemashared.md#schemasharedexample) | unknown | Optional. The example of the property. | -| [format](./vertexai.schemashared.md#schemasharedformat) | string | Optional. The format of the property. When using the Google AI backend, this must be either 'enum' or 'date-time', otherwise requests will fail. | +| [format](./vertexai.schemashared.md#schemasharedformat) | string | Optional. The format of the property. When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this must be either 'enum' or 'date-time', otherwise requests will fail. | | [items](./vertexai.schemashared.md#schemashareditems) | T | Optional. The items of the property. | | [nullable](./vertexai.schemashared.md#schemasharednullable) | boolean | Optional. Whether the property is nullable. | | [properties](./vertexai.schemashared.md#schemasharedproperties) | { \[k: string\]: T; } | Optional. Map of Schema objects. | @@ -62,7 +62,7 @@ example?: unknown; ## SchemaShared.format -Optional. The format of the property. When using the Google AI backend, this must be either `'enum'` or `'date-time'`, otherwise requests will fail. +Optional. The format of the property. When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this must be either `'enum'` or `'date-time'`, otherwise requests will fail. Signature: diff --git a/docs-devsite/vertexai.vertexaibackend.md b/docs-devsite/vertexai.vertexaibackend.md index 38a369fe425..3dbba80af6e 100644 --- a/docs-devsite/vertexai.vertexaibackend.md +++ b/docs-devsite/vertexai.vertexaibackend.md @@ -10,7 +10,9 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # VertexAIBackend class -Represents the configuration class for the Vertex AI backend. Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the server with [getAI()](./vertexai.md#getai_a94a413). +Configuration class for the Gemini API in Vertex AI. + +Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini API in Vertex AI as the backend. Signature: @@ -29,7 +31,7 @@ export declare class VertexAIBackend extends Backend | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [location](./vertexai.vertexaibackend.md#vertexaibackendlocation) | | string | The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations) for a list of supported locations. | +| [location](./vertexai.vertexaibackend.md#vertexaibackendlocation) | | string | The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations#available-locations) for a list of supported locations. | ## VertexAIBackend.(constructor) @@ -45,11 +47,11 @@ constructor(location?: string); | Parameter | Type | Description | | --- | --- | --- | -| location | string | The region identifier, defaulting to us-central1; see [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations) for a list of supported locations. | +| location | string | The region identifier, defaulting to us-central1; see [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations#available-locations) for a list of supported locations. | ## VertexAIBackend.location -The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations) for a list of supported locations. +The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations#available-locations) for a list of supported locations. Signature: diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index 4f0c407e397..e31cda79849 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -67,11 +67,14 @@ declare module '@firebase/component' { /** * It is recommended to use the new {@link getAI | getAI()}. * - * Returns a {@link VertexAI} instance for the given app. - * - * @public + * Returns a {@link VertexAI} instance for the given app, configured to use the + * Gemini API in Vertex AI. This instance will be + * configured to use the Gemini API in Vertex AI. * * @param app - The {@link @firebase/app#FirebaseApp} to use. + * @param options - Options to configure the Vertex AI instance, including the location. + * + * @public */ export function getVertexAI( app: FirebaseApp = getApp(), @@ -100,13 +103,13 @@ export function getVertexAI( * * @example * ```javascript - * // Get an AI instance configured to use Google AI. + * // Get an AI instance configured to use the Gemini Developer API (via Google AI). * const ai = getAI(app, { backend: new GoogleAIBackend() }); * ``` * * @example * ```javascript - * // Get an AI instance configured to use Vertex AI. + * // Get an AI instance configured to use the Gemini API in Vertex AI. * const ai = getAI(app, { backend: new VertexAIBackend() }); * ``` * diff --git a/packages/vertexai/src/backend.ts b/packages/vertexai/src/backend.ts index a1cf0214ad3..f19800e1686 100644 --- a/packages/vertexai/src/backend.ts +++ b/packages/vertexai/src/backend.ts @@ -19,9 +19,11 @@ import { DEFAULT_LOCATION } from './constants'; import { BackendType } from './public-types'; /** - * Abstract base class representing the configuration for an AI service backend. - * This class should not be instantiated directly. Use its subclasses - * {@link GoogleAIBackend} or {@link VertexAIBackend}. + * Abstract base class representing the configuration for an AI service backend, + * determining whether to use the Gemini Developer API (via Google AI) or the Gemini API in Vertex AI. + * This class should not be instantiated directly. Use its subclasses: + * - {@link GoogleAIBackend}: For the Gemini Developer API (via Google AI). + * - {@link VertexAIBackend}: For the Gemini API in Vertex AI. * * @public */ @@ -41,9 +43,10 @@ export abstract class Backend { } /** - * Represents the configuration class for the Google AI backend. - * Use this with {@link AIOptions} when initializing the service with - * {@link getAI | getAI()}. + * Configuration class for the Gemini Developer API (using Google AI). + * + * Use this with {@link AIOptions} when initializing the AI service via + * {@link getAI | getAI()} to specify the Gemini Developer API as the backend. * * @public */ @@ -57,16 +60,17 @@ export class GoogleAIBackend extends Backend { } /** - * Represents the configuration class for the Vertex AI backend. - * Use this with {@link AIOptions} when initializing the server with - * {@link getAI | getAI() }. + * Configuration class for the Gemini API in Vertex AI. + * + * Use this with {@link AIOptions} when initializing the AI service via + * {@link getAI | getAI()} to specify the Gemini API in Vertex AI as the backend. * * @public */ export class VertexAIBackend extends Backend { /** * The region identifier. - * See {@link https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations | Vertex AI locations} + * See {@link https://firebase.google.com/docs/vertex-ai/locations#available-locations | Vertex AI locations} * for a list of supported locations. */ readonly location: string; @@ -75,7 +79,7 @@ export class VertexAIBackend extends Backend { * Creates a configuration object for the Vertex AI backend. * * @param location - The region identifier, defaulting to `us-central1`; - * see {@link https://firebase.google.com/docs/vertex-ai/locations?platform=web#available-locations | Vertex AI locations} + * see {@link https://firebase.google.com/docs/vertex-ai/locations#available-locations | Vertex AI locations} * for a list of supported locations. */ constructor(location: string = DEFAULT_LOCATION) { diff --git a/packages/vertexai/src/googleai-mappers.test.ts b/packages/vertexai/src/googleai-mappers.test.ts index 7aa30ebb73f..12f422625f5 100644 --- a/packages/vertexai/src/googleai-mappers.test.ts +++ b/packages/vertexai/src/googleai-mappers.test.ts @@ -92,7 +92,7 @@ describe('Google AI Mappers', () => { }; const mappedRequest = mapGenerateContentRequest(request); expect(loggerWarnStub).to.have.been.calledOnceWith( - 'topK in GenerationConfig has been rounded to the nearest integer to match the format for Google AI requests.' + 'topK in GenerationConfig has been rounded to the nearest integer to match the format for requests to the Gemini Developer API.' ); expect(mappedRequest.generationConfig?.topK).to.equal(16); }); diff --git a/packages/vertexai/src/googleai-mappers.ts b/packages/vertexai/src/googleai-mappers.ts index 405dbd8d8c9..413e08b9955 100644 --- a/packages/vertexai/src/googleai-mappers.ts +++ b/packages/vertexai/src/googleai-mappers.ts @@ -36,15 +36,15 @@ import { } from './types/googleai'; /** - * This SDK supports both Vertex AI and Google AI APIs. - * The public API prioritizes the Vertex AI API. + * This SDK supports both the Gemini API in Vertex AI and the Gemini Developer API (using Google AI). + * The public API prioritizes the format used by the Gemini API in Vertex AI. * We avoid having two sets of types by translating requests and responses between the two API formats. - * We want to avoid two sets of types so that developers can switch between Vertex AI and Google AI - * with minimal changes to their code. + * This translation allows developers to switch between the Gemini API in Vertex AI and the Gemini Developer API + * with minimal code changes. * * In here are functions that map requests and responses between the two API formats. - * VertexAI requests defined by the user are mapped to Google AI requests before they're sent. - * Google AI responses are mapped to VertexAI responses so they can be returned to the user. + * Requests in the Vertex AI format are mapped to the Google AI format before being sent. + * Responses from the Google AI backend are mapped back to the Vertex AI format before being returned to the user. */ /** @@ -64,7 +64,7 @@ export function mapGenerateContentRequest( if (safetySetting.method) { throw new AIError( AIErrorCode.UNSUPPORTED, - 'SafetySetting.method is not supported in the Google AI. Please remove this property.' + 'SafetySetting.method is not supported in the the Gemini Developer API. Please remove this property.' ); } }); @@ -76,7 +76,7 @@ export function mapGenerateContentRequest( if (roundedTopK !== generateContentRequest.generationConfig.topK) { logger.warn( - 'topK in GenerationConfig has been rounded to the nearest integer to match the format for Google AI requests.' + 'topK in GenerationConfig has been rounded to the nearest integer to match the format for requests to the Gemini Developer API.' ); generateContentRequest.generationConfig.topK = roundedTopK; } @@ -182,7 +182,7 @@ export function mapGenerateContentCandidates( ) { throw new AIError( AIErrorCode.UNSUPPORTED, - 'Part.videoMetadata is not supported in Google AI. Please remove this property.' + 'Part.videoMetadata is not supported in the Gemini Developer API. Please remove this property.' ); } diff --git a/packages/vertexai/src/models/genai-model.test.ts b/packages/vertexai/src/models/ai-model.test.ts similarity index 98% rename from packages/vertexai/src/models/genai-model.test.ts rename to packages/vertexai/src/models/ai-model.test.ts index 229220d7a2a..4f23fe9d06f 100644 --- a/packages/vertexai/src/models/genai-model.test.ts +++ b/packages/vertexai/src/models/ai-model.test.ts @@ -17,7 +17,7 @@ import { use, expect } from 'chai'; import { AI, AIErrorCode } from '../public-types'; import sinonChai from 'sinon-chai'; -import { AIModel } from './genai-model'; +import { AIModel } from './ai-model'; import { AIError } from '../errors'; import { VertexAIBackend } from '../backend'; diff --git a/packages/vertexai/src/models/genai-model.ts b/packages/vertexai/src/models/ai-model.ts similarity index 95% rename from packages/vertexai/src/models/genai-model.ts rename to packages/vertexai/src/models/ai-model.ts index e059ff58530..1a982c25d36 100644 --- a/packages/vertexai/src/models/genai-model.ts +++ b/packages/vertexai/src/models/ai-model.ts @@ -24,6 +24,10 @@ import { _isFirebaseServerApp } from '@firebase/app'; /** * Base class for Firebase AI model APIs. * + * Instances of this class are associated with a specific Firebase AI backend + * (either the Gemini API in Vertex AI or the Gemini Developer API via Google AI) + * and provide methods for interacting with the configured generative model. + * * @public */ export abstract class AIModel { diff --git a/packages/vertexai/src/models/generative-model.ts b/packages/vertexai/src/models/generative-model.ts index 9468cfc0745..b09a9290aa4 100644 --- a/packages/vertexai/src/models/generative-model.ts +++ b/packages/vertexai/src/models/generative-model.ts @@ -42,7 +42,7 @@ import { formatSystemInstruction } from '../requests/request-helpers'; import { AI } from '../public-types'; -import { AIModel } from './genai-model'; +import { AIModel } from './ai-model'; /** * Class for generative model APIs. diff --git a/packages/vertexai/src/models/imagen-model.ts b/packages/vertexai/src/models/imagen-model.ts index 070b1d064ec..3c76a1c721c 100644 --- a/packages/vertexai/src/models/imagen-model.ts +++ b/packages/vertexai/src/models/imagen-model.ts @@ -28,7 +28,7 @@ import { ImagenGenerationResponse, ImagenSafetySettings } from '../types'; -import { AIModel } from './genai-model'; +import { AIModel } from './ai-model'; /** * Class for Imagen model APIs. diff --git a/packages/vertexai/src/models/index.ts b/packages/vertexai/src/models/index.ts index 3034aadedc8..cb694a5360b 100644 --- a/packages/vertexai/src/models/index.ts +++ b/packages/vertexai/src/models/index.ts @@ -15,6 +15,6 @@ * limitations under the License. */ -export * from './genai-model'; +export * from './ai-model'; export * from './generative-model'; export * from './imagen-model'; diff --git a/packages/vertexai/src/public-types.ts b/packages/vertexai/src/public-types.ts index 6d51c6d38c2..99acd64316f 100644 --- a/packages/vertexai/src/public-types.ts +++ b/packages/vertexai/src/public-types.ts @@ -51,7 +51,9 @@ export interface AI { */ app: FirebaseApp; /** - * A {@link Backend} instance that specifies the backend configuration. + * A {@link Backend} instance that specifies the configuration for the target backend, + * either the Gemini Developer API (using {@link GoogleAIBackend}) or the + * Gemini API in Vertex AI (using {@link VertexAIBackend}). */ backend: Backend; /** @@ -65,6 +67,8 @@ export interface AI { /** * An enum-like object containing constants that represent the supported backends * for the Firebase AI SDK. + * This determines which backend service (Gemini API in Vertex AI or Gemini Developer API) + * the SDK will communicate with. * * These values are assigned to the `backendType` property within the specific backend * configuration objects ({@link GoogleAIBackend} or {@link VertexAIBackend}) to identify @@ -74,14 +78,13 @@ export interface AI { */ export const BackendType = { /** - * Identifies the Vertex AI backend service provided through Google Cloud. + * Identifies the backend service for the Gemini API in Vertex AI provided through Google Cloud. * Use this constant when creating a {@link VertexAIBackend} configuration. */ VERTEX_AI: 'VERTEX_AI', /** - * Identifies the Google AI backend service (often associated with models available - * through Google AI Studio, like Gemini). + * Identifies the backend service for the Gemini Developer API (via Google AI). * Use this constant when creating a {@link GoogleAIBackend} configuration. */ GOOGLE_AI: 'GOOGLE_AI' @@ -96,7 +99,9 @@ export const BackendType = { export type BackendType = (typeof BackendType)[keyof typeof BackendType]; /** - * Options interface for initializing the AI service using {@link getAI | getAI()}. + * Options for initializing the AI service using {@link getAI | getAI()}. + * This allows specifying which backend to use (Gemini API in Vertex AI or Gemini Developer API) + * and configuring its specific options (like location for Vertex AI). * * @public */ diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index 2dd67e0a15f..8e618c61edf 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -62,7 +62,7 @@ export enum HarmBlockThreshold { } /** - * This property is not supported in Google AI. + * This property is not supported in the Gemini Developer API ({@link GoogleAIBackend}). * * @public */ diff --git a/packages/vertexai/src/types/imagen/requests.ts b/packages/vertexai/src/types/imagen/requests.ts index c5c54dc1e9a..09bd3dedc9b 100644 --- a/packages/vertexai/src/types/imagen/requests.ts +++ b/packages/vertexai/src/types/imagen/requests.ts @@ -59,7 +59,8 @@ export interface ImagenGenerationConfig { * * See the {@link http://firebase.google.com/docs/vertex-ai/model-parameters#imagen | documentation} for more details. * - * This is no longer supported in Google AI in versions greater than `imagen-3.0-generate-002`. + * This is no longer supported in the Gemini Developer API ({@link GoogleAIBackend}) in versions + * greater than `imagen-3.0-generate-002`. */ negativePrompt?: string; /** @@ -91,7 +92,8 @@ export interface ImagenGenerationConfig { * For Imagen 3 models, the default value is `true`; see the addWatermark * documentation for more details. * - * In Google AI, the default value is true, and it cannot be turned off. + * When using the Gemini Developer API ({@link GoogleAIBackend}), this will default to true, + * and cannot be turned off. */ addWatermark?: boolean; } diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index 53c80efe67d..f232d913bd2 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -64,8 +64,11 @@ export interface SafetySetting { category: HarmCategory; threshold: HarmBlockThreshold; /** - * This property is not supported in Google AI. If this is a property on a - * {@link GenerateContentRequest} to be sent, an {@link AIError} will be thrown. + * The harm block method. + * + * This property is only supported in the Gemini API in Vertex AI ({@link VertexAIBackend}). + * When using the Gemini Developer API ({@link GoogleAIBackend}), an {@link AIError} will be + * thrown if this property is defined. */ method?: HarmBlockMethod; } diff --git a/packages/vertexai/src/types/responses.ts b/packages/vertexai/src/types/responses.ts index b6d325f47ea..7d551ca83d9 100644 --- a/packages/vertexai/src/types/responses.ts +++ b/packages/vertexai/src/types/responses.ts @@ -109,7 +109,9 @@ export interface PromptFeedback { blockReason?: BlockReason; safetyRatings: SafetyRating[]; /** - * This field is not supported in Google AI. + * A human-readable description of the `blockReason`. + * + * This property is only supported in the Gemini API in Vertex AI ({@link VertexAIBackend}). */ blockReasonMessage?: string; } @@ -146,11 +148,15 @@ export interface Citation { uri?: string; license?: string; /** - * This field is not supported in Google AI. + * The title of the cited source, if available. + * + * This property is only supported in the Gemini API in Vertex AI ({@link VertexAIBackend}). */ title?: string; /** - * This field is not supported in Google AI. + * The publication date of the cited source, if available. + * + * This property is only supported in the Gemini API in Vertex AI ({@link VertexAIBackend}). */ publicationDate?: Date; } @@ -222,16 +228,24 @@ export interface SafetyRating { category: HarmCategory; probability: HarmProbability; /** - * This field is not supported in Google AI, so it will default to `HarmSeverity.UNSUPPORTED` - * when using Google AI. + * The harm severity level. + * + * This property is only supported when using the Gemini API in Vertex AI ({@link VertexAIBackend}). + * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`. */ severity: HarmSeverity; /** - * This field is not supported in Google AI, so it will default to 0 when using Google AI. + * The probability score of the harm category. + * + * This property is only supported when using the Gemini API in Vertex AI ({@link VertexAIBackend}). + * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0. */ probabilityScore: number; /** - * This field is not supported in Google AI, so it will default to 0 when using Google AI. + * The severity score of the harm category. + * + * This property is only supported when using the Gemini API in Vertex AI ({@link VertexAIBackend}). + * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0. */ severityScore: number; blocked: boolean; @@ -250,7 +264,8 @@ export interface CountTokensResponse { * The total number of billable characters counted across all instances * from the request. * - * This field is not supported in Google AI, so it will default to 0 when using Google AI. + * This property is only supported when using the Gemini API in Vertex AI ({@link VertexAIBackend}). + * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0. */ totalBillableCharacters?: number; /** diff --git a/packages/vertexai/src/types/schema.ts b/packages/vertexai/src/types/schema.ts index c73caca9993..e9fe9286b61 100644 --- a/packages/vertexai/src/types/schema.ts +++ b/packages/vertexai/src/types/schema.ts @@ -43,8 +43,8 @@ export enum SchemaType { */ export interface SchemaShared { /** Optional. The format of the property. - * When using the Google AI backend, this must be either `'enum'` or `'date-time'`, otherwise - * requests will fail. + * When using the Gemini Developer API ({@link GoogleAIBackend}), this must be either `'enum'` or + * `'date-time'`, otherwise requests will fail. */ format?: string; /** Optional. The description of the property. */ From cc1726d9e9a8d6e00dbd509d11b4efb2a8226483 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 2 May 2025 16:21:51 -0400 Subject: [PATCH 18/32] update changeset --- .changeset/tall-zoos-stare.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tall-zoos-stare.md b/.changeset/tall-zoos-stare.md index f6bbe141228..2711107986c 100644 --- a/.changeset/tall-zoos-stare.md +++ b/.changeset/tall-zoos-stare.md @@ -3,4 +3,4 @@ '@firebase/vertexai': minor --- -Add support for the Google AI API, enabling usage in a free tier, and add new `AI` API to accomodate new product naming. +Add support for the Gemini Developer API, enabling usage in a free tier, and add new `AI` API to accomodate new product naming. From a51677160e4fe245993b65c66223cc6ebc5084e5 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 2 May 2025 16:42:20 -0400 Subject: [PATCH 19/32] Update to Vertex AI Gemini API --- docs-devsite/vertexai.ai.md | 4 ++-- docs-devsite/vertexai.aimodel.md | 2 +- docs-devsite/vertexai.aioptions.md | 2 +- docs-devsite/vertexai.backend.md | 2 +- docs-devsite/vertexai.citation.md | 8 ++++---- docs-devsite/vertexai.counttokensresponse.md | 4 ++-- docs-devsite/vertexai.md | 18 +++++++++--------- docs-devsite/vertexai.promptfeedback.md | 4 ++-- docs-devsite/vertexai.safetyrating.md | 12 ++++++------ docs-devsite/vertexai.safetysetting.md | 4 ++-- docs-devsite/vertexai.vertexaibackend.md | 4 ++-- packages/vertexai/src/api.ts | 6 +++--- packages/vertexai/src/backend.ts | 8 ++++---- packages/vertexai/src/googleai-mappers.ts | 6 +++--- packages/vertexai/src/models/ai-model.ts | 2 +- packages/vertexai/src/public-types.ts | 8 ++++---- packages/vertexai/src/types/requests.ts | 2 +- packages/vertexai/src/types/responses.ts | 14 +++++++------- 18 files changed, 55 insertions(+), 55 deletions(-) diff --git a/docs-devsite/vertexai.ai.md b/docs-devsite/vertexai.ai.md index 1db78d7b7ff..661bf0b4fe3 100644 --- a/docs-devsite/vertexai.ai.md +++ b/docs-devsite/vertexai.ai.md @@ -25,7 +25,7 @@ export interface AI | Property | Type | Description | | --- | --- | --- | | [app](./vertexai.ai.md#aiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./vertexai.ai.md#ai_interface) instance is associated with. | -| [backend](./vertexai.ai.md#aibackend) | [Backend](./vertexai.backend.md#backend_class) | A [Backend](./vertexai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) or the Gemini API in Vertex AI (using [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | +| [backend](./vertexai.ai.md#aibackend) | [Backend](./vertexai.backend.md#backend_class) | A [Backend](./vertexai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) or the Vertex AI Gemini API (using [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | | [location](./vertexai.ai.md#ailocation) | string | The location configured for this AI service instance, relevant for Vertex AI backends. | ## AI.app @@ -40,7 +40,7 @@ app: FirebaseApp; ## AI.backend -A [Backend](./vertexai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) or the Gemini API in Vertex AI (using [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). +A [Backend](./vertexai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) or the Vertex AI Gemini API (using [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.aimodel.md b/docs-devsite/vertexai.aimodel.md index 5cea0c435bb..bddc9c8b985 100644 --- a/docs-devsite/vertexai.aimodel.md +++ b/docs-devsite/vertexai.aimodel.md @@ -12,7 +12,7 @@ https://github.com/firebase/firebase-js-sdk # AIModel class Base class for Firebase AI model APIs. -Instances of this class are associated with a specific Firebase AI backend (either the Gemini API in Vertex AI or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. +Instances of this class are associated with a specific Firebase AI backend (either the Vertex AI Gemini API or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `AIModel` class. diff --git a/docs-devsite/vertexai.aioptions.md b/docs-devsite/vertexai.aioptions.md index d75a4a45d10..00ff0153527 100644 --- a/docs-devsite/vertexai.aioptions.md +++ b/docs-devsite/vertexai.aioptions.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # AIOptions interface -Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Gemini API in Vertex AI or Gemini Developer API) and configuring its specific options (like location for Vertex AI). +Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) and configuring its specific options (like location for Vertex AI). Signature: diff --git a/docs-devsite/vertexai.backend.md b/docs-devsite/vertexai.backend.md index 3ec2d43e565..fe568087c77 100644 --- a/docs-devsite/vertexai.backend.md +++ b/docs-devsite/vertexai.backend.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # Backend class -Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Gemini API in Vertex AI. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Gemini API in Vertex AI. +Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Vertex AI Gemini API. Signature: diff --git a/docs-devsite/vertexai.citation.md b/docs-devsite/vertexai.citation.md index 36df6c91d0c..c694f6c2a9c 100644 --- a/docs-devsite/vertexai.citation.md +++ b/docs-devsite/vertexai.citation.md @@ -24,9 +24,9 @@ export interface Citation | --- | --- | --- | | [endIndex](./vertexai.citation.md#citationendindex) | number | | | [license](./vertexai.citation.md#citationlicense) | string | | -| [publicationDate](./vertexai.citation.md#citationpublicationdate) | Date | The publication date of the cited source, if available.This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | +| [publicationDate](./vertexai.citation.md#citationpublicationdate) | Date | The publication date of the cited source, if available.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | | [startIndex](./vertexai.citation.md#citationstartindex) | number | | -| [title](./vertexai.citation.md#citationtitle) | string | The title of the cited source, if available.This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | +| [title](./vertexai.citation.md#citationtitle) | string | The title of the cited source, if available.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | | [uri](./vertexai.citation.md#citationuri) | string | | ## Citation.endIndex @@ -49,7 +49,7 @@ license?: string; The publication date of the cited source, if available. -This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). +This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). Signature: @@ -69,7 +69,7 @@ startIndex?: number; The title of the cited source, if available. -This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). +This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.counttokensresponse.md b/docs-devsite/vertexai.counttokensresponse.md index df32b78e231..b304ccb82a0 100644 --- a/docs-devsite/vertexai.counttokensresponse.md +++ b/docs-devsite/vertexai.counttokensresponse.md @@ -23,7 +23,7 @@ export interface CountTokensResponse | Property | Type | Description | | --- | --- | --- | | [promptTokensDetails](./vertexai.counttokensresponse.md#counttokensresponseprompttokensdetails) | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface)\[\] | The breakdown, by modality, of how many tokens are consumed by the prompt. | -| [totalBillableCharacters](./vertexai.counttokensresponse.md#counttokensresponsetotalbillablecharacters) | number | The total number of billable characters counted across all instances from the request.This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | +| [totalBillableCharacters](./vertexai.counttokensresponse.md#counttokensresponsetotalbillablecharacters) | number | The total number of billable characters counted across all instances from the request.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | | [totalTokens](./vertexai.counttokensresponse.md#counttokensresponsetotaltokens) | number | The total number of tokens counted across all instances from the request. | ## CountTokensResponse.promptTokensDetails @@ -40,7 +40,7 @@ promptTokensDetails?: ModalityTokenCount[]; The total number of billable characters counted across all instances from the request. -This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. +This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. Signature: diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index bb6863ce5f0..34de969ebbf 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -18,7 +18,7 @@ The Firebase AI Web SDK. | --- | --- | | function(app, ...) | | [getAI(app, options)](./vertexai.md#getai_a94a413) | Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | -| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413).Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Gemini API in Vertex AI. This instance will be configured to use the Gemini API in Vertex AI. | +| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413).Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. | | function(ai, ...) | | [getGenerativeModel(ai, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | | [getImagenModel(ai, modelParams, requestOptions)](./vertexai.md#getimagenmodel_e1f6645) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | @@ -28,9 +28,9 @@ The Firebase AI Web SDK. | Class | Description | | --- | --- | | [AIError](./vertexai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. | -| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.Instances of this class are associated with a specific Firebase AI backend (either the Gemini API in Vertex AI or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. | +| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.Instances of this class are associated with a specific Firebase AI backend (either the Vertex AI Gemini API or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. | | [ArraySchema](./vertexai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | -| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Gemini API in Vertex AI. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Gemini API in Vertex AI. | +| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Vertex AI Gemini API. | | [BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | | [ChatSession](./vertexai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | | [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | @@ -42,7 +42,7 @@ The Firebase AI Web SDK. | [ObjectSchema](./vertexai.objectschema.md#objectschema_class) | Schema class for "object" types. The properties param must be a map of Schema objects. | | [Schema](./vertexai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with JSON.stringify() into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) | | [StringSchema](./vertexai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. | -| [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Gemini API in Vertex AI.Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini API in Vertex AI as the backend. | +| [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Vertex AI Gemini API.Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. | ## Enumerations @@ -68,7 +68,7 @@ The Firebase AI Web SDK. | Interface | Description | | --- | --- | | [AI](./vertexai.ai.md#ai_interface) | An instance of the Firebase AI SDK.Do not create this instance directly. Instead, use [getAI()](./vertexai.md#getai_a94a413). | -| [AIOptions](./vertexai.aioptions.md#aioptions_interface) | Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Gemini API in Vertex AI or Gemini Developer API) and configuring its specific options (like location for Vertex AI). | +| [AIOptions](./vertexai.aioptions.md#aioptions_interface) | Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) and configuring its specific options (like location for Vertex AI). | | [BaseParams](./vertexai.baseparams.md#baseparams_interface) | Base parameters for a number of methods. | | [Citation](./vertexai.citation.md#citation_interface) | A single citation. | | [CitationMetadata](./vertexai.citationmetadata.md#citationmetadata_interface) | Citation metadata that may be found on a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface). | @@ -129,7 +129,7 @@ The Firebase AI Web SDK. | Variable | Description | | --- | --- | -| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Gemini API in Vertex AI or Gemini Developer API) the SDK will communicate with.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | +| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | | [POSSIBLE\_ROLES](./vertexai.md#possible_roles) | Possible roles. | | [VertexAIError](./vertexai.md#vertexaierror) | Error class for the Firebase AI SDK.For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). | | [VertexAIModel](./vertexai.md#vertexaimodel) | Base class for Firebase AI model APIs.For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). | @@ -191,7 +191,7 @@ const ai = getAI(app, { backend: new GoogleAIBackend() }); ```javascript -// Get an AI instance configured to use the Gemini API in Vertex AI. +// Get an AI instance configured to use the Vertex AI Gemini API. const ai = getAI(app, { backend: new VertexAIBackend() }); ``` @@ -200,7 +200,7 @@ const ai = getAI(app, { backend: new VertexAIBackend() }); It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413). -Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Gemini API in Vertex AI. This instance will be configured to use the Gemini API in Vertex AI. +Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. Signature: @@ -276,7 +276,7 @@ If the `apiKey` or `projectId` fields are missing in your Firebase config. ## BackendType -An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Gemini API in Vertex AI or Gemini Developer API) the SDK will communicate with. +An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with. These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. diff --git a/docs-devsite/vertexai.promptfeedback.md b/docs-devsite/vertexai.promptfeedback.md index 574c30a8306..08ea4aaf4cf 100644 --- a/docs-devsite/vertexai.promptfeedback.md +++ b/docs-devsite/vertexai.promptfeedback.md @@ -23,7 +23,7 @@ export interface PromptFeedback | Property | Type | Description | | --- | --- | --- | | [blockReason](./vertexai.promptfeedback.md#promptfeedbackblockreason) | [BlockReason](./vertexai.md#blockreason) | | -| [blockReasonMessage](./vertexai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | A human-readable description of the blockReason.This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | +| [blockReasonMessage](./vertexai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | A human-readable description of the blockReason.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | | [safetyRatings](./vertexai.promptfeedback.md#promptfeedbacksafetyratings) | [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface)\[\] | | ## PromptFeedback.blockReason @@ -38,7 +38,7 @@ blockReason?: BlockReason; A human-readable description of the `blockReason`. -This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). +This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.safetyrating.md b/docs-devsite/vertexai.safetyrating.md index d8f762c977d..ebe5003c662 100644 --- a/docs-devsite/vertexai.safetyrating.md +++ b/docs-devsite/vertexai.safetyrating.md @@ -25,9 +25,9 @@ export interface SafetyRating | [blocked](./vertexai.safetyrating.md#safetyratingblocked) | boolean | | | [category](./vertexai.safetyrating.md#safetyratingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | | [probability](./vertexai.safetyrating.md#safetyratingprobability) | [HarmProbability](./vertexai.md#harmprobability) | | -| [probabilityScore](./vertexai.safetyrating.md#safetyratingprobabilityscore) | number | The probability score of the harm category.This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | -| [severity](./vertexai.safetyrating.md#safetyratingseverity) | [HarmSeverity](./vertexai.md#harmseverity) | The harm severity level.This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to HarmSeverity.UNSUPPORTED. | -| [severityScore](./vertexai.safetyrating.md#safetyratingseverityscore) | number | The severity score of the harm category.This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | +| [probabilityScore](./vertexai.safetyrating.md#safetyratingprobabilityscore) | number | The probability score of the harm category.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | +| [severity](./vertexai.safetyrating.md#safetyratingseverity) | [HarmSeverity](./vertexai.md#harmseverity) | The harm severity level.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to HarmSeverity.UNSUPPORTED. | +| [severityScore](./vertexai.safetyrating.md#safetyratingseverityscore) | number | The severity score of the harm category.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | ## SafetyRating.blocked @@ -57,7 +57,7 @@ probability: HarmProbability; The probability score of the harm category. -This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. +This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. Signature: @@ -69,7 +69,7 @@ probabilityScore: number; The harm severity level. -This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`. +This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`. Signature: @@ -81,7 +81,7 @@ severity: HarmSeverity; The severity score of the harm category. -This property is only supported when using the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. +This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. Signature: diff --git a/docs-devsite/vertexai.safetysetting.md b/docs-devsite/vertexai.safetysetting.md index c4589d5c526..a91843faaa5 100644 --- a/docs-devsite/vertexai.safetysetting.md +++ b/docs-devsite/vertexai.safetysetting.md @@ -23,7 +23,7 @@ export interface SafetySetting | Property | Type | Description | | --- | --- | --- | | [category](./vertexai.safetysetting.md#safetysettingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | -| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | The harm block method.This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), an [AIError](./vertexai.aierror.md#aierror_class) will be thrown if this property is defined. | +| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | The harm block method.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), an [AIError](./vertexai.aierror.md#aierror_class) will be thrown if this property is defined. | | [threshold](./vertexai.safetysetting.md#safetysettingthreshold) | [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | | ## SafetySetting.category @@ -38,7 +38,7 @@ category: HarmCategory; The harm block method. -This property is only supported in the Gemini API in Vertex AI ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), an [AIError](./vertexai.aierror.md#aierror_class) will be thrown if this property is defined. +This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), an [AIError](./vertexai.aierror.md#aierror_class) will be thrown if this property is defined. Signature: diff --git a/docs-devsite/vertexai.vertexaibackend.md b/docs-devsite/vertexai.vertexaibackend.md index 3dbba80af6e..ba82c775ca8 100644 --- a/docs-devsite/vertexai.vertexaibackend.md +++ b/docs-devsite/vertexai.vertexaibackend.md @@ -10,9 +10,9 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # VertexAIBackend class -Configuration class for the Gemini API in Vertex AI. +Configuration class for the Vertex AI Gemini API. -Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini API in Vertex AI as the backend. +Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. Signature: diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index e31cda79849..06bd747746a 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -68,8 +68,8 @@ declare module '@firebase/component' { * It is recommended to use the new {@link getAI | getAI()}. * * Returns a {@link VertexAI} instance for the given app, configured to use the - * Gemini API in Vertex AI. This instance will be - * configured to use the Gemini API in Vertex AI. + * Vertex AI Gemini API. This instance will be + * configured to use the Vertex AI Gemini API. * * @param app - The {@link @firebase/app#FirebaseApp} to use. * @param options - Options to configure the Vertex AI instance, including the location. @@ -109,7 +109,7 @@ export function getVertexAI( * * @example * ```javascript - * // Get an AI instance configured to use the Gemini API in Vertex AI. + * // Get an AI instance configured to use the Vertex AI Gemini API. * const ai = getAI(app, { backend: new VertexAIBackend() }); * ``` * diff --git a/packages/vertexai/src/backend.ts b/packages/vertexai/src/backend.ts index f19800e1686..7dc80ac3b02 100644 --- a/packages/vertexai/src/backend.ts +++ b/packages/vertexai/src/backend.ts @@ -20,10 +20,10 @@ import { BackendType } from './public-types'; /** * Abstract base class representing the configuration for an AI service backend, - * determining whether to use the Gemini Developer API (via Google AI) or the Gemini API in Vertex AI. + * determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. * This class should not be instantiated directly. Use its subclasses: * - {@link GoogleAIBackend}: For the Gemini Developer API (via Google AI). - * - {@link VertexAIBackend}: For the Gemini API in Vertex AI. + * - {@link VertexAIBackend}: For the Vertex AI Gemini API. * * @public */ @@ -60,10 +60,10 @@ export class GoogleAIBackend extends Backend { } /** - * Configuration class for the Gemini API in Vertex AI. + * Configuration class for the Vertex AI Gemini API. * * Use this with {@link AIOptions} when initializing the AI service via - * {@link getAI | getAI()} to specify the Gemini API in Vertex AI as the backend. + * {@link getAI | getAI()} to specify the Vertex AI Gemini API as the backend. * * @public */ diff --git a/packages/vertexai/src/googleai-mappers.ts b/packages/vertexai/src/googleai-mappers.ts index 413e08b9955..23c238c1e3b 100644 --- a/packages/vertexai/src/googleai-mappers.ts +++ b/packages/vertexai/src/googleai-mappers.ts @@ -36,10 +36,10 @@ import { } from './types/googleai'; /** - * This SDK supports both the Gemini API in Vertex AI and the Gemini Developer API (using Google AI). - * The public API prioritizes the format used by the Gemini API in Vertex AI. + * This SDK supports both the Vertex AI Gemini API and the Gemini Developer API (using Google AI). + * The public API prioritizes the format used by the Vertex AI Gemini API. * We avoid having two sets of types by translating requests and responses between the two API formats. - * This translation allows developers to switch between the Gemini API in Vertex AI and the Gemini Developer API + * This translation allows developers to switch between the Vertex AI Gemini API and the Gemini Developer API * with minimal code changes. * * In here are functions that map requests and responses between the two API formats. diff --git a/packages/vertexai/src/models/ai-model.ts b/packages/vertexai/src/models/ai-model.ts index 1a982c25d36..1d93fc557a9 100644 --- a/packages/vertexai/src/models/ai-model.ts +++ b/packages/vertexai/src/models/ai-model.ts @@ -25,7 +25,7 @@ import { _isFirebaseServerApp } from '@firebase/app'; * Base class for Firebase AI model APIs. * * Instances of this class are associated with a specific Firebase AI backend - * (either the Gemini API in Vertex AI or the Gemini Developer API via Google AI) + * (either the Vertex AI Gemini API or the Gemini Developer API via Google AI) * and provide methods for interacting with the configured generative model. * * @public diff --git a/packages/vertexai/src/public-types.ts b/packages/vertexai/src/public-types.ts index 99acd64316f..a82f930b9a8 100644 --- a/packages/vertexai/src/public-types.ts +++ b/packages/vertexai/src/public-types.ts @@ -53,7 +53,7 @@ export interface AI { /** * A {@link Backend} instance that specifies the configuration for the target backend, * either the Gemini Developer API (using {@link GoogleAIBackend}) or the - * Gemini API in Vertex AI (using {@link VertexAIBackend}). + * Vertex AI Gemini API (using {@link VertexAIBackend}). */ backend: Backend; /** @@ -67,7 +67,7 @@ export interface AI { /** * An enum-like object containing constants that represent the supported backends * for the Firebase AI SDK. - * This determines which backend service (Gemini API in Vertex AI or Gemini Developer API) + * This determines which backend service (Vertex AI Gemini API or Gemini Developer API) * the SDK will communicate with. * * These values are assigned to the `backendType` property within the specific backend @@ -78,7 +78,7 @@ export interface AI { */ export const BackendType = { /** - * Identifies the backend service for the Gemini API in Vertex AI provided through Google Cloud. + * Identifies the backend service for the Vertex AI Gemini API provided through Google Cloud. * Use this constant when creating a {@link VertexAIBackend} configuration. */ VERTEX_AI: 'VERTEX_AI', @@ -100,7 +100,7 @@ export type BackendType = (typeof BackendType)[keyof typeof BackendType]; /** * Options for initializing the AI service using {@link getAI | getAI()}. - * This allows specifying which backend to use (Gemini API in Vertex AI or Gemini Developer API) + * This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) * and configuring its specific options (like location for Vertex AI). * * @public diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index f232d913bd2..0781e87cb7c 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -66,7 +66,7 @@ export interface SafetySetting { /** * The harm block method. * - * This property is only supported in the Gemini API in Vertex AI ({@link VertexAIBackend}). + * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}). * When using the Gemini Developer API ({@link GoogleAIBackend}), an {@link AIError} will be * thrown if this property is defined. */ diff --git a/packages/vertexai/src/types/responses.ts b/packages/vertexai/src/types/responses.ts index 7d551ca83d9..17710074de5 100644 --- a/packages/vertexai/src/types/responses.ts +++ b/packages/vertexai/src/types/responses.ts @@ -111,7 +111,7 @@ export interface PromptFeedback { /** * A human-readable description of the `blockReason`. * - * This property is only supported in the Gemini API in Vertex AI ({@link VertexAIBackend}). + * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}). */ blockReasonMessage?: string; } @@ -150,13 +150,13 @@ export interface Citation { /** * The title of the cited source, if available. * - * This property is only supported in the Gemini API in Vertex AI ({@link VertexAIBackend}). + * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}). */ title?: string; /** * The publication date of the cited source, if available. * - * This property is only supported in the Gemini API in Vertex AI ({@link VertexAIBackend}). + * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}). */ publicationDate?: Date; } @@ -230,21 +230,21 @@ export interface SafetyRating { /** * The harm severity level. * - * This property is only supported when using the Gemini API in Vertex AI ({@link VertexAIBackend}). + * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}). * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`. */ severity: HarmSeverity; /** * The probability score of the harm category. * - * This property is only supported when using the Gemini API in Vertex AI ({@link VertexAIBackend}). + * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}). * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0. */ probabilityScore: number; /** * The severity score of the harm category. * - * This property is only supported when using the Gemini API in Vertex AI ({@link VertexAIBackend}). + * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}). * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0. */ severityScore: number; @@ -264,7 +264,7 @@ export interface CountTokensResponse { * The total number of billable characters counted across all instances * from the request. * - * This property is only supported when using the Gemini API in Vertex AI ({@link VertexAIBackend}). + * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}). * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0. */ totalBillableCharacters?: number; From ea28656c516e4c1d5d4f27491820806dbe344902 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 6 May 2025 16:49:46 -0400 Subject: [PATCH 20/32] Revert eslint change to fix firestore docs???? --- common/api-review/firestore.api.md | 42 +++-- config/.eslintrc.js | 1 + docs-devsite/_toc.yaml | 18 ++ docs-devsite/firestore_.md | 159 ++---------------- .../firestore_.memorycachesettings.md | 35 ++++ .../firestore_.memoryeagergarbagecollector.md | 37 ++++ docs-devsite/firestore_.memorylocalcache.md | 35 ++++ .../firestore_.memorylrugarbagecollector.md | 37 ++++ .../firestore_.persistentcachesettings.md | 50 ++++++ .../firestore_.persistentlocalcache.md | 35 ++++ ...firestore_.persistentmultipletabmanager.md | 33 ++++ .../firestore_.persistentsingletabmanager.md | 33 ++++ ...ore_.persistentsingletabmanagersettings.md | 35 ++++ 13 files changed, 391 insertions(+), 159 deletions(-) create mode 100644 docs-devsite/firestore_.memorycachesettings.md create mode 100644 docs-devsite/firestore_.memoryeagergarbagecollector.md create mode 100644 docs-devsite/firestore_.memorylocalcache.md create mode 100644 docs-devsite/firestore_.memorylrugarbagecollector.md create mode 100644 docs-devsite/firestore_.persistentcachesettings.md create mode 100644 docs-devsite/firestore_.persistentlocalcache.md create mode 100644 docs-devsite/firestore_.persistentmultipletabmanager.md create mode 100644 docs-devsite/firestore_.persistentsingletabmanager.md create mode 100644 docs-devsite/firestore_.persistentsingletabmanagersettings.md diff --git a/common/api-review/firestore.api.md b/common/api-review/firestore.api.md index 26c379a6e34..34b56b97f21 100644 --- a/common/api-review/firestore.api.md +++ b/common/api-review/firestore.api.md @@ -375,14 +375,15 @@ export interface LoadBundleTaskProgress { export { LogLevel } // @public -export type MemoryCacheSettings = { +export interface MemoryCacheSettings { garbageCollector?: MemoryGarbageCollector; -}; +} // @public -export type MemoryEagerGarbageCollector = { +export interface MemoryEagerGarbageCollector { + // (undocumented) kind: 'memoryEager'; -}; +} // @public export function memoryEagerGarbageCollector(): MemoryEagerGarbageCollector; @@ -391,17 +392,19 @@ export function memoryEagerGarbageCollector(): MemoryEagerGarbageCollector; export type MemoryGarbageCollector = MemoryEagerGarbageCollector | MemoryLruGarbageCollector; // @public -export type MemoryLocalCache = { +export interface MemoryLocalCache { + // (undocumented) kind: 'memory'; -}; +} // @public export function memoryLocalCache(settings?: MemoryCacheSettings): MemoryLocalCache; // @public -export type MemoryLruGarbageCollector = { +export interface MemoryLruGarbageCollector { + // (undocumented) kind: 'memoryLru'; -}; +} // @public export function memoryLruGarbageCollector(settings?: { @@ -491,39 +494,42 @@ export class PersistentCacheIndexManager { } // @public -export type PersistentCacheSettings = { +export interface PersistentCacheSettings { cacheSizeBytes?: number; tabManager?: PersistentTabManager; -}; +} // @public -export type PersistentLocalCache = { +export interface PersistentLocalCache { + // (undocumented) kind: 'persistent'; -}; +} // @public export function persistentLocalCache(settings?: PersistentCacheSettings): PersistentLocalCache; // @public -export type PersistentMultipleTabManager = { +export interface PersistentMultipleTabManager { + // (undocumented) kind: 'PersistentMultipleTab'; -}; +} // @public export function persistentMultipleTabManager(): PersistentMultipleTabManager; // @public -export type PersistentSingleTabManager = { +export interface PersistentSingleTabManager { + // (undocumented) kind: 'persistentSingleTab'; -}; +} // @public export function persistentSingleTabManager(settings: PersistentSingleTabManagerSettings | undefined): PersistentSingleTabManager; // @public -export type PersistentSingleTabManagerSettings = { +export interface PersistentSingleTabManagerSettings { forceOwnership?: boolean; -}; +} // @public export type PersistentTabManager = PersistentSingleTabManager | PersistentMultipleTabManager; diff --git a/config/.eslintrc.js b/config/.eslintrc.js index d63cc9cd290..57243a3e2a4 100644 --- a/config/.eslintrc.js +++ b/config/.eslintrc.js @@ -174,6 +174,7 @@ module.exports = { } } ], + '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], '@typescript-eslint/explicit-member-accessibility': [ 'error', { diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index 2bcb53bb047..c507b44ce99 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -245,10 +245,28 @@ toc: path: /docs/reference/js/firestore_.loadbundletask.md - title: LoadBundleTaskProgress path: /docs/reference/js/firestore_.loadbundletaskprogress.md + - title: MemoryCacheSettings + path: /docs/reference/js/firestore_.memorycachesettings.md + - title: MemoryEagerGarbageCollector + path: /docs/reference/js/firestore_.memoryeagergarbagecollector.md + - title: MemoryLocalCache + path: /docs/reference/js/firestore_.memorylocalcache.md + - title: MemoryLruGarbageCollector + path: /docs/reference/js/firestore_.memorylrugarbagecollector.md - title: PersistenceSettings path: /docs/reference/js/firestore_.persistencesettings.md - title: PersistentCacheIndexManager path: /docs/reference/js/firestore_.persistentcacheindexmanager.md + - title: PersistentCacheSettings + path: /docs/reference/js/firestore_.persistentcachesettings.md + - title: PersistentLocalCache + path: /docs/reference/js/firestore_.persistentlocalcache.md + - title: PersistentMultipleTabManager + path: /docs/reference/js/firestore_.persistentmultipletabmanager.md + - title: PersistentSingleTabManager + path: /docs/reference/js/firestore_.persistentsingletabmanager.md + - title: PersistentSingleTabManagerSettings + path: /docs/reference/js/firestore_.persistentsingletabmanagersettings.md - title: Query path: /docs/reference/js/firestore_.query.md - title: QueryCompositeFilterConstraint diff --git a/docs-devsite/firestore_.md b/docs-devsite/firestore_.md index 7dfde135ab0..91d21e32708 100644 --- a/docs-devsite/firestore_.md +++ b/docs-devsite/firestore_.md @@ -174,7 +174,16 @@ https://github.com/firebase/firebase-js-sdk | [IndexConfiguration](./firestore_.indexconfiguration.md#indexconfiguration_interface) | (Public Preview) A list of Firestore indexes to speed up local query execution.See [JSON Format](https://firebase.google.com/docs/reference/firestore/indexes/#json_format) for a description of the format of the index definition. | | [IndexField](./firestore_.indexfield.md#indexfield_interface) | (Public Preview) A single field element in an index configuration. | | [LoadBundleTaskProgress](./firestore_.loadbundletaskprogress.md#loadbundletaskprogress_interface) | Represents a progress update or a final state from loading bundles. | +| [MemoryCacheSettings](./firestore_.memorycachesettings.md#memorycachesettings_interface) | An settings object to configure an MemoryLocalCache instance. | +| [MemoryEagerGarbageCollector](./firestore_.memoryeagergarbagecollector.md#memoryeagergarbagecollector_interface) | A garbage collector deletes documents whenever they are not part of any active queries, and have no local mutations attached to them.This collector tries to ensure lowest memory footprints from the SDK, at the risk of documents not being cached for offline queries or for direct queries to the cache.Use factory function to create an instance of this collector. | +| [MemoryLocalCache](./firestore_.memorylocalcache.md#memorylocalcache_interface) | Provides an in-memory cache to the SDK. This is the default cache unless explicitly configured otherwise.To use, create an instance using the factory function , then set the instance to FirestoreSettings.cache and call initializeFirestore using the settings object. | +| [MemoryLruGarbageCollector](./firestore_.memorylrugarbagecollector.md#memorylrugarbagecollector_interface) | A garbage collector deletes Least-Recently-Used documents in multiple batches.This collector is configured with a target size, and will only perform collection when the cached documents exceed the target size. It avoids querying backend repeated for the same query or document, at the risk of having a larger memory footprint.Use factory function to create a instance of this collector. | | [PersistenceSettings](./firestore_.persistencesettings.md#persistencesettings_interface) | Settings that can be passed to enableIndexedDbPersistence() to configure Firestore persistence.Persistence cannot be used in a Node.js environment. | +| [PersistentCacheSettings](./firestore_.persistentcachesettings.md#persistentcachesettings_interface) | An settings object to configure an PersistentLocalCache instance.Persistent cache cannot be used in a Node.js environment. | +| [PersistentLocalCache](./firestore_.persistentlocalcache.md#persistentlocalcache_interface) | Provides a persistent cache backed by IndexedDb to the SDK.To use, create an instance using the factory function , then set the instance to FirestoreSettings.cache and call initializeFirestore using the settings object. | +| [PersistentMultipleTabManager](./firestore_.persistentmultipletabmanager.md#persistentmultipletabmanager_interface) | A tab manager supporting multiple tabs. SDK will synchronize queries and mutations done across all tabs using the SDK. | +| [PersistentSingleTabManager](./firestore_.persistentsingletabmanager.md#persistentsingletabmanager_interface) | A tab manager supporting only one tab, no synchronization will be performed across tabs. | +| [PersistentSingleTabManagerSettings](./firestore_.persistentsingletabmanagersettings.md#persistentsingletabmanagersettings_interface) | Type to configure an PersistentSingleTabManager instance. | | [SnapshotListenOptions](./firestore_.snapshotlistenoptions.md#snapshotlistenoptions_interface) | An options object that can be passed to [onSnapshot()](./firestore_.md#onsnapshot_0312fd7) and [QuerySnapshot.docChanges()](./firestore_.querysnapshot.md#querysnapshotdocchanges) to control which types of changes to include in the result set. | | [SnapshotOptions](./firestore_.snapshotoptions.md#snapshotoptions_interface) | Options that configure how data is retrieved from a DocumentSnapshot (for example the desired behavior for server timestamps that have not yet been set to their final value). | | [TransactionOptions](./firestore_.transactionoptions.md#transactionoptions_interface) | Options to customize transaction behavior. | @@ -199,19 +208,10 @@ https://github.com/firebase/firebase-js-sdk | [FirestoreErrorCode](./firestore_.md#firestoreerrorcode) | The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.mdPossible values: - 'cancelled': The operation was cancelled (typically by the caller). - 'unknown': Unknown error or an error from a different error domain. - 'invalid-argument': Client specified an invalid argument. Note that this differs from 'failed-precondition'. 'invalid-argument' indicates arguments that are problematic regardless of the state of the system (e.g. an invalid field name). - 'deadline-exceeded': Deadline expired before operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. - 'not-found': Some requested document was not found. - 'already-exists': Some document that we attempted to create already exists. - 'permission-denied': The caller does not have permission to execute the specified operation. - 'resource-exhausted': Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. - 'failed-precondition': Operation was rejected because the system is not in a state required for the operation's execution. - 'aborted': The operation was aborted, typically due to a concurrency issue like transaction aborts, etc. - 'out-of-range': Operation was attempted past the valid range. - 'unimplemented': Operation is not implemented or not supported/enabled. - 'internal': Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken. - 'unavailable': The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff. - 'data-loss': Unrecoverable data loss or corruption. - 'unauthenticated': The request does not have valid authentication credentials for the operation. | | [FirestoreLocalCache](./firestore_.md#firestorelocalcache) | Union type from all supported SDK cache layer. | | [ListenSource](./firestore_.md#listensource) | Describe the source a query listens to.Set to default to listen to both cache and server changes. Set to cache to listen to changes in cache only. | -| [MemoryCacheSettings](./firestore_.md#memorycachesettings) | An settings object to configure an MemoryLocalCache instance. | -| [MemoryEagerGarbageCollector](./firestore_.md#memoryeagergarbagecollector) | A garbage collector deletes documents whenever they are not part of any active queries, and have no local mutations attached to them.This collector tries to ensure lowest memory footprints from the SDK, at the risk of documents not being cached for offline queries or for direct queries to the cache.Use factory function to create an instance of this collector. | | [MemoryGarbageCollector](./firestore_.md#memorygarbagecollector) | Union type from all support garbage collectors for memory local cache. | -| [MemoryLocalCache](./firestore_.md#memorylocalcache) | Provides an in-memory cache to the SDK. This is the default cache unless explicitly configured otherwise.To use, create an instance using the factory function , then set the instance to FirestoreSettings.cache and call initializeFirestore using the settings object. | -| [MemoryLruGarbageCollector](./firestore_.md#memorylrugarbagecollector) | A garbage collector deletes Least-Recently-Used documents in multiple batches.This collector is configured with a target size, and will only perform collection when the cached documents exceed the target size. It avoids querying backend repeated for the same query or document, at the risk of having a larger memory footprint.Use factory function to create a instance of this collector. | | [NestedUpdateFields](./firestore_.md#nestedupdatefields) | For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1, 'bar.qux': T2}). Intersect them together to make a single map containing all possible keys that are all marked as optional | | [OrderByDirection](./firestore_.md#orderbydirection) | The direction of a [orderBy()](./firestore_.md#orderby_006d61f) clause is specified as 'desc' or 'asc' (descending or ascending). | | [PartialWithFieldValue](./firestore_.md#partialwithfieldvalue) | Similar to TypeScript's Partial<T>, but allows nested fields to be omitted and FieldValues to be passed in as property values. | -| [PersistentCacheSettings](./firestore_.md#persistentcachesettings) | An settings object to configure an PersistentLocalCache instance.Persistent cache cannot be used in a Node.js environment. | -| [PersistentLocalCache](./firestore_.md#persistentlocalcache) | Provides a persistent cache backed by IndexedDb to the SDK.To use, create an instance using the factory function , then set the instance to FirestoreSettings.cache and call initializeFirestore using the settings object. | -| [PersistentMultipleTabManager](./firestore_.md#persistentmultipletabmanager) | A tab manager supporting multiple tabs. SDK will synchronize queries and mutations done across all tabs using the SDK. | -| [PersistentSingleTabManager](./firestore_.md#persistentsingletabmanager) | A tab manager supporting only one tab, no synchronization will be performed across tabs. | -| [PersistentSingleTabManagerSettings](./firestore_.md#persistentsingletabmanagersettings) | Type to configure an PersistentSingleTabManager instance. | | [PersistentTabManager](./firestore_.md#persistenttabmanager) | A union of all available tab managers. | | [Primitive](./firestore_.md#primitive) | Primitive types. | | [QueryConstraintType](./firestore_.md#queryconstrainttype) | Describes the different query constraints available in this SDK. | @@ -924,7 +924,7 @@ export declare function memoryEagerGarbageCollector(): MemoryEagerGarbageCollect ``` Returns: -[MemoryEagerGarbageCollector](./firestore_.md#memoryeagergarbagecollector) +[MemoryEagerGarbageCollector](./firestore_.memoryeagergarbagecollector.md#memoryeagergarbagecollector_interface) ### persistentMultipleTabManager() {:#persistentmultipletabmanager} @@ -937,7 +937,7 @@ export declare function persistentMultipleTabManager(): PersistentMultipleTabMan ``` Returns: -[PersistentMultipleTabManager](./firestore_.md#persistentmultipletabmanager) +[PersistentMultipleTabManager](./firestore_.persistentmultipletabmanager.md#persistentmultipletabmanager_interface) ### serverTimestamp() {:#servertimestamp} @@ -2293,11 +2293,11 @@ export declare function memoryLocalCache(settings?: MemoryCacheSettings): Memory | Parameter | Type | Description | | --- | --- | --- | -| settings | [MemoryCacheSettings](./firestore_.md#memorycachesettings) | | +| settings | [MemoryCacheSettings](./firestore_.memorycachesettings.md#memorycachesettings_interface) | | Returns: -[MemoryLocalCache](./firestore_.md#memorylocalcache) +[MemoryLocalCache](./firestore_.memorylocalcache.md#memorylocalcache_interface) ### memoryLruGarbageCollector(settings) {:#memorylrugarbagecollector_5ee014c} @@ -2321,7 +2321,7 @@ export declare function memoryLruGarbageCollector(settings?: { Returns: -[MemoryLruGarbageCollector](./firestore_.md#memorylrugarbagecollector) +[MemoryLruGarbageCollector](./firestore_.memorylrugarbagecollector.md#memorylrugarbagecollector_interface) ### persistentLocalCache(settings) {:#persistentlocalcache_d312f71} @@ -2339,11 +2339,11 @@ export declare function persistentLocalCache(settings?: PersistentCacheSettings) | Parameter | Type | Description | | --- | --- | --- | -| settings | [PersistentCacheSettings](./firestore_.md#persistentcachesettings) | | +| settings | [PersistentCacheSettings](./firestore_.persistentcachesettings.md#persistentcachesettings_interface) | | Returns: -[PersistentLocalCache](./firestore_.md#persistentlocalcache) +[PersistentLocalCache](./firestore_.persistentlocalcache.md#persistentlocalcache_interface) ### persistentSingleTabManager(settings) {:#persistentsingletabmanager_c99c68d} @@ -2359,11 +2359,11 @@ export declare function persistentSingleTabManager(settings: PersistentSingleTab | Parameter | Type | Description | | --- | --- | --- | -| settings | [PersistentSingleTabManagerSettings](./firestore_.md#persistentsingletabmanagersettings) \| undefined | Configures the created tab manager. | +| settings | [PersistentSingleTabManagerSettings](./firestore_.persistentsingletabmanagersettings.md#persistentsingletabmanagersettings_interface) \| undefined | Configures the created tab manager. | Returns: -[PersistentSingleTabManager](./firestore_.md#persistentsingletabmanager) +[PersistentSingleTabManager](./firestore_.persistentsingletabmanager.md#persistentsingletabmanager_interface) ## function(snapshot, ...) @@ -2591,34 +2591,6 @@ Set to `default` to listen to both cache and server changes. Set to `cache` to l export declare type ListenSource = 'default' | 'cache'; ``` -## MemoryCacheSettings - -An settings object to configure an `MemoryLocalCache` instance. - -Signature: - -```typescript -export declare type MemoryCacheSettings = { - garbageCollector?: MemoryGarbageCollector; -}; -``` - -## MemoryEagerGarbageCollector - -A garbage collector deletes documents whenever they are not part of any active queries, and have no local mutations attached to them. - -This collector tries to ensure lowest memory footprints from the SDK, at the risk of documents not being cached for offline queries or for direct queries to the cache. - -Use factory function to create an instance of this collector. - -Signature: - -```typescript -export declare type MemoryEagerGarbageCollector = { - kind: 'memoryEager'; -}; -``` - ## MemoryGarbageCollector Union type from all support garbage collectors for memory local cache. @@ -2629,36 +2601,6 @@ Union type from all support garbage collectors for memory local cache. export declare type MemoryGarbageCollector = MemoryEagerGarbageCollector | MemoryLruGarbageCollector; ``` -## MemoryLocalCache - -Provides an in-memory cache to the SDK. This is the default cache unless explicitly configured otherwise. - -To use, create an instance using the factory function , then set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using the settings object. - -Signature: - -```typescript -export declare type MemoryLocalCache = { - kind: 'memory'; -}; -``` - -## MemoryLruGarbageCollector - -A garbage collector deletes Least-Recently-Used documents in multiple batches. - -This collector is configured with a target size, and will only perform collection when the cached documents exceed the target size. It avoids querying backend repeated for the same query or document, at the risk of having a larger memory footprint. - -Use factory function to create a instance of this collector. - -Signature: - -```typescript -export declare type MemoryLruGarbageCollector = { - kind: 'memoryLru'; -}; -``` - ## NestedUpdateFields For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1, 'bar.qux': T2}). Intersect them together to make a single map containing all possible keys that are all marked as optional @@ -2693,71 +2635,6 @@ export declare type PartialWithFieldValue = Partial | (T extends Primitive } : never); ``` -## PersistentCacheSettings - -An settings object to configure an `PersistentLocalCache` instance. - -Persistent cache cannot be used in a Node.js environment. - -Signature: - -```typescript -export declare type PersistentCacheSettings = { - cacheSizeBytes?: number; - tabManager?: PersistentTabManager; -}; -``` - -## PersistentLocalCache - -Provides a persistent cache backed by IndexedDb to the SDK. - -To use, create an instance using the factory function , then set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using the settings object. - -Signature: - -```typescript -export declare type PersistentLocalCache = { - kind: 'persistent'; -}; -``` - -## PersistentMultipleTabManager - -A tab manager supporting multiple tabs. SDK will synchronize queries and mutations done across all tabs using the SDK. - -Signature: - -```typescript -export declare type PersistentMultipleTabManager = { - kind: 'PersistentMultipleTab'; -}; -``` - -## PersistentSingleTabManager - -A tab manager supporting only one tab, no synchronization will be performed across tabs. - -Signature: - -```typescript -export declare type PersistentSingleTabManager = { - kind: 'persistentSingleTab'; -}; -``` - -## PersistentSingleTabManagerSettings - -Type to configure an `PersistentSingleTabManager` instance. - -Signature: - -```typescript -export declare type PersistentSingleTabManagerSettings = { - forceOwnership?: boolean; -}; -``` - ## PersistentTabManager A union of all available tab managers. diff --git a/docs-devsite/firestore_.memorycachesettings.md b/docs-devsite/firestore_.memorycachesettings.md new file mode 100644 index 00000000000..69f46acdf7c --- /dev/null +++ b/docs-devsite/firestore_.memorycachesettings.md @@ -0,0 +1,35 @@ +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 %} + +# MemoryCacheSettings interface +An settings object to configure an `MemoryLocalCache` instance. + +Signature: + +```typescript +export declare interface MemoryCacheSettings +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [garbageCollector](./firestore_.memorycachesettings.md#memorycachesettingsgarbagecollector) | [MemoryGarbageCollector](./firestore_.md#memorygarbagecollector) | The garbage collector to use, for the memory cache layer. A MemoryEagerGarbageCollector is used when this is undefined. | + +## MemoryCacheSettings.garbageCollector + +The garbage collector to use, for the memory cache layer. A `MemoryEagerGarbageCollector` is used when this is undefined. + +Signature: + +```typescript +garbageCollector?: MemoryGarbageCollector; +``` diff --git a/docs-devsite/firestore_.memoryeagergarbagecollector.md b/docs-devsite/firestore_.memoryeagergarbagecollector.md new file mode 100644 index 00000000000..01e7341611a --- /dev/null +++ b/docs-devsite/firestore_.memoryeagergarbagecollector.md @@ -0,0 +1,37 @@ +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 %} + +# MemoryEagerGarbageCollector interface +A garbage collector deletes documents whenever they are not part of any active queries, and have no local mutations attached to them. + +This collector tries to ensure lowest memory footprints from the SDK, at the risk of documents not being cached for offline queries or for direct queries to the cache. + +Use factory function to create an instance of this collector. + +Signature: + +```typescript +export declare interface MemoryEagerGarbageCollector +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [kind](./firestore_.memoryeagergarbagecollector.md#memoryeagergarbagecollectorkind) | 'memoryEager' | | + +## MemoryEagerGarbageCollector.kind + +Signature: + +```typescript +kind: 'memoryEager'; +``` diff --git a/docs-devsite/firestore_.memorylocalcache.md b/docs-devsite/firestore_.memorylocalcache.md new file mode 100644 index 00000000000..92b7d3a2c72 --- /dev/null +++ b/docs-devsite/firestore_.memorylocalcache.md @@ -0,0 +1,35 @@ +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 %} + +# MemoryLocalCache interface +Provides an in-memory cache to the SDK. This is the default cache unless explicitly configured otherwise. + +To use, create an instance using the factory function , then set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using the settings object. + +Signature: + +```typescript +export declare interface MemoryLocalCache +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [kind](./firestore_.memorylocalcache.md#memorylocalcachekind) | 'memory' | | + +## MemoryLocalCache.kind + +Signature: + +```typescript +kind: 'memory'; +``` diff --git a/docs-devsite/firestore_.memorylrugarbagecollector.md b/docs-devsite/firestore_.memorylrugarbagecollector.md new file mode 100644 index 00000000000..6e15513934a --- /dev/null +++ b/docs-devsite/firestore_.memorylrugarbagecollector.md @@ -0,0 +1,37 @@ +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 %} + +# MemoryLruGarbageCollector interface +A garbage collector deletes Least-Recently-Used documents in multiple batches. + +This collector is configured with a target size, and will only perform collection when the cached documents exceed the target size. It avoids querying backend repeated for the same query or document, at the risk of having a larger memory footprint. + +Use factory function to create a instance of this collector. + +Signature: + +```typescript +export declare interface MemoryLruGarbageCollector +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [kind](./firestore_.memorylrugarbagecollector.md#memorylrugarbagecollectorkind) | 'memoryLru' | | + +## MemoryLruGarbageCollector.kind + +Signature: + +```typescript +kind: 'memoryLru'; +``` diff --git a/docs-devsite/firestore_.persistentcachesettings.md b/docs-devsite/firestore_.persistentcachesettings.md new file mode 100644 index 00000000000..a32d05e4e8e --- /dev/null +++ b/docs-devsite/firestore_.persistentcachesettings.md @@ -0,0 +1,50 @@ +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 %} + +# PersistentCacheSettings interface +An settings object to configure an `PersistentLocalCache` instance. + +Persistent cache cannot be used in a Node.js environment. + +Signature: + +```typescript +export declare interface PersistentCacheSettings +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [cacheSizeBytes](./firestore_.persistentcachesettings.md#persistentcachesettingscachesizebytes) | number | An approximate cache size threshold for the on-disk data. If the cache grows beyond this size, Firestore will start removing data that hasn't been recently used. The SDK does not guarantee that the cache will stay below that size, only that if the cache exceeds the given size, cleanup will be attempted.The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to CACHE_SIZE_UNLIMITED to disable garbage collection. | +| [tabManager](./firestore_.persistentcachesettings.md#persistentcachesettingstabmanager) | [PersistentTabManager](./firestore_.md#persistenttabmanager) | Specifies how multiple tabs/windows will be managed by the SDK. | + +## PersistentCacheSettings.cacheSizeBytes + +An approximate cache size threshold for the on-disk data. If the cache grows beyond this size, Firestore will start removing data that hasn't been recently used. The SDK does not guarantee that the cache will stay below that size, only that if the cache exceeds the given size, cleanup will be attempted. + +The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to `CACHE_SIZE_UNLIMITED` to disable garbage collection. + +Signature: + +```typescript +cacheSizeBytes?: number; +``` + +## PersistentCacheSettings.tabManager + +Specifies how multiple tabs/windows will be managed by the SDK. + +Signature: + +```typescript +tabManager?: PersistentTabManager; +``` diff --git a/docs-devsite/firestore_.persistentlocalcache.md b/docs-devsite/firestore_.persistentlocalcache.md new file mode 100644 index 00000000000..48d876d15bd --- /dev/null +++ b/docs-devsite/firestore_.persistentlocalcache.md @@ -0,0 +1,35 @@ +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 %} + +# PersistentLocalCache interface +Provides a persistent cache backed by IndexedDb to the SDK. + +To use, create an instance using the factory function , then set the instance to `FirestoreSettings.cache` and call `initializeFirestore` using the settings object. + +Signature: + +```typescript +export declare interface PersistentLocalCache +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [kind](./firestore_.persistentlocalcache.md#persistentlocalcachekind) | 'persistent' | | + +## PersistentLocalCache.kind + +Signature: + +```typescript +kind: 'persistent'; +``` diff --git a/docs-devsite/firestore_.persistentmultipletabmanager.md b/docs-devsite/firestore_.persistentmultipletabmanager.md new file mode 100644 index 00000000000..20d9cc24452 --- /dev/null +++ b/docs-devsite/firestore_.persistentmultipletabmanager.md @@ -0,0 +1,33 @@ +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 %} + +# PersistentMultipleTabManager interface +A tab manager supporting multiple tabs. SDK will synchronize queries and mutations done across all tabs using the SDK. + +Signature: + +```typescript +export declare interface PersistentMultipleTabManager +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [kind](./firestore_.persistentmultipletabmanager.md#persistentmultipletabmanagerkind) | 'PersistentMultipleTab' | | + +## PersistentMultipleTabManager.kind + +Signature: + +```typescript +kind: 'PersistentMultipleTab'; +``` diff --git a/docs-devsite/firestore_.persistentsingletabmanager.md b/docs-devsite/firestore_.persistentsingletabmanager.md new file mode 100644 index 00000000000..22601cf31fb --- /dev/null +++ b/docs-devsite/firestore_.persistentsingletabmanager.md @@ -0,0 +1,33 @@ +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 %} + +# PersistentSingleTabManager interface +A tab manager supporting only one tab, no synchronization will be performed across tabs. + +Signature: + +```typescript +export declare interface PersistentSingleTabManager +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [kind](./firestore_.persistentsingletabmanager.md#persistentsingletabmanagerkind) | 'persistentSingleTab' | | + +## PersistentSingleTabManager.kind + +Signature: + +```typescript +kind: 'persistentSingleTab'; +``` diff --git a/docs-devsite/firestore_.persistentsingletabmanagersettings.md b/docs-devsite/firestore_.persistentsingletabmanagersettings.md new file mode 100644 index 00000000000..afe2842d4c4 --- /dev/null +++ b/docs-devsite/firestore_.persistentsingletabmanagersettings.md @@ -0,0 +1,35 @@ +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 %} + +# PersistentSingleTabManagerSettings interface +Type to configure an `PersistentSingleTabManager` instance. + +Signature: + +```typescript +export declare interface PersistentSingleTabManagerSettings +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [forceOwnership](./firestore_.persistentsingletabmanagersettings.md#persistentsingletabmanagersettingsforceownership) | boolean | Whether to force-enable persistent (IndexedDB) cache for the client. This cannot be used with multi-tab synchronization and is primarily intended for use with Web Workers. Setting this to true will enable IndexedDB, but cause other tabs using IndexedDB cache to fail. | + +## PersistentSingleTabManagerSettings.forceOwnership + +Whether to force-enable persistent (IndexedDB) cache for the client. This cannot be used with multi-tab synchronization and is primarily intended for use with Web Workers. Setting this to `true` will enable IndexedDB, but cause other tabs using IndexedDB cache to fail. + +Signature: + +```typescript +forceOwnership?: boolean; +``` From 4f8a3cbdbe8b32bcb4ed1e0c8d2fbbfce917c90b Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 9 May 2025 10:18:16 -0400 Subject: [PATCH 21/32] Replace @firebase/vertexai with @firebase/ai --- .../workflows/check-vertexai-responses.yml | 2 +- common/api-review/ai.api.md | 955 ++++++++++++++++++ packages/{vertexai => ai}/.eslintrc.js | 0 packages/{vertexai => ai}/CHANGELOG.md | 2 +- packages/{vertexai => ai}/README.md | 4 +- packages/{vertexai => ai}/api-extractor.json | 0 packages/{vertexai => ai}/karma.conf.js | 0 packages/{vertexai => ai}/package.json | 12 +- packages/{vertexai => ai}/rollup.config.js | 0 packages/{vertexai => ai}/src/api.test.ts | 0 packages/{vertexai => ai}/src/api.ts | 0 packages/{vertexai => ai}/src/backend.test.ts | 0 packages/{vertexai => ai}/src/backend.ts | 0 .../src/backwards-compatbility.test.ts | 0 packages/{vertexai => ai}/src/constants.ts | 0 packages/{vertexai => ai}/src/errors.ts | 0 .../src/googleai-mappers.test.ts | 0 .../{vertexai => ai}/src/googleai-mappers.ts | 0 packages/{vertexai => ai}/src/helpers.test.ts | 0 packages/{vertexai => ai}/src/helpers.ts | 0 packages/{vertexai => ai}/src/index.node.ts | 0 packages/{vertexai => ai}/src/index.ts | 0 packages/{vertexai => ai}/src/logger.ts | 0 .../src/methods/chat-session-helpers.test.ts | 0 .../src/methods/chat-session-helpers.ts | 0 .../src/methods/chat-session.test.ts | 0 .../src/methods/chat-session.ts | 0 .../src/methods/count-tokens.test.ts | 0 .../src/methods/count-tokens.ts | 0 .../src/methods/generate-content.test.ts | 0 .../src/methods/generate-content.ts | 0 .../src/models/ai-model.test.ts | 0 .../{vertexai => ai}/src/models/ai-model.ts | 0 .../src/models/generative-model.test.ts | 0 .../src/models/generative-model.ts | 0 .../src/models/imagen-model.test.ts | 0 .../src/models/imagen-model.ts | 0 packages/{vertexai => ai}/src/models/index.ts | 0 packages/{vertexai => ai}/src/public-types.ts | 0 .../src/requests/imagen-image-format.ts | 0 .../src/requests/request-helpers.test.ts | 0 .../src/requests/request-helpers.ts | 0 .../src/requests/request.test.ts | 0 .../{vertexai => ai}/src/requests/request.ts | 0 .../src/requests/response-helpers.test.ts | 0 .../src/requests/response-helpers.ts | 0 .../src/requests/schema-builder.test.ts | 0 .../src/requests/schema-builder.ts | 0 .../src/requests/stream-reader.test.ts | 0 .../src/requests/stream-reader.ts | 0 packages/{vertexai => ai}/src/service.test.ts | 0 packages/{vertexai => ai}/src/service.ts | 0 .../{vertexai => ai}/src/types/content.ts | 0 packages/{vertexai => ai}/src/types/enums.ts | 0 packages/{vertexai => ai}/src/types/error.ts | 0 .../{vertexai => ai}/src/types/googleai.ts | 0 .../src/types/imagen/index.ts | 0 .../src/types/imagen/internal.ts | 0 .../src/types/imagen/requests.ts | 0 .../src/types/imagen/responses.ts | 0 packages/{vertexai => ai}/src/types/index.ts | 0 .../{vertexai => ai}/src/types/internal.ts | 0 .../{vertexai => ai}/src/types/requests.ts | 0 .../{vertexai => ai}/src/types/responses.ts | 0 packages/{vertexai => ai}/src/types/schema.ts | 0 .../{vertexai => ai}/test-utils/base64cat.ts | 0 packages/{vertexai => ai}/test-utils/cat.jpeg | Bin packages/{vertexai => ai}/test-utils/cat.png | Bin .../test-utils/convert-mocks.ts | 2 +- .../test-utils/mock-response.ts | 0 packages/{vertexai => ai}/tsconfig.json | 0 packages/app/src/constants.ts | 4 +- packages/firebase/ai/index.ts | 2 +- packages/firebase/ai/package.json | 4 +- packages/firebase/package.json | 28 +- packages/firebase/vertexai/index.ts | 2 +- packages/firebase/vertexai/package.json | 4 +- scripts/docgen/docgen.ts | 4 +- scripts/update_vertexai_responses.sh | 2 +- 79 files changed, 991 insertions(+), 36 deletions(-) create mode 100644 common/api-review/ai.api.md rename packages/{vertexai => ai}/.eslintrc.js (100%) rename packages/{vertexai => ai}/CHANGELOG.md (99%) rename packages/{vertexai => ai}/README.md (65%) rename packages/{vertexai => ai}/api-extractor.json (100%) rename packages/{vertexai => ai}/karma.conf.js (100%) rename packages/{vertexai => ai}/package.json (89%) rename packages/{vertexai => ai}/rollup.config.js (100%) rename packages/{vertexai => ai}/src/api.test.ts (100%) rename packages/{vertexai => ai}/src/api.ts (100%) rename packages/{vertexai => ai}/src/backend.test.ts (100%) rename packages/{vertexai => ai}/src/backend.ts (100%) rename packages/{vertexai => ai}/src/backwards-compatbility.test.ts (100%) rename packages/{vertexai => ai}/src/constants.ts (100%) rename packages/{vertexai => ai}/src/errors.ts (100%) rename packages/{vertexai => ai}/src/googleai-mappers.test.ts (100%) rename packages/{vertexai => ai}/src/googleai-mappers.ts (100%) rename packages/{vertexai => ai}/src/helpers.test.ts (100%) rename packages/{vertexai => ai}/src/helpers.ts (100%) rename packages/{vertexai => ai}/src/index.node.ts (100%) rename packages/{vertexai => ai}/src/index.ts (100%) rename packages/{vertexai => ai}/src/logger.ts (100%) rename packages/{vertexai => ai}/src/methods/chat-session-helpers.test.ts (100%) rename packages/{vertexai => ai}/src/methods/chat-session-helpers.ts (100%) rename packages/{vertexai => ai}/src/methods/chat-session.test.ts (100%) rename packages/{vertexai => ai}/src/methods/chat-session.ts (100%) rename packages/{vertexai => ai}/src/methods/count-tokens.test.ts (100%) rename packages/{vertexai => ai}/src/methods/count-tokens.ts (100%) rename packages/{vertexai => ai}/src/methods/generate-content.test.ts (100%) rename packages/{vertexai => ai}/src/methods/generate-content.ts (100%) rename packages/{vertexai => ai}/src/models/ai-model.test.ts (100%) rename packages/{vertexai => ai}/src/models/ai-model.ts (100%) rename packages/{vertexai => ai}/src/models/generative-model.test.ts (100%) rename packages/{vertexai => ai}/src/models/generative-model.ts (100%) rename packages/{vertexai => ai}/src/models/imagen-model.test.ts (100%) rename packages/{vertexai => ai}/src/models/imagen-model.ts (100%) rename packages/{vertexai => ai}/src/models/index.ts (100%) rename packages/{vertexai => ai}/src/public-types.ts (100%) rename packages/{vertexai => ai}/src/requests/imagen-image-format.ts (100%) rename packages/{vertexai => ai}/src/requests/request-helpers.test.ts (100%) rename packages/{vertexai => ai}/src/requests/request-helpers.ts (100%) rename packages/{vertexai => ai}/src/requests/request.test.ts (100%) rename packages/{vertexai => ai}/src/requests/request.ts (100%) rename packages/{vertexai => ai}/src/requests/response-helpers.test.ts (100%) rename packages/{vertexai => ai}/src/requests/response-helpers.ts (100%) rename packages/{vertexai => ai}/src/requests/schema-builder.test.ts (100%) rename packages/{vertexai => ai}/src/requests/schema-builder.ts (100%) rename packages/{vertexai => ai}/src/requests/stream-reader.test.ts (100%) rename packages/{vertexai => ai}/src/requests/stream-reader.ts (100%) rename packages/{vertexai => ai}/src/service.test.ts (100%) rename packages/{vertexai => ai}/src/service.ts (100%) rename packages/{vertexai => ai}/src/types/content.ts (100%) rename packages/{vertexai => ai}/src/types/enums.ts (100%) rename packages/{vertexai => ai}/src/types/error.ts (100%) rename packages/{vertexai => ai}/src/types/googleai.ts (100%) rename packages/{vertexai => ai}/src/types/imagen/index.ts (100%) rename packages/{vertexai => ai}/src/types/imagen/internal.ts (100%) rename packages/{vertexai => ai}/src/types/imagen/requests.ts (100%) rename packages/{vertexai => ai}/src/types/imagen/responses.ts (100%) rename packages/{vertexai => ai}/src/types/index.ts (100%) rename packages/{vertexai => ai}/src/types/internal.ts (100%) rename packages/{vertexai => ai}/src/types/requests.ts (100%) rename packages/{vertexai => ai}/src/types/responses.ts (100%) rename packages/{vertexai => ai}/src/types/schema.ts (100%) rename packages/{vertexai => ai}/test-utils/base64cat.ts (100%) rename packages/{vertexai => ai}/test-utils/cat.jpeg (100%) rename packages/{vertexai => ai}/test-utils/cat.png (100%) rename packages/{vertexai => ai}/test-utils/convert-mocks.ts (97%) rename packages/{vertexai => ai}/test-utils/mock-response.ts (100%) rename packages/{vertexai => ai}/tsconfig.json (100%) diff --git a/.github/workflows/check-vertexai-responses.yml b/.github/workflows/check-vertexai-responses.yml index 5014ad44266..4eceacd61b1 100644 --- a/.github/workflows/check-vertexai-responses.yml +++ b/.github/workflows/check-vertexai-responses.yml @@ -33,7 +33,7 @@ jobs: LATEST=$(git tag --sort=v:refname | tail -n1) echo "cloned_tag=$CLONED" >> $GITHUB_ENV echo "latest_tag=$LATEST" >> $GITHUB_ENV - working-directory: packages/vertexai/test-utils/vertexai-sdk-test-data + working-directory: packages/ai/test-utils/vertexai-sdk-test-data - name: Find comment from previous run if exists # This commit represents v3.1.0 uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e diff --git a/common/api-review/ai.api.md b/common/api-review/ai.api.md new file mode 100644 index 00000000000..7b6b42182c1 --- /dev/null +++ b/common/api-review/ai.api.md @@ -0,0 +1,955 @@ +## API Report File for "@firebase/ai" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import { AppCheckTokenResult } from '@firebase/app-check-interop-types'; +import { FirebaseApp } from '@firebase/app'; +import { FirebaseAuthTokenData } from '@firebase/auth-interop-types'; +import { FirebaseError } from '@firebase/util'; + +// @public +export interface AI { + app: FirebaseApp; + backend: Backend; + // @deprecated + location: string; +} + +// @public +export class AIError extends FirebaseError { + constructor(code: AIErrorCode, message: string, customErrorData?: CustomErrorData | undefined); + // (undocumented) + readonly code: AIErrorCode; + // (undocumented) + readonly customErrorData?: CustomErrorData | undefined; +} + +// @public +const enum AIErrorCode { + API_NOT_ENABLED = "api-not-enabled", + ERROR = "error", + FETCH_ERROR = "fetch-error", + INVALID_CONTENT = "invalid-content", + INVALID_SCHEMA = "invalid-schema", + NO_API_KEY = "no-api-key", + NO_APP_ID = "no-app-id", + NO_MODEL = "no-model", + NO_PROJECT_ID = "no-project-id", + PARSE_FAILED = "parse-failed", + REQUEST_ERROR = "request-error", + RESPONSE_ERROR = "response-error", + UNSUPPORTED = "unsupported" +} + +export { AIErrorCode } + +export { AIErrorCode as VertexAIErrorCode } + +// @public +export abstract class AIModel { + // @internal + protected constructor(ai: AI, modelName: string); + // Warning: (ae-forgotten-export) The symbol "ApiSettings" needs to be exported by the entry point index.d.ts + // + // @internal (undocumented) + protected _apiSettings: ApiSettings; + readonly model: string; + // @internal + static normalizeModelName(modelName: string, backendType: BackendType): string; + } + +// @public +export interface AIOptions { + backend: Backend; +} + +// @public +export class ArraySchema extends Schema { + constructor(schemaParams: SchemaParams, items: TypedSchema); + // (undocumented) + items: TypedSchema; + // @internal (undocumented) + toJSON(): SchemaRequest; +} + +// @public +export abstract class Backend { + protected constructor(type: BackendType); + readonly backendType: BackendType; +} + +// @public +export const BackendType: { + readonly VERTEX_AI: "VERTEX_AI"; + readonly GOOGLE_AI: "GOOGLE_AI"; +}; + +// @public +export type BackendType = (typeof BackendType)[keyof typeof BackendType]; + +// @public +export interface BaseParams { + // (undocumented) + generationConfig?: GenerationConfig; + // (undocumented) + safetySettings?: SafetySetting[]; +} + +// @public +export enum BlockReason { + BLOCKLIST = "BLOCKLIST", + OTHER = "OTHER", + PROHIBITED_CONTENT = "PROHIBITED_CONTENT", + SAFETY = "SAFETY" +} + +// @public +export class BooleanSchema extends Schema { + constructor(schemaParams?: SchemaParams); +} + +// @public +export class ChatSession { + constructor(apiSettings: ApiSettings, model: string, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined); + getHistory(): Promise; + // (undocumented) + model: string; + // (undocumented) + params?: StartChatParams | undefined; + // (undocumented) + requestOptions?: RequestOptions | undefined; + sendMessage(request: string | Array): Promise; + sendMessageStream(request: string | Array): Promise; + } + +// @public +export interface Citation { + // (undocumented) + endIndex?: number; + // (undocumented) + license?: string; + publicationDate?: Date_2; + // (undocumented) + startIndex?: number; + title?: string; + // (undocumented) + uri?: string; +} + +// @public +export interface CitationMetadata { + // (undocumented) + citations: Citation[]; +} + +// @public +export interface Content { + // (undocumented) + parts: Part[]; + // (undocumented) + role: Role; +} + +// @public +export interface CountTokensRequest { + // (undocumented) + contents: Content[]; + generationConfig?: GenerationConfig; + systemInstruction?: string | Part | Content; + tools?: Tool[]; +} + +// @public +export interface CountTokensResponse { + promptTokensDetails?: ModalityTokenCount[]; + totalBillableCharacters?: number; + totalTokens: number; +} + +// @public +export interface CustomErrorData { + errorDetails?: ErrorDetails[]; + response?: GenerateContentResponse; + status?: number; + statusText?: string; +} + +// @public +interface Date_2 { + // (undocumented) + day: number; + // (undocumented) + month: number; + // (undocumented) + year: number; +} + +export { Date_2 as Date } + +// @public +export interface EnhancedGenerateContentResponse extends GenerateContentResponse { + // (undocumented) + functionCalls: () => FunctionCall[] | undefined; + inlineDataParts: () => InlineDataPart[] | undefined; + text: () => string; +} + +// @public +export interface ErrorDetails { + // (undocumented) + '@type'?: string; + [key: string]: unknown; + domain?: string; + metadata?: Record; + reason?: string; +} + +// @public +export interface FileData { + // (undocumented) + fileUri: string; + // (undocumented) + mimeType: string; +} + +// @public +export interface FileDataPart { + // (undocumented) + fileData: FileData; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export enum FinishReason { + BLOCKLIST = "BLOCKLIST", + MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL", + MAX_TOKENS = "MAX_TOKENS", + OTHER = "OTHER", + PROHIBITED_CONTENT = "PROHIBITED_CONTENT", + RECITATION = "RECITATION", + SAFETY = "SAFETY", + SPII = "SPII", + STOP = "STOP" +} + +// @public +export interface FunctionCall { + // (undocumented) + args: object; + // (undocumented) + name: string; +} + +// @public (undocumented) +export interface FunctionCallingConfig { + // (undocumented) + allowedFunctionNames?: string[]; + // (undocumented) + mode?: FunctionCallingMode; +} + +// @public (undocumented) +export enum FunctionCallingMode { + ANY = "ANY", + AUTO = "AUTO", + NONE = "NONE" +} + +// @public +export interface FunctionCallPart { + // (undocumented) + functionCall: FunctionCall; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export interface FunctionDeclaration { + description: string; + name: string; + parameters?: ObjectSchemaInterface; +} + +// @public +export interface FunctionDeclarationsTool { + functionDeclarations?: FunctionDeclaration[]; +} + +// @public +export interface FunctionResponse { + // (undocumented) + name: string; + // (undocumented) + response: object; +} + +// @public +export interface FunctionResponsePart { + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse: FunctionResponse; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export interface GenerateContentCandidate { + // (undocumented) + citationMetadata?: CitationMetadata; + // (undocumented) + content: Content; + // (undocumented) + finishMessage?: string; + // (undocumented) + finishReason?: FinishReason; + // (undocumented) + groundingMetadata?: GroundingMetadata; + // (undocumented) + index: number; + // (undocumented) + safetyRatings?: SafetyRating[]; +} + +// @public +export interface GenerateContentRequest extends BaseParams { + // (undocumented) + contents: Content[]; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export interface GenerateContentResponse { + // (undocumented) + candidates?: GenerateContentCandidate[]; + // (undocumented) + promptFeedback?: PromptFeedback; + // (undocumented) + usageMetadata?: UsageMetadata; +} + +// @public +export interface GenerateContentResult { + // (undocumented) + response: EnhancedGenerateContentResponse; +} + +// @public +export interface GenerateContentStreamResult { + // (undocumented) + response: Promise; + // (undocumented) + stream: AsyncGenerator; +} + +// @public +export interface GenerationConfig { + // (undocumented) + candidateCount?: number; + // (undocumented) + frequencyPenalty?: number; + // (undocumented) + maxOutputTokens?: number; + // (undocumented) + presencePenalty?: number; + responseMimeType?: string; + // @beta + responseModalities?: ResponseModality[]; + responseSchema?: TypedSchema | SchemaRequest; + // (undocumented) + stopSequences?: string[]; + // (undocumented) + temperature?: number; + // (undocumented) + topK?: number; + // (undocumented) + topP?: number; +} + +// @public +export interface GenerativeContentBlob { + data: string; + // (undocumented) + mimeType: string; +} + +// @public +export class GenerativeModel extends AIModel { + constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions); + countTokens(request: CountTokensRequest | string | Array): Promise; + generateContent(request: GenerateContentRequest | string | Array): Promise; + generateContentStream(request: GenerateContentRequest | string | Array): Promise; + // (undocumented) + generationConfig: GenerationConfig; + // (undocumented) + requestOptions?: RequestOptions; + // (undocumented) + safetySettings: SafetySetting[]; + startChat(startChatParams?: StartChatParams): ChatSession; + // (undocumented) + systemInstruction?: Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export function getAI(app?: FirebaseApp, options?: AIOptions): AI; + +// @public +export function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; + +// @beta +export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; + +// @public +export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; + +// @public +export class GoogleAIBackend extends Backend { + constructor(); +} + +// Warning: (ae-internal-missing-underscore) The name "GoogleAICitationMetadata" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export interface GoogleAICitationMetadata { + // (undocumented) + citationSources: Citation[]; +} + +// Warning: (ae-internal-missing-underscore) The name "GoogleAICountTokensRequest" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export interface GoogleAICountTokensRequest { + // (undocumented) + generateContentRequest: { + model: string; + contents: Content[]; + systemInstruction?: string | Part | Content; + tools?: Tool[]; + generationConfig?: GenerationConfig; + }; +} + +// Warning: (ae-internal-missing-underscore) The name "GoogleAIGenerateContentCandidate" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export interface GoogleAIGenerateContentCandidate { + // (undocumented) + citationMetadata?: GoogleAICitationMetadata; + // (undocumented) + content: Content; + // (undocumented) + finishMessage?: string; + // (undocumented) + finishReason?: FinishReason; + // (undocumented) + groundingMetadata?: GroundingMetadata; + // (undocumented) + index: number; + // (undocumented) + safetyRatings?: SafetyRating[]; +} + +// Warning: (ae-internal-missing-underscore) The name "GoogleAIGenerateContentResponse" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal (undocumented) +export interface GoogleAIGenerateContentResponse { + // (undocumented) + candidates?: GoogleAIGenerateContentCandidate[]; + // (undocumented) + promptFeedback?: PromptFeedback; + // (undocumented) + usageMetadata?: UsageMetadata; +} + +// @public @deprecated (undocumented) +export interface GroundingAttribution { + // (undocumented) + confidenceScore?: number; + // (undocumented) + retrievedContext?: RetrievedContextAttribution; + // (undocumented) + segment: Segment; + // (undocumented) + web?: WebAttribution; +} + +// @public +export interface GroundingMetadata { + // @deprecated (undocumented) + groundingAttributions: GroundingAttribution[]; + // (undocumented) + retrievalQueries?: string[]; + // (undocumented) + webSearchQueries?: string[]; +} + +// @public +export enum HarmBlockMethod { + PROBABILITY = "PROBABILITY", + SEVERITY = "SEVERITY" +} + +// @public +export enum HarmBlockThreshold { + BLOCK_LOW_AND_ABOVE = "BLOCK_LOW_AND_ABOVE", + BLOCK_MEDIUM_AND_ABOVE = "BLOCK_MEDIUM_AND_ABOVE", + BLOCK_NONE = "BLOCK_NONE", + BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH" +} + +// @public +export enum HarmCategory { + // (undocumented) + HARM_CATEGORY_DANGEROUS_CONTENT = "HARM_CATEGORY_DANGEROUS_CONTENT", + // (undocumented) + HARM_CATEGORY_HARASSMENT = "HARM_CATEGORY_HARASSMENT", + // (undocumented) + HARM_CATEGORY_HATE_SPEECH = "HARM_CATEGORY_HATE_SPEECH", + // (undocumented) + HARM_CATEGORY_SEXUALLY_EXPLICIT = "HARM_CATEGORY_SEXUALLY_EXPLICIT" +} + +// @public +export enum HarmProbability { + HIGH = "HIGH", + LOW = "LOW", + MEDIUM = "MEDIUM", + NEGLIGIBLE = "NEGLIGIBLE" +} + +// @public +export enum HarmSeverity { + HARM_SEVERITY_HIGH = "HARM_SEVERITY_HIGH", + HARM_SEVERITY_LOW = "HARM_SEVERITY_LOW", + HARM_SEVERITY_MEDIUM = "HARM_SEVERITY_MEDIUM", + HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE", + HARM_SEVERITY_UNSUPPORTED = "HARM_SEVERITY_UNSUPPORTED" +} + +// @beta +export enum ImagenAspectRatio { + LANDSCAPE_16x9 = "16:9", + LANDSCAPE_3x4 = "3:4", + PORTRAIT_4x3 = "4:3", + PORTRAIT_9x16 = "9:16", + SQUARE = "1:1" +} + +// @public +export interface ImagenGCSImage { + gcsURI: string; + mimeType: string; +} + +// @beta +export interface ImagenGenerationConfig { + addWatermark?: boolean; + aspectRatio?: ImagenAspectRatio; + imageFormat?: ImagenImageFormat; + negativePrompt?: string; + numberOfImages?: number; +} + +// @beta +export interface ImagenGenerationResponse { + filteredReason?: string; + images: T[]; +} + +// @beta +export class ImagenImageFormat { + compressionQuality?: number; + static jpeg(compressionQuality?: number): ImagenImageFormat; + mimeType: string; + static png(): ImagenImageFormat; +} + +// @beta +export interface ImagenInlineImage { + bytesBase64Encoded: string; + mimeType: string; +} + +// @beta +export class ImagenModel extends AIModel { + constructor(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined); + generateImages(prompt: string): Promise>; + // @internal + generateImagesGCS(prompt: string, gcsURI: string): Promise>; + generationConfig?: ImagenGenerationConfig; + // (undocumented) + requestOptions?: RequestOptions | undefined; + safetySettings?: ImagenSafetySettings; +} + +// @beta +export interface ImagenModelParams { + generationConfig?: ImagenGenerationConfig; + model: string; + safetySettings?: ImagenSafetySettings; +} + +// @beta +export enum ImagenPersonFilterLevel { + ALLOW_ADULT = "allow_adult", + ALLOW_ALL = "allow_all", + BLOCK_ALL = "dont_allow" +} + +// @beta +export enum ImagenSafetyFilterLevel { + BLOCK_LOW_AND_ABOVE = "block_low_and_above", + BLOCK_MEDIUM_AND_ABOVE = "block_medium_and_above", + BLOCK_NONE = "block_none", + BLOCK_ONLY_HIGH = "block_only_high" +} + +// @beta +export interface ImagenSafetySettings { + personFilterLevel?: ImagenPersonFilterLevel; + safetyFilterLevel?: ImagenSafetyFilterLevel; +} + +// @public +export interface InlineDataPart { + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData: GenerativeContentBlob; + // (undocumented) + text?: never; + videoMetadata?: VideoMetadata; +} + +// @public +export class IntegerSchema extends Schema { + constructor(schemaParams?: SchemaParams); +} + +// @public +export enum Modality { + AUDIO = "AUDIO", + DOCUMENT = "DOCUMENT", + IMAGE = "IMAGE", + MODALITY_UNSPECIFIED = "MODALITY_UNSPECIFIED", + TEXT = "TEXT", + VIDEO = "VIDEO" +} + +// @public +export interface ModalityTokenCount { + modality: Modality; + tokenCount: number; +} + +// @public +export interface ModelParams extends BaseParams { + // (undocumented) + model: string; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export class NumberSchema extends Schema { + constructor(schemaParams?: SchemaParams); +} + +// @public +export class ObjectSchema extends Schema { + constructor(schemaParams: SchemaParams, properties: { + [k: string]: TypedSchema; + }, optionalProperties?: string[]); + // (undocumented) + optionalProperties: string[]; + // (undocumented) + properties: { + [k: string]: TypedSchema; + }; + // @internal (undocumented) + toJSON(): SchemaRequest; +} + +// @public +export interface ObjectSchemaInterface extends SchemaInterface { + // (undocumented) + optionalProperties?: string[]; + // (undocumented) + type: SchemaType.OBJECT; +} + +// @public +export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; + +// @public +export const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"]; + +// @public +export interface PromptFeedback { + // (undocumented) + blockReason?: BlockReason; + blockReasonMessage?: string; + // (undocumented) + safetyRatings: SafetyRating[]; +} + +// @public +export interface RequestOptions { + baseUrl?: string; + timeout?: number; +} + +// @beta +export const ResponseModality: { + readonly TEXT: "TEXT"; + readonly IMAGE: "IMAGE"; +}; + +// @beta +export type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality]; + +// @public (undocumented) +export interface RetrievedContextAttribution { + // (undocumented) + title: string; + // (undocumented) + uri: string; +} + +// @public +export type Role = (typeof POSSIBLE_ROLES)[number]; + +// @public +export interface SafetyRating { + // (undocumented) + blocked: boolean; + // (undocumented) + category: HarmCategory; + // (undocumented) + probability: HarmProbability; + probabilityScore: number; + severity: HarmSeverity; + severityScore: number; +} + +// @public +export interface SafetySetting { + // (undocumented) + category: HarmCategory; + method?: HarmBlockMethod; + // (undocumented) + threshold: HarmBlockThreshold; +} + +// @public +export abstract class Schema implements SchemaInterface { + constructor(schemaParams: SchemaInterface); + [key: string]: unknown; + // (undocumented) + static array(arrayParams: SchemaParams & { + items: Schema; + }): ArraySchema; + // (undocumented) + static boolean(booleanParams?: SchemaParams): BooleanSchema; + description?: string; + // (undocumented) + static enumString(stringParams: SchemaParams & { + enum: string[]; + }): StringSchema; + example?: unknown; + format?: string; + // (undocumented) + static integer(integerParams?: SchemaParams): IntegerSchema; + nullable: boolean; + // (undocumented) + static number(numberParams?: SchemaParams): NumberSchema; + // (undocumented) + static object(objectParams: SchemaParams & { + properties: { + [k: string]: Schema; + }; + optionalProperties?: string[]; + }): ObjectSchema; + // (undocumented) + static string(stringParams?: SchemaParams): StringSchema; + // @internal + toJSON(): SchemaRequest; + type: SchemaType; +} + +// @public +export interface SchemaInterface extends SchemaShared { + type: SchemaType; +} + +// @public +export interface SchemaParams extends SchemaShared { +} + +// @public +export interface SchemaRequest extends SchemaShared { + required?: string[]; + type: SchemaType; +} + +// @public +export interface SchemaShared { + // (undocumented) + [key: string]: unknown; + description?: string; + enum?: string[]; + example?: unknown; + format?: string; + items?: T; + nullable?: boolean; + properties?: { + [k: string]: T; + }; +} + +// @public +export enum SchemaType { + ARRAY = "array", + BOOLEAN = "boolean", + INTEGER = "integer", + NUMBER = "number", + OBJECT = "object", + STRING = "string" +} + +// @public (undocumented) +export interface Segment { + // (undocumented) + endIndex: number; + // (undocumented) + partIndex: number; + // (undocumented) + startIndex: number; +} + +// @public +export interface StartChatParams extends BaseParams { + // (undocumented) + history?: Content[]; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export class StringSchema extends Schema { + constructor(schemaParams?: SchemaParams, enumValues?: string[]); + // (undocumented) + enum?: string[]; + // @internal (undocumented) + toJSON(): SchemaRequest; +} + +// @public +export interface TextPart { + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text: string; +} + +// @public +export type Tool = FunctionDeclarationsTool; + +// @public +export interface ToolConfig { + // (undocumented) + functionCallingConfig?: FunctionCallingConfig; +} + +// @public +export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; + +// @public +export interface UsageMetadata { + // (undocumented) + candidatesTokenCount: number; + // (undocumented) + candidatesTokensDetails?: ModalityTokenCount[]; + // (undocumented) + promptTokenCount: number; + // (undocumented) + promptTokensDetails?: ModalityTokenCount[]; + // (undocumented) + totalTokenCount: number; +} + +// @public +export type VertexAI = AI; + +// @public +export class VertexAIBackend extends Backend { + constructor(location?: string); + readonly location: string; +} + +// @public +export const VertexAIError: typeof AIError; + +// @public +export const VertexAIModel: typeof AIModel; + +// @public +export interface VertexAIOptions { + // (undocumented) + location?: string; +} + +// @public +export interface VideoMetadata { + endOffset: string; + startOffset: string; +} + +// @public (undocumented) +export interface WebAttribution { + // (undocumented) + title: string; + // (undocumented) + uri: string; +} + + +``` diff --git a/packages/vertexai/.eslintrc.js b/packages/ai/.eslintrc.js similarity index 100% rename from packages/vertexai/.eslintrc.js rename to packages/ai/.eslintrc.js diff --git a/packages/vertexai/CHANGELOG.md b/packages/ai/CHANGELOG.md similarity index 99% rename from packages/vertexai/CHANGELOG.md rename to packages/ai/CHANGELOG.md index 8fa9e9d4b4a..a49b5dacbd4 100644 --- a/packages/vertexai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -1,4 +1,4 @@ -# @firebase/vertexai +# @firebase/ai ## 1.2.2 diff --git a/packages/vertexai/README.md b/packages/ai/README.md similarity index 65% rename from packages/vertexai/README.md rename to packages/ai/README.md index b559a1e739e..94c95e50b25 100644 --- a/packages/vertexai/README.md +++ b/packages/ai/README.md @@ -1,5 +1,5 @@ -# @firebase/vertexai +# @firebase/ai -This is the Firebase Vertex AI component of the Firebase JS SDK. +This is the Firebase AI component of the Firebase JS SDK. **This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.** diff --git a/packages/vertexai/api-extractor.json b/packages/ai/api-extractor.json similarity index 100% rename from packages/vertexai/api-extractor.json rename to packages/ai/api-extractor.json diff --git a/packages/vertexai/karma.conf.js b/packages/ai/karma.conf.js similarity index 100% rename from packages/vertexai/karma.conf.js rename to packages/ai/karma.conf.js diff --git a/packages/vertexai/package.json b/packages/ai/package.json similarity index 89% rename from packages/vertexai/package.json rename to packages/ai/package.json index 0c6b24fc495..d159793b206 100644 --- a/packages/vertexai/package.json +++ b/packages/ai/package.json @@ -1,7 +1,7 @@ { - "name": "@firebase/vertexai", + "name": "@firebase/ai", "version": "1.2.2", - "description": "A Firebase SDK for VertexAI", + "description": "The Firebase AI SDK", "author": "Firebase (https://firebase.google.com/)", "engines": { "node": ">=18.0.0" @@ -11,7 +11,7 @@ "module": "dist/esm/index.esm2017.js", "exports": { ".": { - "types": "./dist/vertexai-public.d.ts", + "types": "./dist/ai-public.d.ts", "node": { "require": "./dist/index.node.cjs.js", "import": "./dist/index.node.mjs" @@ -31,7 +31,7 @@ "lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'", "lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'", "build": "rollup -c && yarn api-report", - "build:deps": "lerna run --scope @firebase/vertexai --include-dependencies build", + "build:deps": "lerna run --scope @firebase/ai --include-dependencies build", "dev": "rollup -c -w", "update-responses": "../../scripts/update_vertexai_responses.sh", "testsetup": "yarn update-responses && yarn ts-node ./test-utils/convert-mocks.ts", @@ -40,7 +40,7 @@ "test:skip-clone": "karma start", "test:browser": "yarn testsetup && karma start", "api-report": "api-extractor run --local --verbose", - "typings:public": "node ../../scripts/build/use_typings.js ./dist/vertexai-public.d.ts", + "typings:public": "node ../../scripts/build/use_typings.js ./dist/ai-public.d.ts", "trusted-type-check": "tsec -p tsconfig.json --noEmit" }, "peerDependencies": { @@ -64,7 +64,7 @@ "typescript": "5.5.4" }, "repository": { - "directory": "packages/vertexai", + "directory": "packages/ai", "type": "git", "url": "git+https://github.com/firebase/firebase-js-sdk.git" }, diff --git a/packages/vertexai/rollup.config.js b/packages/ai/rollup.config.js similarity index 100% rename from packages/vertexai/rollup.config.js rename to packages/ai/rollup.config.js diff --git a/packages/vertexai/src/api.test.ts b/packages/ai/src/api.test.ts similarity index 100% rename from packages/vertexai/src/api.test.ts rename to packages/ai/src/api.test.ts diff --git a/packages/vertexai/src/api.ts b/packages/ai/src/api.ts similarity index 100% rename from packages/vertexai/src/api.ts rename to packages/ai/src/api.ts diff --git a/packages/vertexai/src/backend.test.ts b/packages/ai/src/backend.test.ts similarity index 100% rename from packages/vertexai/src/backend.test.ts rename to packages/ai/src/backend.test.ts diff --git a/packages/vertexai/src/backend.ts b/packages/ai/src/backend.ts similarity index 100% rename from packages/vertexai/src/backend.ts rename to packages/ai/src/backend.ts diff --git a/packages/vertexai/src/backwards-compatbility.test.ts b/packages/ai/src/backwards-compatbility.test.ts similarity index 100% rename from packages/vertexai/src/backwards-compatbility.test.ts rename to packages/ai/src/backwards-compatbility.test.ts diff --git a/packages/vertexai/src/constants.ts b/packages/ai/src/constants.ts similarity index 100% rename from packages/vertexai/src/constants.ts rename to packages/ai/src/constants.ts diff --git a/packages/vertexai/src/errors.ts b/packages/ai/src/errors.ts similarity index 100% rename from packages/vertexai/src/errors.ts rename to packages/ai/src/errors.ts diff --git a/packages/vertexai/src/googleai-mappers.test.ts b/packages/ai/src/googleai-mappers.test.ts similarity index 100% rename from packages/vertexai/src/googleai-mappers.test.ts rename to packages/ai/src/googleai-mappers.test.ts diff --git a/packages/vertexai/src/googleai-mappers.ts b/packages/ai/src/googleai-mappers.ts similarity index 100% rename from packages/vertexai/src/googleai-mappers.ts rename to packages/ai/src/googleai-mappers.ts diff --git a/packages/vertexai/src/helpers.test.ts b/packages/ai/src/helpers.test.ts similarity index 100% rename from packages/vertexai/src/helpers.test.ts rename to packages/ai/src/helpers.test.ts diff --git a/packages/vertexai/src/helpers.ts b/packages/ai/src/helpers.ts similarity index 100% rename from packages/vertexai/src/helpers.ts rename to packages/ai/src/helpers.ts diff --git a/packages/vertexai/src/index.node.ts b/packages/ai/src/index.node.ts similarity index 100% rename from packages/vertexai/src/index.node.ts rename to packages/ai/src/index.node.ts diff --git a/packages/vertexai/src/index.ts b/packages/ai/src/index.ts similarity index 100% rename from packages/vertexai/src/index.ts rename to packages/ai/src/index.ts diff --git a/packages/vertexai/src/logger.ts b/packages/ai/src/logger.ts similarity index 100% rename from packages/vertexai/src/logger.ts rename to packages/ai/src/logger.ts diff --git a/packages/vertexai/src/methods/chat-session-helpers.test.ts b/packages/ai/src/methods/chat-session-helpers.test.ts similarity index 100% rename from packages/vertexai/src/methods/chat-session-helpers.test.ts rename to packages/ai/src/methods/chat-session-helpers.test.ts diff --git a/packages/vertexai/src/methods/chat-session-helpers.ts b/packages/ai/src/methods/chat-session-helpers.ts similarity index 100% rename from packages/vertexai/src/methods/chat-session-helpers.ts rename to packages/ai/src/methods/chat-session-helpers.ts diff --git a/packages/vertexai/src/methods/chat-session.test.ts b/packages/ai/src/methods/chat-session.test.ts similarity index 100% rename from packages/vertexai/src/methods/chat-session.test.ts rename to packages/ai/src/methods/chat-session.test.ts diff --git a/packages/vertexai/src/methods/chat-session.ts b/packages/ai/src/methods/chat-session.ts similarity index 100% rename from packages/vertexai/src/methods/chat-session.ts rename to packages/ai/src/methods/chat-session.ts diff --git a/packages/vertexai/src/methods/count-tokens.test.ts b/packages/ai/src/methods/count-tokens.test.ts similarity index 100% rename from packages/vertexai/src/methods/count-tokens.test.ts rename to packages/ai/src/methods/count-tokens.test.ts diff --git a/packages/vertexai/src/methods/count-tokens.ts b/packages/ai/src/methods/count-tokens.ts similarity index 100% rename from packages/vertexai/src/methods/count-tokens.ts rename to packages/ai/src/methods/count-tokens.ts diff --git a/packages/vertexai/src/methods/generate-content.test.ts b/packages/ai/src/methods/generate-content.test.ts similarity index 100% rename from packages/vertexai/src/methods/generate-content.test.ts rename to packages/ai/src/methods/generate-content.test.ts diff --git a/packages/vertexai/src/methods/generate-content.ts b/packages/ai/src/methods/generate-content.ts similarity index 100% rename from packages/vertexai/src/methods/generate-content.ts rename to packages/ai/src/methods/generate-content.ts diff --git a/packages/vertexai/src/models/ai-model.test.ts b/packages/ai/src/models/ai-model.test.ts similarity index 100% rename from packages/vertexai/src/models/ai-model.test.ts rename to packages/ai/src/models/ai-model.test.ts diff --git a/packages/vertexai/src/models/ai-model.ts b/packages/ai/src/models/ai-model.ts similarity index 100% rename from packages/vertexai/src/models/ai-model.ts rename to packages/ai/src/models/ai-model.ts diff --git a/packages/vertexai/src/models/generative-model.test.ts b/packages/ai/src/models/generative-model.test.ts similarity index 100% rename from packages/vertexai/src/models/generative-model.test.ts rename to packages/ai/src/models/generative-model.test.ts diff --git a/packages/vertexai/src/models/generative-model.ts b/packages/ai/src/models/generative-model.ts similarity index 100% rename from packages/vertexai/src/models/generative-model.ts rename to packages/ai/src/models/generative-model.ts diff --git a/packages/vertexai/src/models/imagen-model.test.ts b/packages/ai/src/models/imagen-model.test.ts similarity index 100% rename from packages/vertexai/src/models/imagen-model.test.ts rename to packages/ai/src/models/imagen-model.test.ts diff --git a/packages/vertexai/src/models/imagen-model.ts b/packages/ai/src/models/imagen-model.ts similarity index 100% rename from packages/vertexai/src/models/imagen-model.ts rename to packages/ai/src/models/imagen-model.ts diff --git a/packages/vertexai/src/models/index.ts b/packages/ai/src/models/index.ts similarity index 100% rename from packages/vertexai/src/models/index.ts rename to packages/ai/src/models/index.ts diff --git a/packages/vertexai/src/public-types.ts b/packages/ai/src/public-types.ts similarity index 100% rename from packages/vertexai/src/public-types.ts rename to packages/ai/src/public-types.ts diff --git a/packages/vertexai/src/requests/imagen-image-format.ts b/packages/ai/src/requests/imagen-image-format.ts similarity index 100% rename from packages/vertexai/src/requests/imagen-image-format.ts rename to packages/ai/src/requests/imagen-image-format.ts diff --git a/packages/vertexai/src/requests/request-helpers.test.ts b/packages/ai/src/requests/request-helpers.test.ts similarity index 100% rename from packages/vertexai/src/requests/request-helpers.test.ts rename to packages/ai/src/requests/request-helpers.test.ts diff --git a/packages/vertexai/src/requests/request-helpers.ts b/packages/ai/src/requests/request-helpers.ts similarity index 100% rename from packages/vertexai/src/requests/request-helpers.ts rename to packages/ai/src/requests/request-helpers.ts diff --git a/packages/vertexai/src/requests/request.test.ts b/packages/ai/src/requests/request.test.ts similarity index 100% rename from packages/vertexai/src/requests/request.test.ts rename to packages/ai/src/requests/request.test.ts diff --git a/packages/vertexai/src/requests/request.ts b/packages/ai/src/requests/request.ts similarity index 100% rename from packages/vertexai/src/requests/request.ts rename to packages/ai/src/requests/request.ts diff --git a/packages/vertexai/src/requests/response-helpers.test.ts b/packages/ai/src/requests/response-helpers.test.ts similarity index 100% rename from packages/vertexai/src/requests/response-helpers.test.ts rename to packages/ai/src/requests/response-helpers.test.ts diff --git a/packages/vertexai/src/requests/response-helpers.ts b/packages/ai/src/requests/response-helpers.ts similarity index 100% rename from packages/vertexai/src/requests/response-helpers.ts rename to packages/ai/src/requests/response-helpers.ts diff --git a/packages/vertexai/src/requests/schema-builder.test.ts b/packages/ai/src/requests/schema-builder.test.ts similarity index 100% rename from packages/vertexai/src/requests/schema-builder.test.ts rename to packages/ai/src/requests/schema-builder.test.ts diff --git a/packages/vertexai/src/requests/schema-builder.ts b/packages/ai/src/requests/schema-builder.ts similarity index 100% rename from packages/vertexai/src/requests/schema-builder.ts rename to packages/ai/src/requests/schema-builder.ts diff --git a/packages/vertexai/src/requests/stream-reader.test.ts b/packages/ai/src/requests/stream-reader.test.ts similarity index 100% rename from packages/vertexai/src/requests/stream-reader.test.ts rename to packages/ai/src/requests/stream-reader.test.ts diff --git a/packages/vertexai/src/requests/stream-reader.ts b/packages/ai/src/requests/stream-reader.ts similarity index 100% rename from packages/vertexai/src/requests/stream-reader.ts rename to packages/ai/src/requests/stream-reader.ts diff --git a/packages/vertexai/src/service.test.ts b/packages/ai/src/service.test.ts similarity index 100% rename from packages/vertexai/src/service.test.ts rename to packages/ai/src/service.test.ts diff --git a/packages/vertexai/src/service.ts b/packages/ai/src/service.ts similarity index 100% rename from packages/vertexai/src/service.ts rename to packages/ai/src/service.ts diff --git a/packages/vertexai/src/types/content.ts b/packages/ai/src/types/content.ts similarity index 100% rename from packages/vertexai/src/types/content.ts rename to packages/ai/src/types/content.ts diff --git a/packages/vertexai/src/types/enums.ts b/packages/ai/src/types/enums.ts similarity index 100% rename from packages/vertexai/src/types/enums.ts rename to packages/ai/src/types/enums.ts diff --git a/packages/vertexai/src/types/error.ts b/packages/ai/src/types/error.ts similarity index 100% rename from packages/vertexai/src/types/error.ts rename to packages/ai/src/types/error.ts diff --git a/packages/vertexai/src/types/googleai.ts b/packages/ai/src/types/googleai.ts similarity index 100% rename from packages/vertexai/src/types/googleai.ts rename to packages/ai/src/types/googleai.ts diff --git a/packages/vertexai/src/types/imagen/index.ts b/packages/ai/src/types/imagen/index.ts similarity index 100% rename from packages/vertexai/src/types/imagen/index.ts rename to packages/ai/src/types/imagen/index.ts diff --git a/packages/vertexai/src/types/imagen/internal.ts b/packages/ai/src/types/imagen/internal.ts similarity index 100% rename from packages/vertexai/src/types/imagen/internal.ts rename to packages/ai/src/types/imagen/internal.ts diff --git a/packages/vertexai/src/types/imagen/requests.ts b/packages/ai/src/types/imagen/requests.ts similarity index 100% rename from packages/vertexai/src/types/imagen/requests.ts rename to packages/ai/src/types/imagen/requests.ts diff --git a/packages/vertexai/src/types/imagen/responses.ts b/packages/ai/src/types/imagen/responses.ts similarity index 100% rename from packages/vertexai/src/types/imagen/responses.ts rename to packages/ai/src/types/imagen/responses.ts diff --git a/packages/vertexai/src/types/index.ts b/packages/ai/src/types/index.ts similarity index 100% rename from packages/vertexai/src/types/index.ts rename to packages/ai/src/types/index.ts diff --git a/packages/vertexai/src/types/internal.ts b/packages/ai/src/types/internal.ts similarity index 100% rename from packages/vertexai/src/types/internal.ts rename to packages/ai/src/types/internal.ts diff --git a/packages/vertexai/src/types/requests.ts b/packages/ai/src/types/requests.ts similarity index 100% rename from packages/vertexai/src/types/requests.ts rename to packages/ai/src/types/requests.ts diff --git a/packages/vertexai/src/types/responses.ts b/packages/ai/src/types/responses.ts similarity index 100% rename from packages/vertexai/src/types/responses.ts rename to packages/ai/src/types/responses.ts diff --git a/packages/vertexai/src/types/schema.ts b/packages/ai/src/types/schema.ts similarity index 100% rename from packages/vertexai/src/types/schema.ts rename to packages/ai/src/types/schema.ts diff --git a/packages/vertexai/test-utils/base64cat.ts b/packages/ai/test-utils/base64cat.ts similarity index 100% rename from packages/vertexai/test-utils/base64cat.ts rename to packages/ai/test-utils/base64cat.ts diff --git a/packages/vertexai/test-utils/cat.jpeg b/packages/ai/test-utils/cat.jpeg similarity index 100% rename from packages/vertexai/test-utils/cat.jpeg rename to packages/ai/test-utils/cat.jpeg diff --git a/packages/vertexai/test-utils/cat.png b/packages/ai/test-utils/cat.png similarity index 100% rename from packages/vertexai/test-utils/cat.png rename to packages/ai/test-utils/cat.png diff --git a/packages/vertexai/test-utils/convert-mocks.ts b/packages/ai/test-utils/convert-mocks.ts similarity index 97% rename from packages/vertexai/test-utils/convert-mocks.ts rename to packages/ai/test-utils/convert-mocks.ts index 8690af4ac72..4bac70d1d10 100644 --- a/packages/vertexai/test-utils/convert-mocks.ts +++ b/packages/ai/test-utils/convert-mocks.ts @@ -47,7 +47,7 @@ function generateMockLookupFile(): void { const fileText = ` /** - * DO NOT EDIT - This file was generated by the packages/vertexai/test-utils/convert-mocks.ts script. + * DO NOT EDIT - This file was generated by the packages/ai/test-utils/convert-mocks.ts script. * * These objects map mock response filenames to their JSON contents. * diff --git a/packages/vertexai/test-utils/mock-response.ts b/packages/ai/test-utils/mock-response.ts similarity index 100% rename from packages/vertexai/test-utils/mock-response.ts rename to packages/ai/test-utils/mock-response.ts diff --git a/packages/vertexai/tsconfig.json b/packages/ai/tsconfig.json similarity index 100% rename from packages/vertexai/tsconfig.json rename to packages/ai/tsconfig.json diff --git a/packages/app/src/constants.ts b/packages/app/src/constants.ts index 8ef4eada39c..21ded00529a 100644 --- a/packages/app/src/constants.ts +++ b/packages/app/src/constants.ts @@ -39,7 +39,7 @@ import { name as remoteConfigCompatName } from '../../../packages/remote-config- import { name as storageName } from '../../../packages/storage/package.json'; import { name as storageCompatName } from '../../../packages/storage-compat/package.json'; import { name as firestoreName } from '../../../packages/firestore/package.json'; -import { name as vertexName } from '../../../packages/vertexai/package.json'; +import { name as aiName } from '../../../packages/ai/package.json'; import { name as firestoreCompatName } from '../../../packages/firestore-compat/package.json'; import { name as packageName } from '../../../packages/firebase/package.json'; @@ -76,7 +76,7 @@ export const PLATFORM_LOG_STRING = { [storageCompatName]: 'fire-gcs-compat', [firestoreName]: 'fire-fst', [firestoreCompatName]: 'fire-fst-compat', - [vertexName]: 'fire-vertex', + [aiName]: 'fire-vertex', 'fire-js': 'fire-js', // Platform identifier for JS SDK. [packageName]: 'fire-js-all' } as const; diff --git a/packages/firebase/ai/index.ts b/packages/firebase/ai/index.ts index 2645fd3004f..530f99162ed 100644 --- a/packages/firebase/ai/index.ts +++ b/packages/firebase/ai/index.ts @@ -15,4 +15,4 @@ * limitations under the License. */ -export * from '@firebase/vertexai'; +export * from '@firebase/ai'; diff --git a/packages/firebase/ai/package.json b/packages/firebase/ai/package.json index 75405002478..932f0f8d2a1 100644 --- a/packages/firebase/ai/package.json +++ b/packages/firebase/ai/package.json @@ -3,5 +3,5 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm.js", "module": "dist/esm/index.esm.js", - "typings": "dist/vertexai/index.d.ts" -} \ No newline at end of file + "typings": "dist/ai/index.d.ts" +} diff --git a/packages/firebase/package.json b/packages/firebase/package.json index c61bc701426..caaba0fd528 100644 --- a/packages/firebase/package.json +++ b/packages/firebase/package.json @@ -228,28 +228,28 @@ "default": "./storage/dist/esm/index.esm.js" }, "./ai": { - "types": "./vertexai/dist/vertexai/index.d.ts", + "types": "./ai/dist/ai/index.d.ts", "node": { - "require": "./vertexai/dist/index.cjs.js", - "import": "./vertexai/dist/index.mjs" + "require": "./ai/dist/index.cjs.js", + "import": "./ai/dist/index.mjs" }, "browser": { - "require": "./vertexai/dist/index.cjs.js", - "import": "./vertexai/dist/esm/index.esm.js" + "require": "./ai/dist/index.cjs.js", + "import": "./ai/dist/esm/index.esm.js" }, - "default": "./vertexai/dist/esm/index.esm.js" + "default": "./ai/dist/esm/index.esm.js" }, "./vertexai": { - "types": "./vertexai/dist/vertexai/index.d.ts", + "types": "./ai/dist/ai/index.d.ts", "node": { - "require": "./vertexai/dist/index.cjs.js", - "import": "./vertexai/dist/index.mjs" + "require": "./ai/dist/index.cjs.js", + "import": "./ai/dist/index.mjs" }, "browser": { - "require": "./vertexai/dist/index.cjs.js", - "import": "./vertexai/dist/esm/index.esm.js" + "require": "./ai/dist/index.cjs.js", + "import": "./ai/dist/esm/index.esm.js" }, - "default": "./vertexai/dist/esm/index.esm.js" + "default": "./ai/dist/esm/index.esm.js" }, "./compat/analytics": { "types": "./compat/analytics/dist/compat/analytics/index.d.ts", @@ -411,6 +411,7 @@ "trusted-type-check": "tsec -p tsconfig.json --noEmit" }, "dependencies": { + "@firebase/ai": "1.2.2", "@firebase/app": "0.12.1", "@firebase/app-compat": "0.3.1", "@firebase/app-types": "0.9.3", @@ -437,8 +438,7 @@ "@firebase/analytics-compat": "0.2.19", "@firebase/app-check": "0.9.1", "@firebase/app-check-compat": "0.3.22", - "@firebase/util": "1.11.1", - "@firebase/vertexai": "1.2.2" + "@firebase/util": "1.11.1" }, "devDependencies": { "rollup": "2.79.2", diff --git a/packages/firebase/vertexai/index.ts b/packages/firebase/vertexai/index.ts index 2645fd3004f..530f99162ed 100644 --- a/packages/firebase/vertexai/index.ts +++ b/packages/firebase/vertexai/index.ts @@ -15,4 +15,4 @@ * limitations under the License. */ -export * from '@firebase/vertexai'; +export * from '@firebase/ai'; diff --git a/packages/firebase/vertexai/package.json b/packages/firebase/vertexai/package.json index 20e04a3bbb5..3da541949dc 100644 --- a/packages/firebase/vertexai/package.json +++ b/packages/firebase/vertexai/package.json @@ -3,5 +3,5 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm.js", "module": "dist/esm/index.esm.js", - "typings": "dist/vertexai/index.d.ts" -} \ No newline at end of file + "typings": "dist/ai/index.d.ts" +} diff --git a/scripts/docgen/docgen.ts b/scripts/docgen/docgen.ts index 113e4a6b339..5d0ebd9088e 100644 --- a/scripts/docgen/docgen.ts +++ b/scripts/docgen/docgen.ts @@ -60,7 +60,7 @@ const PREFERRED_PARAMS = [ 'performance', 'remoteConfig', 'storage', - 'vertexAI' + 'vertexAI' // TODO (dlarocque-ai) ]; let authApiReportOriginal: string; @@ -133,7 +133,7 @@ function cleanup() { } catch (e) { console.error( 'Error cleaning up files on exit - ' + - 'check for temp modifications to md and json files.' + 'check for temp modifications to md and json files.' ); console.error(e); } diff --git a/scripts/update_vertexai_responses.sh b/scripts/update_vertexai_responses.sh index d80959febce..680a71ff776 100755 --- a/scripts/update_vertexai_responses.sh +++ b/scripts/update_vertexai_responses.sh @@ -21,7 +21,7 @@ RESPONSES_VERSION='v11.*' # The major version of mock responses to use REPO_NAME="vertexai-sdk-test-data" REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git" -cd "$(dirname "$0")/../packages/vertexai/test-utils" || exit +cd "$(dirname "$0")/../packages/ai/test-utils" || exit rm -rf "$REPO_NAME" git clone "$REPO_LINK" --quiet || exit cd "$REPO_NAME" || exit From 6b6eba4893c63890740ea6a6be4e7a9837ad0262 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 9 May 2025 10:30:36 -0400 Subject: [PATCH 22/32] ai docs --- docs-devsite/_toc.yaml | 298 ++++---- docs-devsite/ai.ai.md | 64 ++ .../{vertexai.aierror.md => ai.aierror.md} | 10 +- .../{vertexai.aimodel.md => ai.aimodel.md} | 2 +- ...{vertexai.aioptions.md => ai.aioptions.md} | 4 +- ...texai.arrayschema.md => ai.arrayschema.md} | 10 +- .../{vertexai.backend.md => ai.backend.md} | 8 +- ...ertexai.baseparams.md => ai.baseparams.md} | 4 +- ...i.booleanschema.md => ai.booleanschema.md} | 6 +- ...texai.chatsession.md => ai.chatsession.md} | 32 +- .../{vertexai.citation.md => ai.citation.md} | 16 +- ...tionmetadata.md => ai.citationmetadata.md} | 4 +- .../{vertexai.content.md => ai.content.md} | 4 +- ...ensrequest.md => ai.counttokensrequest.md} | 12 +- docs-devsite/ai.counttokensresponse.md | 59 ++ ...stomerrordata.md => ai.customerrordata.md} | 10 +- .../{vertexai.date_2.md => ai.date_2.md} | 6 +- .../ai.enhancedgeneratecontentresponse.md | 56 ++ ...xai.errordetails.md => ai.errordetails.md} | 8 +- .../{vertexai.filedata.md => ai.filedata.md} | 4 +- ...xai.filedatapart.md => ai.filedatapart.md} | 12 +- ...xai.functioncall.md => ai.functioncall.md} | 6 +- ...gconfig.md => ai.functioncallingconfig.md} | 4 +- ...tioncallpart.md => ai.functioncallpart.md} | 10 +- ...claration.md => ai.functiondeclaration.md} | 6 +- docs-devsite/ai.functiondeclarationstool.md | 35 + ...tionresponse.md => ai.functionresponse.md} | 6 +- ...onsepart.md => ai.functionresponsepart.md} | 10 +- ...date.md => ai.generatecontentcandidate.md} | 16 +- ...equest.md => ai.generatecontentrequest.md} | 12 +- docs-devsite/ai.generatecontentresponse.md | 51 ++ ...tresult.md => ai.generatecontentresult.md} | 4 +- ...t.md => ai.generatecontentstreamresult.md} | 6 +- docs-devsite/ai.generationconfig.md | 134 ++++ ...entblob.md => ai.generativecontentblob.md} | 4 +- docs-devsite/ai.generativemodel.md | 193 +++++ ...ogleaibackend.md => ai.googleaibackend.md} | 6 +- ...ribution.md => ai.groundingattribution.md} | 8 +- ...ingmetadata.md => ai.groundingmetadata.md} | 6 +- ...imagengcsimage.md => ai.imagengcsimage.md} | 6 +- ...config.md => ai.imagengenerationconfig.md} | 18 +- ...onse.md => ai.imagengenerationresponse.md} | 6 +- ...imageformat.md => ai.imagenimageformat.md} | 22 +- ...inlineimage.md => ai.imageninlineimage.md} | 6 +- ...texai.imagenmodel.md => ai.imagenmodel.md} | 24 +- ...modelparams.md => ai.imagenmodelparams.md} | 8 +- ...settings.md => ai.imagensafetysettings.md} | 4 +- ...inlinedatapart.md => ai.inlinedatapart.md} | 10 +- ...i.integerschema.md => ai.integerschema.md} | 6 +- docs-devsite/ai.md | 716 ++++++++++++++++++ ...tokencount.md => ai.modalitytokencount.md} | 4 +- ...texai.modelparams.md => ai.modelparams.md} | 12 +- ...xai.numberschema.md => ai.numberschema.md} | 6 +- ...xai.objectschema.md => ai.objectschema.md} | 12 +- ...terface.md => ai.objectschemainterface.md} | 8 +- ...promptfeedback.md => ai.promptfeedback.md} | 8 +- ...requestoptions.md => ai.requestoptions.md} | 6 +- ...n.md => ai.retrievedcontextattribution.md} | 4 +- docs-devsite/ai.safetyrating.md | 90 +++ docs-devsite/ai.safetysetting.md | 55 ++ .../{vertexai.schema.md => ai.schema.md} | 60 +- ...hemainterface.md => ai.schemainterface.md} | 8 +- ...xai.schemaparams.md => ai.schemaparams.md} | 4 +- ...i.schemarequest.md => ai.schemarequest.md} | 10 +- ...xai.schemashared.md => ai.schemashared.md} | 18 +- .../{vertexai.segment.md => ai.segment.md} | 6 +- ...artchatparams.md => ai.startchatparams.md} | 12 +- ...xai.stringschema.md => ai.stringschema.md} | 8 +- .../{vertexai.textpart.md => ai.textpart.md} | 8 +- ...ertexai.toolconfig.md => ai.toolconfig.md} | 2 +- ...i.usagemetadata.md => ai.usagemetadata.md} | 12 +- ...rtexaibackend.md => ai.vertexaibackend.md} | 8 +- ...rtexaioptions.md => ai.vertexaioptions.md} | 2 +- ...i.videometadata.md => ai.videometadata.md} | 4 +- ...webattribution.md => ai.webattribution.md} | 4 +- docs-devsite/index.md | 2 +- docs-devsite/vertexai.ai.md | 64 -- docs-devsite/vertexai.counttokensresponse.md | 59 -- ...ertexai.enhancedgeneratecontentresponse.md | 56 -- .../vertexai.functiondeclarationstool.md | 35 - .../vertexai.generatecontentresponse.md | 51 -- docs-devsite/vertexai.generationconfig.md | 134 ---- docs-devsite/vertexai.generativemodel.md | 193 ----- docs-devsite/vertexai.md | 716 ------------------ docs-devsite/vertexai.safetyrating.md | 90 --- docs-devsite/vertexai.safetysetting.md | 55 -- 86 files changed, 1899 insertions(+), 1899 deletions(-) create mode 100644 docs-devsite/ai.ai.md rename docs-devsite/{vertexai.aierror.md => ai.aierror.md} (65%) rename docs-devsite/{vertexai.aimodel.md => ai.aimodel.md} (84%) rename docs-devsite/{vertexai.aioptions.md => ai.aioptions.md} (59%) rename docs-devsite/{vertexai.arrayschema.md => ai.arrayschema.md} (69%) rename docs-devsite/{vertexai.backend.md => ai.backend.md} (66%) rename docs-devsite/{vertexai.baseparams.md => ai.baseparams.md} (69%) rename docs-devsite/{vertexai.booleanschema.md => ai.booleanschema.md} (71%) rename docs-devsite/{vertexai.chatsession.md => ai.chatsession.md} (52%) rename docs-devsite/{vertexai.citation.md => ai.citation.md} (55%) rename docs-devsite/{vertexai.citationmetadata.md => ai.citationmetadata.md} (73%) rename docs-devsite/{vertexai.content.md => ai.content.md} (79%) rename docs-devsite/{vertexai.counttokensrequest.md => ai.counttokensrequest.md} (52%) create mode 100644 docs-devsite/ai.counttokensresponse.md rename docs-devsite/{vertexai.customerrordata.md => ai.customerrordata.md} (55%) rename docs-devsite/{vertexai.date_2.md => ai.date_2.md} (80%) create mode 100644 docs-devsite/ai.enhancedgeneratecontentresponse.md rename docs-devsite/{vertexai.errordetails.md => ai.errordetails.md} (70%) rename docs-devsite/{vertexai.filedata.md => ai.filedata.md} (83%) rename docs-devsite/{vertexai.filedatapart.md => ai.filedatapart.md} (62%) rename docs-devsite/{vertexai.functioncall.md => ai.functioncall.md} (59%) rename docs-devsite/{vertexai.functioncallingconfig.md => ai.functioncallingconfig.md} (73%) rename docs-devsite/{vertexai.functioncallpart.md => ai.functioncallpart.md} (66%) rename docs-devsite/{vertexai.functiondeclaration.md => ai.functiondeclaration.md} (65%) create mode 100644 docs-devsite/ai.functiondeclarationstool.md rename docs-devsite/{vertexai.functionresponse.md => ai.functionresponse.md} (51%) rename docs-devsite/{vertexai.functionresponsepart.md => ai.functionresponsepart.md} (64%) rename docs-devsite/{vertexai.generatecontentcandidate.md => ai.generatecontentcandidate.md} (51%) rename docs-devsite/{vertexai.generatecontentrequest.md => ai.generatecontentrequest.md} (53%) create mode 100644 docs-devsite/ai.generatecontentresponse.md rename docs-devsite/{vertexai.generatecontentresult.md => ai.generatecontentresult.md} (71%) rename docs-devsite/{vertexai.generatecontentstreamresult.md => ai.generatecontentstreamresult.md} (54%) create mode 100644 docs-devsite/ai.generationconfig.md rename docs-devsite/{vertexai.generativecontentblob.md => ai.generativecontentblob.md} (78%) create mode 100644 docs-devsite/ai.generativemodel.md rename docs-devsite/{vertexai.googleaibackend.md => ai.googleaibackend.md} (64%) rename docs-devsite/{vertexai.groundingattribution.md => ai.groundingattribution.md} (61%) rename docs-devsite/{vertexai.groundingmetadata.md => ai.groundingmetadata.md} (68%) rename docs-devsite/{vertexai.imagengcsimage.md => ai.imagengcsimage.md} (62%) rename docs-devsite/{vertexai.imagengenerationconfig.md => ai.imagengenerationconfig.md} (52%) rename docs-devsite/{vertexai.imagengenerationresponse.md => ai.imagengenerationresponse.md} (56%) rename docs-devsite/{vertexai.imagenimageformat.md => ai.imagenimageformat.md} (61%) rename docs-devsite/{vertexai.imageninlineimage.md => ai.imageninlineimage.md} (66%) rename docs-devsite/{vertexai.imagenmodel.md => ai.imagenmodel.md} (62%) rename docs-devsite/{vertexai.imagenmodelparams.md => ai.imagenmodelparams.md} (63%) rename docs-devsite/{vertexai.imagensafetysettings.md => ai.imagensafetysettings.md} (72%) rename docs-devsite/{vertexai.inlinedatapart.md => ai.inlinedatapart.md} (62%) rename docs-devsite/{vertexai.integerschema.md => ai.integerschema.md} (71%) create mode 100644 docs-devsite/ai.md rename docs-devsite/{vertexai.modalitytokencount.md => ai.modalitytokencount.md} (74%) rename docs-devsite/{vertexai.modelparams.md => ai.modelparams.md} (57%) rename docs-devsite/{vertexai.numberschema.md => ai.numberschema.md} (72%) rename docs-devsite/{vertexai.objectschema.md => ai.objectschema.md} (68%) rename docs-devsite/{vertexai.objectschemainterface.md => ai.objectschemainterface.md} (62%) rename docs-devsite/{vertexai.promptfeedback.md => ai.promptfeedback.md} (60%) rename docs-devsite/{vertexai.requestoptions.md => ai.requestoptions.md} (67%) rename docs-devsite/{vertexai.retrievedcontextattribution.md => ai.retrievedcontextattribution.md} (77%) create mode 100644 docs-devsite/ai.safetyrating.md create mode 100644 docs-devsite/ai.safetysetting.md rename docs-devsite/{vertexai.schema.md => ai.schema.md} (53%) rename docs-devsite/{vertexai.schemainterface.md => ai.schemainterface.md} (55%) rename docs-devsite/{vertexai.schemaparams.md => ai.schemaparams.md} (58%) rename docs-devsite/{vertexai.schemarequest.md => ai.schemarequest.md} (53%) rename docs-devsite/{vertexai.schemashared.md => ai.schemashared.md} (51%) rename docs-devsite/{vertexai.segment.md => ai.segment.md} (77%) rename docs-devsite/{vertexai.startchatparams.md => ai.startchatparams.md} (54%) rename docs-devsite/{vertexai.stringschema.md => ai.stringschema.md} (72%) rename docs-devsite/{vertexai.textpart.md => ai.textpart.md} (74%) rename docs-devsite/{vertexai.toolconfig.md => ai.toolconfig.md} (78%) rename docs-devsite/{vertexai.usagemetadata.md => ai.usagemetadata.md} (56%) rename docs-devsite/{vertexai.vertexaibackend.md => ai.vertexaibackend.md} (67%) rename docs-devsite/{vertexai.vertexaioptions.md => ai.vertexaioptions.md} (88%) rename docs-devsite/{vertexai.videometadata.md => ai.videometadata.md} (75%) rename docs-devsite/{vertexai.webattribution.md => ai.webattribution.md} (81%) delete mode 100644 docs-devsite/vertexai.ai.md delete mode 100644 docs-devsite/vertexai.counttokensresponse.md delete mode 100644 docs-devsite/vertexai.enhancedgeneratecontentresponse.md delete mode 100644 docs-devsite/vertexai.functiondeclarationstool.md delete mode 100644 docs-devsite/vertexai.generatecontentresponse.md delete mode 100644 docs-devsite/vertexai.generationconfig.md delete mode 100644 docs-devsite/vertexai.generativemodel.md delete mode 100644 docs-devsite/vertexai.md delete mode 100644 docs-devsite/vertexai.safetyrating.md delete mode 100644 docs-devsite/vertexai.safetysetting.md diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index c507b44ce99..b77a6b5910e 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -1,6 +1,155 @@ toc: - title: firebase path: /docs/reference/js/index +- title: ai + path: /docs/reference/js/ai.md + section: + - title: AI + path: /docs/reference/js/ai.ai.md + - title: AIError + path: /docs/reference/js/ai.aierror.md + - title: AIModel + path: /docs/reference/js/ai.aimodel.md + - title: AIOptions + path: /docs/reference/js/ai.aioptions.md + - title: ArraySchema + path: /docs/reference/js/ai.arrayschema.md + - title: Backend + path: /docs/reference/js/ai.backend.md + - title: BaseParams + path: /docs/reference/js/ai.baseparams.md + - title: BooleanSchema + path: /docs/reference/js/ai.booleanschema.md + - title: ChatSession + path: /docs/reference/js/ai.chatsession.md + - title: Citation + path: /docs/reference/js/ai.citation.md + - title: CitationMetadata + path: /docs/reference/js/ai.citationmetadata.md + - title: Content + path: /docs/reference/js/ai.content.md + - title: CountTokensRequest + path: /docs/reference/js/ai.counttokensrequest.md + - title: CountTokensResponse + path: /docs/reference/js/ai.counttokensresponse.md + - title: CustomErrorData + path: /docs/reference/js/ai.customerrordata.md + - title: Date_2 + path: /docs/reference/js/ai.date_2.md + - title: EnhancedGenerateContentResponse + path: /docs/reference/js/ai.enhancedgeneratecontentresponse.md + - title: ErrorDetails + path: /docs/reference/js/ai.errordetails.md + - title: FileData + path: /docs/reference/js/ai.filedata.md + - title: FileDataPart + path: /docs/reference/js/ai.filedatapart.md + - title: FunctionCall + path: /docs/reference/js/ai.functioncall.md + - title: FunctionCallingConfig + path: /docs/reference/js/ai.functioncallingconfig.md + - title: FunctionCallPart + path: /docs/reference/js/ai.functioncallpart.md + - title: FunctionDeclaration + path: /docs/reference/js/ai.functiondeclaration.md + - title: FunctionDeclarationsTool + path: /docs/reference/js/ai.functiondeclarationstool.md + - title: FunctionResponse + path: /docs/reference/js/ai.functionresponse.md + - title: FunctionResponsePart + path: /docs/reference/js/ai.functionresponsepart.md + - title: GenerateContentCandidate + path: /docs/reference/js/ai.generatecontentcandidate.md + - title: GenerateContentRequest + path: /docs/reference/js/ai.generatecontentrequest.md + - title: GenerateContentResponse + path: /docs/reference/js/ai.generatecontentresponse.md + - title: GenerateContentResult + path: /docs/reference/js/ai.generatecontentresult.md + - title: GenerateContentStreamResult + path: /docs/reference/js/ai.generatecontentstreamresult.md + - title: GenerationConfig + path: /docs/reference/js/ai.generationconfig.md + - title: GenerativeContentBlob + path: /docs/reference/js/ai.generativecontentblob.md + - title: GenerativeModel + path: /docs/reference/js/ai.generativemodel.md + - title: GoogleAIBackend + path: /docs/reference/js/ai.googleaibackend.md + - title: GroundingAttribution + path: /docs/reference/js/ai.groundingattribution.md + - title: GroundingMetadata + path: /docs/reference/js/ai.groundingmetadata.md + - title: ImagenGCSImage + path: /docs/reference/js/ai.imagengcsimage.md + - title: ImagenGenerationConfig + path: /docs/reference/js/ai.imagengenerationconfig.md + - title: ImagenGenerationResponse + path: /docs/reference/js/ai.imagengenerationresponse.md + - title: ImagenImageFormat + path: /docs/reference/js/ai.imagenimageformat.md + - title: ImagenInlineImage + path: /docs/reference/js/ai.imageninlineimage.md + - title: ImagenModel + path: /docs/reference/js/ai.imagenmodel.md + - title: ImagenModelParams + path: /docs/reference/js/ai.imagenmodelparams.md + - title: ImagenSafetySettings + path: /docs/reference/js/ai.imagensafetysettings.md + - title: InlineDataPart + path: /docs/reference/js/ai.inlinedatapart.md + - title: IntegerSchema + path: /docs/reference/js/ai.integerschema.md + - title: ModalityTokenCount + path: /docs/reference/js/ai.modalitytokencount.md + - title: ModelParams + path: /docs/reference/js/ai.modelparams.md + - title: NumberSchema + path: /docs/reference/js/ai.numberschema.md + - title: ObjectSchema + path: /docs/reference/js/ai.objectschema.md + - title: ObjectSchemaInterface + path: /docs/reference/js/ai.objectschemainterface.md + - title: PromptFeedback + path: /docs/reference/js/ai.promptfeedback.md + - title: RequestOptions + path: /docs/reference/js/ai.requestoptions.md + - title: RetrievedContextAttribution + path: /docs/reference/js/ai.retrievedcontextattribution.md + - title: SafetyRating + path: /docs/reference/js/ai.safetyrating.md + - title: SafetySetting + path: /docs/reference/js/ai.safetysetting.md + - title: Schema + path: /docs/reference/js/ai.schema.md + - title: SchemaInterface + path: /docs/reference/js/ai.schemainterface.md + - title: SchemaParams + path: /docs/reference/js/ai.schemaparams.md + - title: SchemaRequest + path: /docs/reference/js/ai.schemarequest.md + - title: SchemaShared + path: /docs/reference/js/ai.schemashared.md + - title: Segment + path: /docs/reference/js/ai.segment.md + - title: StartChatParams + path: /docs/reference/js/ai.startchatparams.md + - title: StringSchema + path: /docs/reference/js/ai.stringschema.md + - title: TextPart + path: /docs/reference/js/ai.textpart.md + - title: ToolConfig + path: /docs/reference/js/ai.toolconfig.md + - title: UsageMetadata + path: /docs/reference/js/ai.usagemetadata.md + - title: VertexAIBackend + path: /docs/reference/js/ai.vertexaibackend.md + - title: VertexAIOptions + path: /docs/reference/js/ai.vertexaioptions.md + - title: VideoMetadata + path: /docs/reference/js/ai.videometadata.md + - title: WebAttribution + path: /docs/reference/js/ai.webattribution.md - title: analytics path: /docs/reference/js/analytics.md section: @@ -469,152 +618,3 @@ toc: path: /docs/reference/js/storage.uploadtask.md - title: UploadTaskSnapshot path: /docs/reference/js/storage.uploadtasksnapshot.md -- title: vertexai - path: /docs/reference/js/vertexai.md - section: - - title: AI - path: /docs/reference/js/vertexai.ai.md - - title: AIError - path: /docs/reference/js/vertexai.aierror.md - - title: AIModel - path: /docs/reference/js/vertexai.aimodel.md - - title: AIOptions - path: /docs/reference/js/vertexai.aioptions.md - - title: ArraySchema - path: /docs/reference/js/vertexai.arrayschema.md - - title: Backend - path: /docs/reference/js/vertexai.backend.md - - title: BaseParams - path: /docs/reference/js/vertexai.baseparams.md - - title: BooleanSchema - path: /docs/reference/js/vertexai.booleanschema.md - - title: ChatSession - path: /docs/reference/js/vertexai.chatsession.md - - title: Citation - path: /docs/reference/js/vertexai.citation.md - - title: CitationMetadata - path: /docs/reference/js/vertexai.citationmetadata.md - - title: Content - path: /docs/reference/js/vertexai.content.md - - title: CountTokensRequest - path: /docs/reference/js/vertexai.counttokensrequest.md - - title: CountTokensResponse - path: /docs/reference/js/vertexai.counttokensresponse.md - - title: CustomErrorData - path: /docs/reference/js/vertexai.customerrordata.md - - title: Date_2 - path: /docs/reference/js/vertexai.date_2.md - - title: EnhancedGenerateContentResponse - path: /docs/reference/js/vertexai.enhancedgeneratecontentresponse.md - - title: ErrorDetails - path: /docs/reference/js/vertexai.errordetails.md - - title: FileData - path: /docs/reference/js/vertexai.filedata.md - - title: FileDataPart - path: /docs/reference/js/vertexai.filedatapart.md - - title: FunctionCall - path: /docs/reference/js/vertexai.functioncall.md - - title: FunctionCallingConfig - path: /docs/reference/js/vertexai.functioncallingconfig.md - - title: FunctionCallPart - path: /docs/reference/js/vertexai.functioncallpart.md - - title: FunctionDeclaration - path: /docs/reference/js/vertexai.functiondeclaration.md - - title: FunctionDeclarationsTool - path: /docs/reference/js/vertexai.functiondeclarationstool.md - - title: FunctionResponse - path: /docs/reference/js/vertexai.functionresponse.md - - title: FunctionResponsePart - path: /docs/reference/js/vertexai.functionresponsepart.md - - title: GenerateContentCandidate - path: /docs/reference/js/vertexai.generatecontentcandidate.md - - title: GenerateContentRequest - path: /docs/reference/js/vertexai.generatecontentrequest.md - - title: GenerateContentResponse - path: /docs/reference/js/vertexai.generatecontentresponse.md - - title: GenerateContentResult - path: /docs/reference/js/vertexai.generatecontentresult.md - - title: GenerateContentStreamResult - path: /docs/reference/js/vertexai.generatecontentstreamresult.md - - title: GenerationConfig - path: /docs/reference/js/vertexai.generationconfig.md - - title: GenerativeContentBlob - path: /docs/reference/js/vertexai.generativecontentblob.md - - title: GenerativeModel - path: /docs/reference/js/vertexai.generativemodel.md - - title: GoogleAIBackend - path: /docs/reference/js/vertexai.googleaibackend.md - - title: GroundingAttribution - 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 - path: /docs/reference/js/vertexai.integerschema.md - - title: ModalityTokenCount - path: /docs/reference/js/vertexai.modalitytokencount.md - - title: ModelParams - path: /docs/reference/js/vertexai.modelparams.md - - title: NumberSchema - path: /docs/reference/js/vertexai.numberschema.md - - title: ObjectSchema - path: /docs/reference/js/vertexai.objectschema.md - - title: ObjectSchemaInterface - path: /docs/reference/js/vertexai.objectschemainterface.md - - title: PromptFeedback - path: /docs/reference/js/vertexai.promptfeedback.md - - title: RequestOptions - path: /docs/reference/js/vertexai.requestoptions.md - - title: RetrievedContextAttribution - path: /docs/reference/js/vertexai.retrievedcontextattribution.md - - title: SafetyRating - path: /docs/reference/js/vertexai.safetyrating.md - - title: SafetySetting - path: /docs/reference/js/vertexai.safetysetting.md - - title: Schema - path: /docs/reference/js/vertexai.schema.md - - title: SchemaInterface - path: /docs/reference/js/vertexai.schemainterface.md - - title: SchemaParams - path: /docs/reference/js/vertexai.schemaparams.md - - title: SchemaRequest - path: /docs/reference/js/vertexai.schemarequest.md - - title: SchemaShared - path: /docs/reference/js/vertexai.schemashared.md - - title: Segment - path: /docs/reference/js/vertexai.segment.md - - title: StartChatParams - path: /docs/reference/js/vertexai.startchatparams.md - - title: StringSchema - path: /docs/reference/js/vertexai.stringschema.md - - title: TextPart - path: /docs/reference/js/vertexai.textpart.md - - title: ToolConfig - path: /docs/reference/js/vertexai.toolconfig.md - - title: UsageMetadata - path: /docs/reference/js/vertexai.usagemetadata.md - - title: VertexAIBackend - path: /docs/reference/js/vertexai.vertexaibackend.md - - title: VertexAIOptions - path: /docs/reference/js/vertexai.vertexaioptions.md - - title: VideoMetadata - path: /docs/reference/js/vertexai.videometadata.md - - title: WebAttribution - path: /docs/reference/js/vertexai.webattribution.md diff --git a/docs-devsite/ai.ai.md b/docs-devsite/ai.ai.md new file mode 100644 index 00000000000..bc06122edf6 --- /dev/null +++ b/docs-devsite/ai.ai.md @@ -0,0 +1,64 @@ +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 %} + +# AI interface +An instance of the Firebase AI SDK. + +Do not create this instance directly. Instead, use [getAI()](./ai.md#getai_a94a413). + +Signature: + +```typescript +export interface AI +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [app](./ai.ai.md#aiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./ai.ai.md#ai_interface) instance is associated with. | +| [backend](./ai.ai.md#aibackend) | [Backend](./ai.backend.md#backend_class) | A [Backend](./ai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)) or the Vertex AI Gemini API (using [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). | +| [location](./ai.ai.md#ailocation) | string | The location configured for this AI service instance, relevant for Vertex AI backends. | + +## AI.app + +The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./ai.ai.md#ai_interface) instance is associated with. + +Signature: + +```typescript +app: FirebaseApp; +``` + +## AI.backend + +A [Backend](./ai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)) or the Vertex AI Gemini API (using [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). + +Signature: + +```typescript +backend: Backend; +``` + +## AI.location + +> Warning: This API is now obsolete. +> +> use `AI.backend.location` instead. +> + +The location configured for this AI service instance, relevant for Vertex AI backends. + +Signature: + +```typescript +location: string; +``` diff --git a/docs-devsite/vertexai.aierror.md b/docs-devsite/ai.aierror.md similarity index 65% rename from docs-devsite/vertexai.aierror.md rename to docs-devsite/ai.aierror.md index dac50815b6a..cf2d7e2b4c1 100644 --- a/docs-devsite/vertexai.aierror.md +++ b/docs-devsite/ai.aierror.md @@ -23,14 +23,14 @@ export declare class AIError extends FirebaseError | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(code, message, customErrorData)](./vertexai.aierror.md#aierrorconstructor) | | Constructs a new instance of the AIError class. | +| [(constructor)(code, message, customErrorData)](./ai.aierror.md#aierrorconstructor) | | Constructs a new instance of the AIError class. | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [code](./vertexai.aierror.md#aierrorcode) | | [AIErrorCode](./vertexai.md#aierrorcode) | | -| [customErrorData](./vertexai.aierror.md#aierrorcustomerrordata) | | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | | +| [code](./ai.aierror.md#aierrorcode) | | [AIErrorCode](./ai.md#aierrorcode) | | +| [customErrorData](./ai.aierror.md#aierrorcustomerrordata) | | [CustomErrorData](./ai.customerrordata.md#customerrordata_interface) \| undefined | | ## AIError.(constructor) @@ -46,9 +46,9 @@ constructor(code: AIErrorCode, message: string, customErrorData?: CustomErrorDat | Parameter | Type | Description | | --- | --- | --- | -| code | [AIErrorCode](./vertexai.md#aierrorcode) | The error code from [AIErrorCode](./vertexai.md#aierrorcode). | +| code | [AIErrorCode](./ai.md#aierrorcode) | The error code from [AIErrorCode](./ai.md#aierrorcode). | | message | string | A human-readable message describing the error. | -| customErrorData | [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) \| undefined | Optional error data. | +| customErrorData | [CustomErrorData](./ai.customerrordata.md#customerrordata_interface) \| undefined | Optional error data. | ## AIError.code diff --git a/docs-devsite/vertexai.aimodel.md b/docs-devsite/ai.aimodel.md similarity index 84% rename from docs-devsite/vertexai.aimodel.md rename to docs-devsite/ai.aimodel.md index bddc9c8b985..255d980b276 100644 --- a/docs-devsite/vertexai.aimodel.md +++ b/docs-devsite/ai.aimodel.md @@ -26,7 +26,7 @@ export declare abstract class AIModel | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [model](./vertexai.aimodel.md#aimodelmodel) | | string | The fully qualified model resource name to use for generating images (for example, publishers/google/models/imagen-3.0-generate-002). | +| [model](./ai.aimodel.md#aimodelmodel) | | string | The fully qualified model resource name to use for generating images (for example, publishers/google/models/imagen-3.0-generate-002). | ## AIModel.model diff --git a/docs-devsite/vertexai.aioptions.md b/docs-devsite/ai.aioptions.md similarity index 59% rename from docs-devsite/vertexai.aioptions.md rename to docs-devsite/ai.aioptions.md index 00ff0153527..a092046900b 100644 --- a/docs-devsite/vertexai.aioptions.md +++ b/docs-devsite/ai.aioptions.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # AIOptions interface -Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) and configuring its specific options (like location for Vertex AI). +Options for initializing the AI service using [getAI()](./ai.md#getai_a94a413). This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) and configuring its specific options (like location for Vertex AI). Signature: @@ -22,7 +22,7 @@ export interface AIOptions | Property | Type | Description | | --- | --- | --- | -| [backend](./vertexai.aioptions.md#aioptionsbackend) | [Backend](./vertexai.backend.md#backend_class) | The backend configuration to use for the AI service instance. | +| [backend](./ai.aioptions.md#aioptionsbackend) | [Backend](./ai.backend.md#backend_class) | The backend configuration to use for the AI service instance. | ## AIOptions.backend diff --git a/docs-devsite/vertexai.arrayschema.md b/docs-devsite/ai.arrayschema.md similarity index 69% rename from docs-devsite/vertexai.arrayschema.md rename to docs-devsite/ai.arrayschema.md index 8f228baf9e8..ef29bbd63f5 100644 --- a/docs-devsite/vertexai.arrayschema.md +++ b/docs-devsite/ai.arrayschema.md @@ -17,19 +17,19 @@ Schema class for "array" types. The `items` param should refer to the type of it ```typescript export declare class ArraySchema extends Schema ``` -Extends: [Schema](./vertexai.schema.md#schema_class) +Extends: [Schema](./ai.schema.md#schema_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(schemaParams, items)](./vertexai.arrayschema.md#arrayschemaconstructor) | | Constructs a new instance of the ArraySchema class | +| [(constructor)(schemaParams, items)](./ai.arrayschema.md#arrayschemaconstructor) | | Constructs a new instance of the ArraySchema class | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [items](./vertexai.arrayschema.md#arrayschemaitems) | | [TypedSchema](./vertexai.md#typedschema) | | +| [items](./ai.arrayschema.md#arrayschemaitems) | | [TypedSchema](./ai.md#typedschema) | | ## ArraySchema.(constructor) @@ -45,8 +45,8 @@ constructor(schemaParams: SchemaParams, items: TypedSchema); | Parameter | Type | Description | | --- | --- | --- | -| schemaParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | -| items | [TypedSchema](./vertexai.md#typedschema) | | +| schemaParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | +| items | [TypedSchema](./ai.md#typedschema) | | ## ArraySchema.items diff --git a/docs-devsite/vertexai.backend.md b/docs-devsite/ai.backend.md similarity index 66% rename from docs-devsite/vertexai.backend.md rename to docs-devsite/ai.backend.md index fe568087c77..307eeb97b2c 100644 --- a/docs-devsite/vertexai.backend.md +++ b/docs-devsite/ai.backend.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # Backend class -Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Vertex AI Gemini API. +Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class): For the Vertex AI Gemini API. Signature: @@ -22,13 +22,13 @@ export declare abstract class Backend | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(type)](./vertexai.backend.md#backendconstructor) | | Protected constructor for use by subclasses. | +| [(constructor)(type)](./ai.backend.md#backendconstructor) | | Protected constructor for use by subclasses. | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [backendType](./vertexai.backend.md#backendbackendtype) | | [BackendType](./vertexai.md#backendtype) | Specifies the backend type. | +| [backendType](./ai.backend.md#backendbackendtype) | | [BackendType](./ai.md#backendtype) | Specifies the backend type. | ## Backend.(constructor) @@ -44,7 +44,7 @@ protected constructor(type: BackendType); | Parameter | Type | Description | | --- | --- | --- | -| type | [BackendType](./vertexai.md#backendtype) | The specific backend type constant (e.g., BackendType.GOOGLE\_AI). | +| type | [BackendType](./ai.md#backendtype) | The specific backend type constant (e.g., BackendType.GOOGLE\_AI). | ## Backend.backendType diff --git a/docs-devsite/vertexai.baseparams.md b/docs-devsite/ai.baseparams.md similarity index 69% rename from docs-devsite/vertexai.baseparams.md rename to docs-devsite/ai.baseparams.md index 382ec825210..62484281f3b 100644 --- a/docs-devsite/vertexai.baseparams.md +++ b/docs-devsite/ai.baseparams.md @@ -22,8 +22,8 @@ export interface BaseParams | Property | Type | Description | | --- | --- | --- | -| [generationConfig](./vertexai.baseparams.md#baseparamsgenerationconfig) | [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | | -| [safetySettings](./vertexai.baseparams.md#baseparamssafetysettings) | [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface)\[\] | | +| [generationConfig](./ai.baseparams.md#baseparamsgenerationconfig) | [GenerationConfig](./ai.generationconfig.md#generationconfig_interface) | | +| [safetySettings](./ai.baseparams.md#baseparamssafetysettings) | [SafetySetting](./ai.safetysetting.md#safetysetting_interface)\[\] | | ## BaseParams.generationConfig diff --git a/docs-devsite/vertexai.booleanschema.md b/docs-devsite/ai.booleanschema.md similarity index 71% rename from docs-devsite/vertexai.booleanschema.md rename to docs-devsite/ai.booleanschema.md index 89449f26142..5797d530286 100644 --- a/docs-devsite/vertexai.booleanschema.md +++ b/docs-devsite/ai.booleanschema.md @@ -17,13 +17,13 @@ Schema class for "boolean" types. ```typescript export declare class BooleanSchema extends Schema ``` -Extends: [Schema](./vertexai.schema.md#schema_class) +Extends: [Schema](./ai.schema.md#schema_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(schemaParams)](./vertexai.booleanschema.md#booleanschemaconstructor) | | Constructs a new instance of the BooleanSchema class | +| [(constructor)(schemaParams)](./ai.booleanschema.md#booleanschemaconstructor) | | Constructs a new instance of the BooleanSchema class | ## BooleanSchema.(constructor) @@ -39,5 +39,5 @@ constructor(schemaParams?: SchemaParams); | Parameter | Type | Description | | --- | --- | --- | -| schemaParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | +| schemaParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | diff --git a/docs-devsite/vertexai.chatsession.md b/docs-devsite/ai.chatsession.md similarity index 52% rename from docs-devsite/vertexai.chatsession.md rename to docs-devsite/ai.chatsession.md index ed359f7e08c..1d6e403b6a8 100644 --- a/docs-devsite/vertexai.chatsession.md +++ b/docs-devsite/ai.chatsession.md @@ -22,23 +22,23 @@ export declare class ChatSession | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(apiSettings, model, params, requestOptions)](./vertexai.chatsession.md#chatsessionconstructor) | | Constructs a new instance of the ChatSession class | +| [(constructor)(apiSettings, model, params, requestOptions)](./ai.chatsession.md#chatsessionconstructor) | | Constructs a new instance of the ChatSession class | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [model](./vertexai.chatsession.md#chatsessionmodel) | | string | | -| [params](./vertexai.chatsession.md#chatsessionparams) | | [StartChatParams](./vertexai.startchatparams.md#startchatparams_interface) \| undefined | | -| [requestOptions](./vertexai.chatsession.md#chatsessionrequestoptions) | | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) \| undefined | | +| [model](./ai.chatsession.md#chatsessionmodel) | | string | | +| [params](./ai.chatsession.md#chatsessionparams) | | [StartChatParams](./ai.startchatparams.md#startchatparams_interface) \| undefined | | +| [requestOptions](./ai.chatsession.md#chatsessionrequestoptions) | | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \| undefined | | ## Methods | Method | Modifiers | Description | | --- | --- | --- | -| [getHistory()](./vertexai.chatsession.md#chatsessiongethistory) | | Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history. | -| [sendMessage(request)](./vertexai.chatsession.md#chatsessionsendmessage) | | Sends a chat message and receives a non-streaming [GenerateContentResult](./vertexai.generatecontentresult.md#generatecontentresult_interface) | -| [sendMessageStream(request)](./vertexai.chatsession.md#chatsessionsendmessagestream) | | Sends a chat message and receives the response as a [GenerateContentStreamResult](./vertexai.generatecontentstreamresult.md#generatecontentstreamresult_interface) containing an iterable stream and a response promise. | +| [getHistory()](./ai.chatsession.md#chatsessiongethistory) | | Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history. | +| [sendMessage(request)](./ai.chatsession.md#chatsessionsendmessage) | | Sends a chat message and receives a non-streaming [GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface) | +| [sendMessageStream(request)](./ai.chatsession.md#chatsessionsendmessagestream) | | Sends a chat message and receives the response as a [GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface) containing an iterable stream and a response promise. | ## ChatSession.(constructor) @@ -56,8 +56,8 @@ constructor(apiSettings: ApiSettings, model: string, params?: StartChatParams | | --- | --- | --- | | apiSettings | ApiSettings | | | model | string | | -| params | [StartChatParams](./vertexai.startchatparams.md#startchatparams_interface) \| undefined | | -| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) \| undefined | | +| params | [StartChatParams](./ai.startchatparams.md#startchatparams_interface) \| undefined | | +| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \| undefined | | ## ChatSession.model @@ -94,11 +94,11 @@ getHistory(): Promise; ``` Returns: -Promise<[Content](./vertexai.content.md#content_interface)\[\]> +Promise<[Content](./ai.content.md#content_interface)\[\]> ## ChatSession.sendMessage() -Sends a chat message and receives a non-streaming [GenerateContentResult](./vertexai.generatecontentresult.md#generatecontentresult_interface) +Sends a chat message and receives a non-streaming [GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface) Signature: @@ -110,15 +110,15 @@ sendMessage(request: string | Array): Promise> | | +| request | string \| Array<string \| [Part](./ai.md#part)> | | Returns: -Promise<[GenerateContentResult](./vertexai.generatecontentresult.md#generatecontentresult_interface)> +Promise<[GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface)> ## ChatSession.sendMessageStream() -Sends a chat message and receives the response as a [GenerateContentStreamResult](./vertexai.generatecontentstreamresult.md#generatecontentstreamresult_interface) containing an iterable stream and a response promise. +Sends a chat message and receives the response as a [GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface) containing an iterable stream and a response promise. Signature: @@ -130,9 +130,9 @@ sendMessageStream(request: string | Array): Promise> | | +| request | string \| Array<string \| [Part](./ai.md#part)> | | Returns: -Promise<[GenerateContentStreamResult](./vertexai.generatecontentstreamresult.md#generatecontentstreamresult_interface)> +Promise<[GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface)> diff --git a/docs-devsite/vertexai.citation.md b/docs-devsite/ai.citation.md similarity index 55% rename from docs-devsite/vertexai.citation.md rename to docs-devsite/ai.citation.md index c694f6c2a9c..3ed9dddc70d 100644 --- a/docs-devsite/vertexai.citation.md +++ b/docs-devsite/ai.citation.md @@ -22,12 +22,12 @@ export interface Citation | Property | Type | Description | | --- | --- | --- | -| [endIndex](./vertexai.citation.md#citationendindex) | number | | -| [license](./vertexai.citation.md#citationlicense) | string | | -| [publicationDate](./vertexai.citation.md#citationpublicationdate) | Date | The publication date of the cited source, if available.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | -| [startIndex](./vertexai.citation.md#citationstartindex) | number | | -| [title](./vertexai.citation.md#citationtitle) | string | The title of the cited source, if available.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | -| [uri](./vertexai.citation.md#citationuri) | string | | +| [endIndex](./ai.citation.md#citationendindex) | number | | +| [license](./ai.citation.md#citationlicense) | string | | +| [publicationDate](./ai.citation.md#citationpublicationdate) | Date | The publication date of the cited source, if available.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). | +| [startIndex](./ai.citation.md#citationstartindex) | number | | +| [title](./ai.citation.md#citationtitle) | string | The title of the cited source, if available.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). | +| [uri](./ai.citation.md#citationuri) | string | | ## Citation.endIndex @@ -49,7 +49,7 @@ license?: string; The publication date of the cited source, if available. -This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). +This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). Signature: @@ -69,7 +69,7 @@ startIndex?: number; The title of the cited source, if available. -This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). +This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.citationmetadata.md b/docs-devsite/ai.citationmetadata.md similarity index 73% rename from docs-devsite/vertexai.citationmetadata.md rename to docs-devsite/ai.citationmetadata.md index c317160e64f..a87654de38f 100644 --- a/docs-devsite/vertexai.citationmetadata.md +++ b/docs-devsite/ai.citationmetadata.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # CitationMetadata interface -Citation metadata that may be found on a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface). +Citation metadata that may be found on a [GenerateContentCandidate](./ai.generatecontentcandidate.md#generatecontentcandidate_interface). Signature: @@ -22,7 +22,7 @@ export interface CitationMetadata | Property | Type | Description | | --- | --- | --- | -| [citations](./vertexai.citationmetadata.md#citationmetadatacitations) | [Citation](./vertexai.citation.md#citation_interface)\[\] | | +| [citations](./ai.citationmetadata.md#citationmetadatacitations) | [Citation](./ai.citation.md#citation_interface)\[\] | | ## CitationMetadata.citations diff --git a/docs-devsite/vertexai.content.md b/docs-devsite/ai.content.md similarity index 79% rename from docs-devsite/vertexai.content.md rename to docs-devsite/ai.content.md index 7a4634a62bc..299a0947924 100644 --- a/docs-devsite/vertexai.content.md +++ b/docs-devsite/ai.content.md @@ -22,8 +22,8 @@ export interface Content | Property | Type | Description | | --- | --- | --- | -| [parts](./vertexai.content.md#contentparts) | [Part](./vertexai.md#part)\[\] | | -| [role](./vertexai.content.md#contentrole) | [Role](./vertexai.md#role) | | +| [parts](./ai.content.md#contentparts) | [Part](./ai.md#part)\[\] | | +| [role](./ai.content.md#contentrole) | [Role](./ai.md#role) | | ## Content.parts diff --git a/docs-devsite/vertexai.counttokensrequest.md b/docs-devsite/ai.counttokensrequest.md similarity index 52% rename from docs-devsite/vertexai.counttokensrequest.md rename to docs-devsite/ai.counttokensrequest.md index 740ae5feed4..ddcb020378b 100644 --- a/docs-devsite/vertexai.counttokensrequest.md +++ b/docs-devsite/ai.counttokensrequest.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # CountTokensRequest interface -Params for calling [GenerativeModel.countTokens()](./vertexai.generativemodel.md#generativemodelcounttokens) +Params for calling [GenerativeModel.countTokens()](./ai.generativemodel.md#generativemodelcounttokens) Signature: @@ -22,10 +22,10 @@ export interface CountTokensRequest | Property | Type | Description | | --- | --- | --- | -| [contents](./vertexai.counttokensrequest.md#counttokensrequestcontents) | [Content](./vertexai.content.md#content_interface)\[\] | | -| [generationConfig](./vertexai.counttokensrequest.md#counttokensrequestgenerationconfig) | [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | Configuration options that control how the model generates a response. | -| [systemInstruction](./vertexai.counttokensrequest.md#counttokensrequestsysteminstruction) | string \| [Part](./vertexai.md#part) \| [Content](./vertexai.content.md#content_interface) | Instructions that direct the model to behave a certain way. | -| [tools](./vertexai.counttokensrequest.md#counttokensrequesttools) | [Tool](./vertexai.md#tool)\[\] | [Tool](./vertexai.md#tool) configuration. | +| [contents](./ai.counttokensrequest.md#counttokensrequestcontents) | [Content](./ai.content.md#content_interface)\[\] | | +| [generationConfig](./ai.counttokensrequest.md#counttokensrequestgenerationconfig) | [GenerationConfig](./ai.generationconfig.md#generationconfig_interface) | Configuration options that control how the model generates a response. | +| [systemInstruction](./ai.counttokensrequest.md#counttokensrequestsysteminstruction) | string \| [Part](./ai.md#part) \| [Content](./ai.content.md#content_interface) | Instructions that direct the model to behave a certain way. | +| [tools](./ai.counttokensrequest.md#counttokensrequesttools) | [Tool](./ai.md#tool)\[\] | [Tool](./ai.md#tool) configuration. | ## CountTokensRequest.contents @@ -57,7 +57,7 @@ systemInstruction?: string | Part | Content; ## CountTokensRequest.tools -[Tool](./vertexai.md#tool) configuration. +[Tool](./ai.md#tool) configuration. Signature: diff --git a/docs-devsite/ai.counttokensresponse.md b/docs-devsite/ai.counttokensresponse.md new file mode 100644 index 00000000000..71e64d885d8 --- /dev/null +++ b/docs-devsite/ai.counttokensresponse.md @@ -0,0 +1,59 @@ +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 %} + +# CountTokensResponse interface +Response from calling [GenerativeModel.countTokens()](./ai.generativemodel.md#generativemodelcounttokens). + +Signature: + +```typescript +export interface CountTokensResponse +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [promptTokensDetails](./ai.counttokensresponse.md#counttokensresponseprompttokensdetails) | [ModalityTokenCount](./ai.modalitytokencount.md#modalitytokencount_interface)\[\] | The breakdown, by modality, of how many tokens are consumed by the prompt. | +| [totalBillableCharacters](./ai.counttokensresponse.md#counttokensresponsetotalbillablecharacters) | number | The total number of billable characters counted across all instances from the request.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | +| [totalTokens](./ai.counttokensresponse.md#counttokensresponsetotaltokens) | number | The total number of tokens counted across all instances from the request. | + +## CountTokensResponse.promptTokensDetails + +The breakdown, by modality, of how many tokens are consumed by the prompt. + +Signature: + +```typescript +promptTokensDetails?: ModalityTokenCount[]; +``` + +## CountTokensResponse.totalBillableCharacters + +The total number of billable characters counted across all instances from the request. + +This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. + +Signature: + +```typescript +totalBillableCharacters?: number; +``` + +## CountTokensResponse.totalTokens + +The total number of tokens counted across all instances from the request. + +Signature: + +```typescript +totalTokens: number; +``` diff --git a/docs-devsite/vertexai.customerrordata.md b/docs-devsite/ai.customerrordata.md similarity index 55% rename from docs-devsite/vertexai.customerrordata.md rename to docs-devsite/ai.customerrordata.md index 100f4a85fd9..149ad876191 100644 --- a/docs-devsite/vertexai.customerrordata.md +++ b/docs-devsite/ai.customerrordata.md @@ -22,10 +22,10 @@ export interface CustomErrorData | Property | Type | Description | | --- | --- | --- | -| [errorDetails](./vertexai.customerrordata.md#customerrordataerrordetails) | [ErrorDetails](./vertexai.errordetails.md#errordetails_interface)\[\] | Optional additional details about the error. | -| [response](./vertexai.customerrordata.md#customerrordataresponse) | [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface) | Response from a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) | -| [status](./vertexai.customerrordata.md#customerrordatastatus) | number | HTTP status code of the error response. | -| [statusText](./vertexai.customerrordata.md#customerrordatastatustext) | string | HTTP status text of the error response. | +| [errorDetails](./ai.customerrordata.md#customerrordataerrordetails) | [ErrorDetails](./ai.errordetails.md#errordetails_interface)\[\] | Optional additional details about the error. | +| [response](./ai.customerrordata.md#customerrordataresponse) | [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface) | Response from a [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | +| [status](./ai.customerrordata.md#customerrordatastatus) | number | HTTP status code of the error response. | +| [statusText](./ai.customerrordata.md#customerrordatastatustext) | string | HTTP status text of the error response. | ## CustomErrorData.errorDetails @@ -39,7 +39,7 @@ errorDetails?: ErrorDetails[]; ## CustomErrorData.response -Response from a [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) +Response from a [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) Signature: diff --git a/docs-devsite/vertexai.date_2.md b/docs-devsite/ai.date_2.md similarity index 80% rename from docs-devsite/vertexai.date_2.md rename to docs-devsite/ai.date_2.md index cf073bb86fe..10b3cfc41e9 100644 --- a/docs-devsite/vertexai.date_2.md +++ b/docs-devsite/ai.date_2.md @@ -22,9 +22,9 @@ export interface Date | Property | Type | Description | | --- | --- | --- | -| [day](./vertexai.date_2.md#date_2day) | number | | -| [month](./vertexai.date_2.md#date_2month) | number | | -| [year](./vertexai.date_2.md#date_2year) | number | | +| [day](./ai.date_2.md#date_2day) | number | | +| [month](./ai.date_2.md#date_2month) | number | | +| [year](./ai.date_2.md#date_2year) | number | | ## Date\_2.day diff --git a/docs-devsite/ai.enhancedgeneratecontentresponse.md b/docs-devsite/ai.enhancedgeneratecontentresponse.md new file mode 100644 index 00000000000..330dc10f322 --- /dev/null +++ b/docs-devsite/ai.enhancedgeneratecontentresponse.md @@ -0,0 +1,56 @@ +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 %} + +# EnhancedGenerateContentResponse interface +Response object wrapped with helper methods. + +Signature: + +```typescript +export interface EnhancedGenerateContentResponse extends GenerateContentResponse +``` +Extends: [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface) + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [functionCalls](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponsefunctioncalls) | () => [FunctionCall](./ai.functioncall.md#functioncall_interface)\[\] \| undefined | | +| [inlineDataParts](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponseinlinedataparts) | () => [InlineDataPart](./ai.inlinedatapart.md#inlinedatapart_interface)\[\] \| undefined | Aggregates and returns all [InlineDataPart](./ai.inlinedatapart.md#inlinedatapart_interface)s from the [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)'s first candidate. | +| [text](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponsetext) | () => string | Returns the text string from the response, if available. Throws if the prompt or candidate was blocked. | + +## EnhancedGenerateContentResponse.functionCalls + +Signature: + +```typescript +functionCalls: () => FunctionCall[] | undefined; +``` + +## EnhancedGenerateContentResponse.inlineDataParts + +Aggregates and returns all [InlineDataPart](./ai.inlinedatapart.md#inlinedatapart_interface)s from the [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)'s first candidate. + +Signature: + +```typescript +inlineDataParts: () => InlineDataPart[] | undefined; +``` + +## EnhancedGenerateContentResponse.text + +Returns the text string from the response, if available. Throws if the prompt or candidate was blocked. + +Signature: + +```typescript +text: () => string; +``` diff --git a/docs-devsite/vertexai.errordetails.md b/docs-devsite/ai.errordetails.md similarity index 70% rename from docs-devsite/vertexai.errordetails.md rename to docs-devsite/ai.errordetails.md index 68959343439..efa49c23021 100644 --- a/docs-devsite/vertexai.errordetails.md +++ b/docs-devsite/ai.errordetails.md @@ -22,10 +22,10 @@ export interface ErrorDetails | Property | Type | Description | | --- | --- | --- | -| ["@type"](./vertexai.errordetails.md#errordetails"@type") | string | | -| [domain](./vertexai.errordetails.md#errordetailsdomain) | string | The domain where the error occurred. | -| [metadata](./vertexai.errordetails.md#errordetailsmetadata) | Record<string, unknown> | Additional metadata about the error. | -| [reason](./vertexai.errordetails.md#errordetailsreason) | string | The reason for the error. | +| ["@type"](./ai.errordetails.md#errordetails"@type") | string | | +| [domain](./ai.errordetails.md#errordetailsdomain) | string | The domain where the error occurred. | +| [metadata](./ai.errordetails.md#errordetailsmetadata) | Record<string, unknown> | Additional metadata about the error. | +| [reason](./ai.errordetails.md#errordetailsreason) | string | The reason for the error. | ## ErrorDetails."@type" diff --git a/docs-devsite/vertexai.filedata.md b/docs-devsite/ai.filedata.md similarity index 83% rename from docs-devsite/vertexai.filedata.md rename to docs-devsite/ai.filedata.md index 7e000174692..c88ca71a8bb 100644 --- a/docs-devsite/vertexai.filedata.md +++ b/docs-devsite/ai.filedata.md @@ -22,8 +22,8 @@ export interface FileData | Property | Type | Description | | --- | --- | --- | -| [fileUri](./vertexai.filedata.md#filedatafileuri) | string | | -| [mimeType](./vertexai.filedata.md#filedatamimetype) | string | | +| [fileUri](./ai.filedata.md#filedatafileuri) | string | | +| [mimeType](./ai.filedata.md#filedatamimetype) | string | | ## FileData.fileUri diff --git a/docs-devsite/vertexai.filedatapart.md b/docs-devsite/ai.filedatapart.md similarity index 62% rename from docs-devsite/vertexai.filedatapart.md rename to docs-devsite/ai.filedatapart.md index 76162227526..65cb9dc00ef 100644 --- a/docs-devsite/vertexai.filedatapart.md +++ b/docs-devsite/ai.filedatapart.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # FileDataPart interface -Content part interface if the part represents [FileData](./vertexai.filedata.md#filedata_interface) +Content part interface if the part represents [FileData](./ai.filedata.md#filedata_interface) Signature: @@ -22,11 +22,11 @@ export interface FileDataPart | Property | Type | Description | | --- | --- | --- | -| [fileData](./vertexai.filedatapart.md#filedatapartfiledata) | [FileData](./vertexai.filedata.md#filedata_interface) | | -| [functionCall](./vertexai.filedatapart.md#filedatapartfunctioncall) | never | | -| [functionResponse](./vertexai.filedatapart.md#filedatapartfunctionresponse) | never | | -| [inlineData](./vertexai.filedatapart.md#filedatapartinlinedata) | never | | -| [text](./vertexai.filedatapart.md#filedataparttext) | never | | +| [fileData](./ai.filedatapart.md#filedatapartfiledata) | [FileData](./ai.filedata.md#filedata_interface) | | +| [functionCall](./ai.filedatapart.md#filedatapartfunctioncall) | never | | +| [functionResponse](./ai.filedatapart.md#filedatapartfunctionresponse) | never | | +| [inlineData](./ai.filedatapart.md#filedatapartinlinedata) | never | | +| [text](./ai.filedatapart.md#filedataparttext) | never | | ## FileDataPart.fileData diff --git a/docs-devsite/vertexai.functioncall.md b/docs-devsite/ai.functioncall.md similarity index 59% rename from docs-devsite/vertexai.functioncall.md rename to docs-devsite/ai.functioncall.md index 299fb7130f4..1c789784fe1 100644 --- a/docs-devsite/vertexai.functioncall.md +++ b/docs-devsite/ai.functioncall.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # FunctionCall interface -A predicted [FunctionCall](./vertexai.functioncall.md#functioncall_interface) returned from the model that contains a string representing the [FunctionDeclaration.name](./vertexai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing the parameters and their values. +A predicted [FunctionCall](./ai.functioncall.md#functioncall_interface) returned from the model that contains a string representing the [FunctionDeclaration.name](./ai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing the parameters and their values. Signature: @@ -22,8 +22,8 @@ export interface FunctionCall | Property | Type | Description | | --- | --- | --- | -| [args](./vertexai.functioncall.md#functioncallargs) | object | | -| [name](./vertexai.functioncall.md#functioncallname) | string | | +| [args](./ai.functioncall.md#functioncallargs) | object | | +| [name](./ai.functioncall.md#functioncallname) | string | | ## FunctionCall.args diff --git a/docs-devsite/vertexai.functioncallingconfig.md b/docs-devsite/ai.functioncallingconfig.md similarity index 73% rename from docs-devsite/vertexai.functioncallingconfig.md rename to docs-devsite/ai.functioncallingconfig.md index 3724fec5bf7..99531b4cb1f 100644 --- a/docs-devsite/vertexai.functioncallingconfig.md +++ b/docs-devsite/ai.functioncallingconfig.md @@ -21,8 +21,8 @@ export interface FunctionCallingConfig | Property | Type | Description | | --- | --- | --- | -| [allowedFunctionNames](./vertexai.functioncallingconfig.md#functioncallingconfigallowedfunctionnames) | string\[\] | | -| [mode](./vertexai.functioncallingconfig.md#functioncallingconfigmode) | [FunctionCallingMode](./vertexai.md#functioncallingmode) | | +| [allowedFunctionNames](./ai.functioncallingconfig.md#functioncallingconfigallowedfunctionnames) | string\[\] | | +| [mode](./ai.functioncallingconfig.md#functioncallingconfigmode) | [FunctionCallingMode](./ai.md#functioncallingmode) | | ## FunctionCallingConfig.allowedFunctionNames diff --git a/docs-devsite/vertexai.functioncallpart.md b/docs-devsite/ai.functioncallpart.md similarity index 66% rename from docs-devsite/vertexai.functioncallpart.md rename to docs-devsite/ai.functioncallpart.md index 58fe0f5fa97..b16e58f80a6 100644 --- a/docs-devsite/vertexai.functioncallpart.md +++ b/docs-devsite/ai.functioncallpart.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # FunctionCallPart interface -Content part interface if the part represents a [FunctionCall](./vertexai.functioncall.md#functioncall_interface). +Content part interface if the part represents a [FunctionCall](./ai.functioncall.md#functioncall_interface). Signature: @@ -22,10 +22,10 @@ export interface FunctionCallPart | Property | Type | Description | | --- | --- | --- | -| [functionCall](./vertexai.functioncallpart.md#functioncallpartfunctioncall) | [FunctionCall](./vertexai.functioncall.md#functioncall_interface) | | -| [functionResponse](./vertexai.functioncallpart.md#functioncallpartfunctionresponse) | never | | -| [inlineData](./vertexai.functioncallpart.md#functioncallpartinlinedata) | never | | -| [text](./vertexai.functioncallpart.md#functioncallparttext) | never | | +| [functionCall](./ai.functioncallpart.md#functioncallpartfunctioncall) | [FunctionCall](./ai.functioncall.md#functioncall_interface) | | +| [functionResponse](./ai.functioncallpart.md#functioncallpartfunctionresponse) | never | | +| [inlineData](./ai.functioncallpart.md#functioncallpartinlinedata) | never | | +| [text](./ai.functioncallpart.md#functioncallparttext) | never | | ## FunctionCallPart.functionCall diff --git a/docs-devsite/vertexai.functiondeclaration.md b/docs-devsite/ai.functiondeclaration.md similarity index 65% rename from docs-devsite/vertexai.functiondeclaration.md rename to docs-devsite/ai.functiondeclaration.md index 211c1dd868d..2a87d67ed47 100644 --- a/docs-devsite/vertexai.functiondeclaration.md +++ b/docs-devsite/ai.functiondeclaration.md @@ -22,9 +22,9 @@ export declare interface FunctionDeclaration | Property | Type | Description | | --- | --- | --- | -| [description](./vertexai.functiondeclaration.md#functiondeclarationdescription) | string | Description and purpose of the function. Model uses it to decide how and whether to call the function. | -| [name](./vertexai.functiondeclaration.md#functiondeclarationname) | string | The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a max length of 64. | -| [parameters](./vertexai.functiondeclaration.md#functiondeclarationparameters) | [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. Parameter names are case-sensitive. For a function with no parameters, this can be left unset. | +| [description](./ai.functiondeclaration.md#functiondeclarationdescription) | string | Description and purpose of the function. Model uses it to decide how and whether to call the function. | +| [name](./ai.functiondeclaration.md#functiondeclarationname) | string | The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a max length of 64. | +| [parameters](./ai.functiondeclaration.md#functiondeclarationparameters) | [ObjectSchemaInterface](./ai.objectschemainterface.md#objectschemainterface_interface) | Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. Parameter names are case-sensitive. For a function with no parameters, this can be left unset. | ## FunctionDeclaration.description diff --git a/docs-devsite/ai.functiondeclarationstool.md b/docs-devsite/ai.functiondeclarationstool.md new file mode 100644 index 00000000000..bde785d730b --- /dev/null +++ b/docs-devsite/ai.functiondeclarationstool.md @@ -0,0 +1,35 @@ +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 %} + +# FunctionDeclarationsTool interface +A `FunctionDeclarationsTool` is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. + +Signature: + +```typescript +export declare interface FunctionDeclarationsTool +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [functionDeclarations](./ai.functiondeclarationstool.md#functiondeclarationstoolfunctiondeclarations) | [FunctionDeclaration](./ai.functiondeclaration.md#functiondeclaration_interface)\[\] | Optional. One or more function declarations to be passed to the model along with the current user query. Model may decide to call a subset of these functions by populating [FunctionCall](./ai.functioncall.md#functioncall_interface) in the response. User should provide a [FunctionResponse](./ai.functionresponse.md#functionresponse_interface) for each function call in the next turn. Based on the function responses, the model will generate the final response back to the user. Maximum 64 function declarations can be provided. | + +## FunctionDeclarationsTool.functionDeclarations + +Optional. One or more function declarations to be passed to the model along with the current user query. Model may decide to call a subset of these functions by populating [FunctionCall](./ai.functioncall.md#functioncall_interface) in the response. User should provide a [FunctionResponse](./ai.functionresponse.md#functionresponse_interface) for each function call in the next turn. Based on the function responses, the model will generate the final response back to the user. Maximum 64 function declarations can be provided. + +Signature: + +```typescript +functionDeclarations?: FunctionDeclaration[]; +``` diff --git a/docs-devsite/vertexai.functionresponse.md b/docs-devsite/ai.functionresponse.md similarity index 51% rename from docs-devsite/vertexai.functionresponse.md rename to docs-devsite/ai.functionresponse.md index 072a08b3486..e0838cf515a 100644 --- a/docs-devsite/vertexai.functionresponse.md +++ b/docs-devsite/ai.functionresponse.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # FunctionResponse interface -The result output from a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) that contains a string representing the [FunctionDeclaration.name](./vertexai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) made based on model prediction. +The result output from a [FunctionCall](./ai.functioncall.md#functioncall_interface) that contains a string representing the [FunctionDeclaration.name](./ai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall](./ai.functioncall.md#functioncall_interface) made based on model prediction. Signature: @@ -22,8 +22,8 @@ export interface FunctionResponse | Property | Type | Description | | --- | --- | --- | -| [name](./vertexai.functionresponse.md#functionresponsename) | string | | -| [response](./vertexai.functionresponse.md#functionresponseresponse) | object | | +| [name](./ai.functionresponse.md#functionresponsename) | string | | +| [response](./ai.functionresponse.md#functionresponseresponse) | object | | ## FunctionResponse.name diff --git a/docs-devsite/vertexai.functionresponsepart.md b/docs-devsite/ai.functionresponsepart.md similarity index 64% rename from docs-devsite/vertexai.functionresponsepart.md rename to docs-devsite/ai.functionresponsepart.md index ffbf2ad0517..9c80258f43f 100644 --- a/docs-devsite/vertexai.functionresponsepart.md +++ b/docs-devsite/ai.functionresponsepart.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # FunctionResponsePart interface -Content part interface if the part represents [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface). +Content part interface if the part represents [FunctionResponse](./ai.functionresponse.md#functionresponse_interface). Signature: @@ -22,10 +22,10 @@ export interface FunctionResponsePart | Property | Type | Description | | --- | --- | --- | -| [functionCall](./vertexai.functionresponsepart.md#functionresponsepartfunctioncall) | never | | -| [functionResponse](./vertexai.functionresponsepart.md#functionresponsepartfunctionresponse) | [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface) | | -| [inlineData](./vertexai.functionresponsepart.md#functionresponsepartinlinedata) | never | | -| [text](./vertexai.functionresponsepart.md#functionresponseparttext) | never | | +| [functionCall](./ai.functionresponsepart.md#functionresponsepartfunctioncall) | never | | +| [functionResponse](./ai.functionresponsepart.md#functionresponsepartfunctionresponse) | [FunctionResponse](./ai.functionresponse.md#functionresponse_interface) | | +| [inlineData](./ai.functionresponsepart.md#functionresponsepartinlinedata) | never | | +| [text](./ai.functionresponsepart.md#functionresponseparttext) | never | | ## FunctionResponsePart.functionCall diff --git a/docs-devsite/vertexai.generatecontentcandidate.md b/docs-devsite/ai.generatecontentcandidate.md similarity index 51% rename from docs-devsite/vertexai.generatecontentcandidate.md rename to docs-devsite/ai.generatecontentcandidate.md index e5fd9eacbbe..ca0383549a7 100644 --- a/docs-devsite/vertexai.generatecontentcandidate.md +++ b/docs-devsite/ai.generatecontentcandidate.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # GenerateContentCandidate interface -A candidate returned as part of a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). +A candidate returned as part of a [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface). Signature: @@ -22,13 +22,13 @@ export interface GenerateContentCandidate | Property | Type | Description | | --- | --- | --- | -| [citationMetadata](./vertexai.generatecontentcandidate.md#generatecontentcandidatecitationmetadata) | [CitationMetadata](./vertexai.citationmetadata.md#citationmetadata_interface) | | -| [content](./vertexai.generatecontentcandidate.md#generatecontentcandidatecontent) | [Content](./vertexai.content.md#content_interface) | | -| [finishMessage](./vertexai.generatecontentcandidate.md#generatecontentcandidatefinishmessage) | string | | -| [finishReason](./vertexai.generatecontentcandidate.md#generatecontentcandidatefinishreason) | [FinishReason](./vertexai.md#finishreason) | | -| [groundingMetadata](./vertexai.generatecontentcandidate.md#generatecontentcandidategroundingmetadata) | [GroundingMetadata](./vertexai.groundingmetadata.md#groundingmetadata_interface) | | -| [index](./vertexai.generatecontentcandidate.md#generatecontentcandidateindex) | number | | -| [safetyRatings](./vertexai.generatecontentcandidate.md#generatecontentcandidatesafetyratings) | [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface)\[\] | | +| [citationMetadata](./ai.generatecontentcandidate.md#generatecontentcandidatecitationmetadata) | [CitationMetadata](./ai.citationmetadata.md#citationmetadata_interface) | | +| [content](./ai.generatecontentcandidate.md#generatecontentcandidatecontent) | [Content](./ai.content.md#content_interface) | | +| [finishMessage](./ai.generatecontentcandidate.md#generatecontentcandidatefinishmessage) | string | | +| [finishReason](./ai.generatecontentcandidate.md#generatecontentcandidatefinishreason) | [FinishReason](./ai.md#finishreason) | | +| [groundingMetadata](./ai.generatecontentcandidate.md#generatecontentcandidategroundingmetadata) | [GroundingMetadata](./ai.groundingmetadata.md#groundingmetadata_interface) | | +| [index](./ai.generatecontentcandidate.md#generatecontentcandidateindex) | number | | +| [safetyRatings](./ai.generatecontentcandidate.md#generatecontentcandidatesafetyratings) | [SafetyRating](./ai.safetyrating.md#safetyrating_interface)\[\] | | ## GenerateContentCandidate.citationMetadata diff --git a/docs-devsite/vertexai.generatecontentrequest.md b/docs-devsite/ai.generatecontentrequest.md similarity index 53% rename from docs-devsite/vertexai.generatecontentrequest.md rename to docs-devsite/ai.generatecontentrequest.md index 31f1103a2e2..257a2d308fa 100644 --- a/docs-devsite/vertexai.generatecontentrequest.md +++ b/docs-devsite/ai.generatecontentrequest.md @@ -10,23 +10,23 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # GenerateContentRequest interface -Request sent through [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) +Request sent through [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) Signature: ```typescript export interface GenerateContentRequest extends BaseParams ``` -Extends: [BaseParams](./vertexai.baseparams.md#baseparams_interface) +Extends: [BaseParams](./ai.baseparams.md#baseparams_interface) ## Properties | Property | Type | Description | | --- | --- | --- | -| [contents](./vertexai.generatecontentrequest.md#generatecontentrequestcontents) | [Content](./vertexai.content.md#content_interface)\[\] | | -| [systemInstruction](./vertexai.generatecontentrequest.md#generatecontentrequestsysteminstruction) | string \| [Part](./vertexai.md#part) \| [Content](./vertexai.content.md#content_interface) | | -| [toolConfig](./vertexai.generatecontentrequest.md#generatecontentrequesttoolconfig) | [ToolConfig](./vertexai.toolconfig.md#toolconfig_interface) | | -| [tools](./vertexai.generatecontentrequest.md#generatecontentrequesttools) | [Tool](./vertexai.md#tool)\[\] | | +| [contents](./ai.generatecontentrequest.md#generatecontentrequestcontents) | [Content](./ai.content.md#content_interface)\[\] | | +| [systemInstruction](./ai.generatecontentrequest.md#generatecontentrequestsysteminstruction) | string \| [Part](./ai.md#part) \| [Content](./ai.content.md#content_interface) | | +| [toolConfig](./ai.generatecontentrequest.md#generatecontentrequesttoolconfig) | [ToolConfig](./ai.toolconfig.md#toolconfig_interface) | | +| [tools](./ai.generatecontentrequest.md#generatecontentrequesttools) | [Tool](./ai.md#tool)\[\] | | ## GenerateContentRequest.contents diff --git a/docs-devsite/ai.generatecontentresponse.md b/docs-devsite/ai.generatecontentresponse.md new file mode 100644 index 00000000000..7c2dc1dc86a --- /dev/null +++ b/docs-devsite/ai.generatecontentresponse.md @@ -0,0 +1,51 @@ +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 %} + +# GenerateContentResponse interface +Individual response from [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) and [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream). `generateContentStream()` will return one in each chunk until the stream is done. + +Signature: + +```typescript +export interface GenerateContentResponse +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [candidates](./ai.generatecontentresponse.md#generatecontentresponsecandidates) | [GenerateContentCandidate](./ai.generatecontentcandidate.md#generatecontentcandidate_interface)\[\] | | +| [promptFeedback](./ai.generatecontentresponse.md#generatecontentresponsepromptfeedback) | [PromptFeedback](./ai.promptfeedback.md#promptfeedback_interface) | | +| [usageMetadata](./ai.generatecontentresponse.md#generatecontentresponseusagemetadata) | [UsageMetadata](./ai.usagemetadata.md#usagemetadata_interface) | | + +## GenerateContentResponse.candidates + +Signature: + +```typescript +candidates?: GenerateContentCandidate[]; +``` + +## GenerateContentResponse.promptFeedback + +Signature: + +```typescript +promptFeedback?: PromptFeedback; +``` + +## GenerateContentResponse.usageMetadata + +Signature: + +```typescript +usageMetadata?: UsageMetadata; +``` diff --git a/docs-devsite/vertexai.generatecontentresult.md b/docs-devsite/ai.generatecontentresult.md similarity index 71% rename from docs-devsite/vertexai.generatecontentresult.md rename to docs-devsite/ai.generatecontentresult.md index 3e162f9ebb2..a59e75f8672 100644 --- a/docs-devsite/vertexai.generatecontentresult.md +++ b/docs-devsite/ai.generatecontentresult.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # GenerateContentResult interface -Result object returned from [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) call. +Result object returned from [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) call. Signature: @@ -22,7 +22,7 @@ export interface GenerateContentResult | Property | Type | Description | | --- | --- | --- | -| [response](./vertexai.generatecontentresult.md#generatecontentresultresponse) | [EnhancedGenerateContentResponse](./vertexai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface) | | +| [response](./ai.generatecontentresult.md#generatecontentresultresponse) | [EnhancedGenerateContentResponse](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface) | | ## GenerateContentResult.response diff --git a/docs-devsite/vertexai.generatecontentstreamresult.md b/docs-devsite/ai.generatecontentstreamresult.md similarity index 54% rename from docs-devsite/vertexai.generatecontentstreamresult.md rename to docs-devsite/ai.generatecontentstreamresult.md index 340abb1d0bd..fd3a06e933e 100644 --- a/docs-devsite/vertexai.generatecontentstreamresult.md +++ b/docs-devsite/ai.generatecontentstreamresult.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # GenerateContentStreamResult interface -Result object returned from [GenerativeModel.generateContentStream()](./vertexai.generativemodel.md#generativemodelgeneratecontentstream) call. Iterate over `stream` to get chunks as they come in and/or use the `response` promise to get the aggregated response when the stream is done. +Result object returned from [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream) call. Iterate over `stream` to get chunks as they come in and/or use the `response` promise to get the aggregated response when the stream is done. Signature: @@ -22,8 +22,8 @@ export interface GenerateContentStreamResult | Property | Type | Description | | --- | --- | --- | -| [response](./vertexai.generatecontentstreamresult.md#generatecontentstreamresultresponse) | Promise<[EnhancedGenerateContentResponse](./vertexai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface)> | | -| [stream](./vertexai.generatecontentstreamresult.md#generatecontentstreamresultstream) | AsyncGenerator<[EnhancedGenerateContentResponse](./vertexai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface)> | | +| [response](./ai.generatecontentstreamresult.md#generatecontentstreamresultresponse) | Promise<[EnhancedGenerateContentResponse](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface)> | | +| [stream](./ai.generatecontentstreamresult.md#generatecontentstreamresultstream) | AsyncGenerator<[EnhancedGenerateContentResponse](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface)> | | ## GenerateContentStreamResult.response diff --git a/docs-devsite/ai.generationconfig.md b/docs-devsite/ai.generationconfig.md new file mode 100644 index 00000000000..f9697a07454 --- /dev/null +++ b/docs-devsite/ai.generationconfig.md @@ -0,0 +1,134 @@ +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 %} + +# GenerationConfig interface +Config options for content-related requests + +Signature: + +```typescript +export interface GenerationConfig +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [candidateCount](./ai.generationconfig.md#generationconfigcandidatecount) | number | | +| [frequencyPenalty](./ai.generationconfig.md#generationconfigfrequencypenalty) | number | | +| [maxOutputTokens](./ai.generationconfig.md#generationconfigmaxoutputtokens) | number | | +| [presencePenalty](./ai.generationconfig.md#generationconfigpresencepenalty) | number | | +| [responseMimeType](./ai.generationconfig.md#generationconfigresponsemimetype) | string | Output response MIME type of the generated candidate text. Supported MIME types are text/plain (default, text output), application/json (JSON response in the candidates), and text/x.enum. | +| [responseModalities](./ai.generationconfig.md#generationconfigresponsemodalities) | [ResponseModality](./ai.md#responsemodality)\[\] | (Public Preview) Generation modalities to be returned in generation responses. | +| [responseSchema](./ai.generationconfig.md#generationconfigresponseschema) | [TypedSchema](./ai.md#typedschema) \| [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) | Output response schema of the generated candidate text. This value can be a class generated with a [Schema](./ai.schema.md#schema_class) static method like Schema.string() or Schema.object() or it can be a plain JS object matching the [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) interface.
Note: This only applies when the specified responseMIMEType supports a schema; currently this is limited to application/json and text/x.enum. | +| [stopSequences](./ai.generationconfig.md#generationconfigstopsequences) | string\[\] | | +| [temperature](./ai.generationconfig.md#generationconfigtemperature) | number | | +| [topK](./ai.generationconfig.md#generationconfigtopk) | number | | +| [topP](./ai.generationconfig.md#generationconfigtopp) | number | | + +## GenerationConfig.candidateCount + +Signature: + +```typescript +candidateCount?: number; +``` + +## GenerationConfig.frequencyPenalty + +Signature: + +```typescript +frequencyPenalty?: number; +``` + +## GenerationConfig.maxOutputTokens + +Signature: + +```typescript +maxOutputTokens?: number; +``` + +## GenerationConfig.presencePenalty + +Signature: + +```typescript +presencePenalty?: number; +``` + +## GenerationConfig.responseMimeType + +Output response MIME type of the generated candidate text. Supported MIME types are `text/plain` (default, text output), `application/json` (JSON response in the candidates), and `text/x.enum`. + +Signature: + +```typescript +responseMimeType?: string; +``` + +## GenerationConfig.responseModalities + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Generation modalities to be returned in generation responses. + +- Multimodal response generation is only supported by some Gemini models and versions; see [model versions](https://firebase.google.com/docs/vertex-ai/models). - Only image generation (`ResponseModality.IMAGE`) is supported. + +Signature: + +```typescript +responseModalities?: ResponseModality[]; +``` + +## GenerationConfig.responseSchema + +Output response schema of the generated candidate text. This value can be a class generated with a [Schema](./ai.schema.md#schema_class) static method like `Schema.string()` or `Schema.object()` or it can be a plain JS object matching the [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) interface.
Note: This only applies when the specified `responseMIMEType` supports a schema; currently this is limited to `application/json` and `text/x.enum`. + +Signature: + +```typescript +responseSchema?: TypedSchema | SchemaRequest; +``` + +## GenerationConfig.stopSequences + +Signature: + +```typescript +stopSequences?: string[]; +``` + +## GenerationConfig.temperature + +Signature: + +```typescript +temperature?: number; +``` + +## GenerationConfig.topK + +Signature: + +```typescript +topK?: number; +``` + +## GenerationConfig.topP + +Signature: + +```typescript +topP?: number; +``` diff --git a/docs-devsite/vertexai.generativecontentblob.md b/docs-devsite/ai.generativecontentblob.md similarity index 78% rename from docs-devsite/vertexai.generativecontentblob.md rename to docs-devsite/ai.generativecontentblob.md index dfcd098291f..74a582aae6d 100644 --- a/docs-devsite/vertexai.generativecontentblob.md +++ b/docs-devsite/ai.generativecontentblob.md @@ -22,8 +22,8 @@ export interface GenerativeContentBlob | Property | Type | Description | | --- | --- | --- | -| [data](./vertexai.generativecontentblob.md#generativecontentblobdata) | string | Image as a base64 string. | -| [mimeType](./vertexai.generativecontentblob.md#generativecontentblobmimetype) | string | | +| [data](./ai.generativecontentblob.md#generativecontentblobdata) | string | Image as a base64 string. | +| [mimeType](./ai.generativecontentblob.md#generativecontentblobmimetype) | string | | ## GenerativeContentBlob.data diff --git a/docs-devsite/ai.generativemodel.md b/docs-devsite/ai.generativemodel.md new file mode 100644 index 00000000000..d91cf80e881 --- /dev/null +++ b/docs-devsite/ai.generativemodel.md @@ -0,0 +1,193 @@ +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 %} + +# GenerativeModel class +Class for generative model APIs. + +Signature: + +```typescript +export declare class GenerativeModel extends AIModel +``` +Extends: [AIModel](./ai.aimodel.md#aimodel_class) + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(ai, modelParams, requestOptions)](./ai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the GenerativeModel class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [generationConfig](./ai.generativemodel.md#generativemodelgenerationconfig) | | [GenerationConfig](./ai.generationconfig.md#generationconfig_interface) | | +| [requestOptions](./ai.generativemodel.md#generativemodelrequestoptions) | | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | | +| [safetySettings](./ai.generativemodel.md#generativemodelsafetysettings) | | [SafetySetting](./ai.safetysetting.md#safetysetting_interface)\[\] | | +| [systemInstruction](./ai.generativemodel.md#generativemodelsysteminstruction) | | [Content](./ai.content.md#content_interface) | | +| [toolConfig](./ai.generativemodel.md#generativemodeltoolconfig) | | [ToolConfig](./ai.toolconfig.md#toolconfig_interface) | | +| [tools](./ai.generativemodel.md#generativemodeltools) | | [Tool](./ai.md#tool)\[\] | | + +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [countTokens(request)](./ai.generativemodel.md#generativemodelcounttokens) | | Counts the tokens in the provided request. | +| [generateContent(request)](./ai.generativemodel.md#generativemodelgeneratecontent) | | Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface). | +| [generateContentStream(request)](./ai.generativemodel.md#generativemodelgeneratecontentstream) | | Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. | +| [startChat(startChatParams)](./ai.generativemodel.md#generativemodelstartchat) | | Gets a new [ChatSession](./ai.chatsession.md#chatsession_class) instance which can be used for multi-turn chats. | + +## GenerativeModel.(constructor) + +Constructs a new instance of the `GenerativeModel` class + +Signature: + +```typescript +constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions); +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| ai | [AI](./ai.ai.md#ai_interface) | | +| modelParams | [ModelParams](./ai.modelparams.md#modelparams_interface) | | +| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | | + +## GenerativeModel.generationConfig + +Signature: + +```typescript +generationConfig: GenerationConfig; +``` + +## GenerativeModel.requestOptions + +Signature: + +```typescript +requestOptions?: RequestOptions; +``` + +## GenerativeModel.safetySettings + +Signature: + +```typescript +safetySettings: SafetySetting[]; +``` + +## GenerativeModel.systemInstruction + +Signature: + +```typescript +systemInstruction?: Content; +``` + +## GenerativeModel.toolConfig + +Signature: + +```typescript +toolConfig?: ToolConfig; +``` + +## GenerativeModel.tools + +Signature: + +```typescript +tools?: Tool[]; +``` + +## GenerativeModel.countTokens() + +Counts the tokens in the provided request. + +Signature: + +```typescript +countTokens(request: CountTokensRequest | string | Array): Promise; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| request | [CountTokensRequest](./ai.counttokensrequest.md#counttokensrequest_interface) \| string \| Array<string \| [Part](./ai.md#part)> | | + +Returns: + +Promise<[CountTokensResponse](./ai.counttokensresponse.md#counttokensresponse_interface)> + +## GenerativeModel.generateContent() + +Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface). + +Signature: + +```typescript +generateContent(request: GenerateContentRequest | string | Array): Promise; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| request | [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) \| string \| Array<string \| [Part](./ai.md#part)> | | + +Returns: + +Promise<[GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface)> + +## GenerativeModel.generateContentStream() + +Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. + +Signature: + +```typescript +generateContentStream(request: GenerateContentRequest | string | Array): Promise; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| request | [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) \| string \| Array<string \| [Part](./ai.md#part)> | | + +Returns: + +Promise<[GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface)> + +## GenerativeModel.startChat() + +Gets a new [ChatSession](./ai.chatsession.md#chatsession_class) instance which can be used for multi-turn chats. + +Signature: + +```typescript +startChat(startChatParams?: StartChatParams): ChatSession; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| startChatParams | [StartChatParams](./ai.startchatparams.md#startchatparams_interface) | | + +Returns: + +[ChatSession](./ai.chatsession.md#chatsession_class) + diff --git a/docs-devsite/vertexai.googleaibackend.md b/docs-devsite/ai.googleaibackend.md similarity index 64% rename from docs-devsite/vertexai.googleaibackend.md rename to docs-devsite/ai.googleaibackend.md index 79b115f78cd..c00b8cc5d91 100644 --- a/docs-devsite/vertexai.googleaibackend.md +++ b/docs-devsite/ai.googleaibackend.md @@ -12,20 +12,20 @@ https://github.com/firebase/firebase-js-sdk # GoogleAIBackend class Configuration class for the Gemini Developer API (using Google AI). -Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini Developer API as the backend. +Use this with [AIOptions](./ai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./ai.md#getai_a94a413) to specify the Gemini Developer API as the backend. Signature: ```typescript export declare class GoogleAIBackend extends Backend ``` -Extends: [Backend](./vertexai.backend.md#backend_class) +Extends: [Backend](./ai.backend.md#backend_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)()](./vertexai.googleaibackend.md#googleaibackendconstructor) | | Creates a configuration object for the Google AI backend. | +| [(constructor)()](./ai.googleaibackend.md#googleaibackendconstructor) | | Creates a configuration object for the Google AI backend. | ## GoogleAIBackend.(constructor) diff --git a/docs-devsite/vertexai.groundingattribution.md b/docs-devsite/ai.groundingattribution.md similarity index 61% rename from docs-devsite/vertexai.groundingattribution.md rename to docs-devsite/ai.groundingattribution.md index b3a3b6257c3..a0895550bf1 100644 --- a/docs-devsite/vertexai.groundingattribution.md +++ b/docs-devsite/ai.groundingattribution.md @@ -24,10 +24,10 @@ export interface GroundingAttribution | Property | Type | Description | | --- | --- | --- | -| [confidenceScore](./vertexai.groundingattribution.md#groundingattributionconfidencescore) | number | | -| [retrievedContext](./vertexai.groundingattribution.md#groundingattributionretrievedcontext) | [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | | -| [segment](./vertexai.groundingattribution.md#groundingattributionsegment) | [Segment](./vertexai.segment.md#segment_interface) | | -| [web](./vertexai.groundingattribution.md#groundingattributionweb) | [WebAttribution](./vertexai.webattribution.md#webattribution_interface) | | +| [confidenceScore](./ai.groundingattribution.md#groundingattributionconfidencescore) | number | | +| [retrievedContext](./ai.groundingattribution.md#groundingattributionretrievedcontext) | [RetrievedContextAttribution](./ai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | | +| [segment](./ai.groundingattribution.md#groundingattributionsegment) | [Segment](./ai.segment.md#segment_interface) | | +| [web](./ai.groundingattribution.md#groundingattributionweb) | [WebAttribution](./ai.webattribution.md#webattribution_interface) | | ## GroundingAttribution.confidenceScore diff --git a/docs-devsite/vertexai.groundingmetadata.md b/docs-devsite/ai.groundingmetadata.md similarity index 68% rename from docs-devsite/vertexai.groundingmetadata.md rename to docs-devsite/ai.groundingmetadata.md index 24686da39ba..90994d9c01c 100644 --- a/docs-devsite/vertexai.groundingmetadata.md +++ b/docs-devsite/ai.groundingmetadata.md @@ -22,9 +22,9 @@ export interface GroundingMetadata | Property | Type | Description | | --- | --- | --- | -| [groundingAttributions](./vertexai.groundingmetadata.md#groundingmetadatagroundingattributions) | [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface)\[\] | | -| [retrievalQueries](./vertexai.groundingmetadata.md#groundingmetadataretrievalqueries) | string\[\] | | -| [webSearchQueries](./vertexai.groundingmetadata.md#groundingmetadatawebsearchqueries) | string\[\] | | +| [groundingAttributions](./ai.groundingmetadata.md#groundingmetadatagroundingattributions) | [GroundingAttribution](./ai.groundingattribution.md#groundingattribution_interface)\[\] | | +| [retrievalQueries](./ai.groundingmetadata.md#groundingmetadataretrievalqueries) | string\[\] | | +| [webSearchQueries](./ai.groundingmetadata.md#groundingmetadatawebsearchqueries) | string\[\] | | ## GroundingMetadata.groundingAttributions diff --git a/docs-devsite/vertexai.imagengcsimage.md b/docs-devsite/ai.imagengcsimage.md similarity index 62% rename from docs-devsite/vertexai.imagengcsimage.md rename to docs-devsite/ai.imagengcsimage.md index 23770192b3b..cd11d8ee354 100644 --- a/docs-devsite/vertexai.imagengcsimage.md +++ b/docs-devsite/ai.imagengcsimage.md @@ -24,8 +24,8 @@ export interface ImagenGCSImage | Property | Type | Description | | --- | --- | --- | -| [gcsURI](./vertexai.imagengcsimage.md#imagengcsimagegcsuri) | string | The URI of the file stored in a Cloud Storage for Firebase bucket. | -| [mimeType](./vertexai.imagengcsimage.md#imagengcsimagemimetype) | string | The MIME type of the image; either "image/png" or "image/jpeg".To request a different format, set the imageFormat property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface). | +| [gcsURI](./ai.imagengcsimage.md#imagengcsimagegcsuri) | string | The URI of the file stored in a Cloud Storage for Firebase bucket. | +| [mimeType](./ai.imagengcsimage.md#imagengcsimagemimetype) | string | The MIME type of the image; either "image/png" or "image/jpeg".To request a different format, set the imageFormat property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface). | ## ImagenGCSImage.gcsURI @@ -45,7 +45,7 @@ gcsURI: string; The MIME type of the image; either `"image/png"` or `"image/jpeg"`. -To request a different format, set the `imageFormat` property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface). +To request a different format, set the `imageFormat` property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface). Signature: diff --git a/docs-devsite/vertexai.imagengenerationconfig.md b/docs-devsite/ai.imagengenerationconfig.md similarity index 52% rename from docs-devsite/vertexai.imagengenerationconfig.md rename to docs-devsite/ai.imagengenerationconfig.md index 51a66b147dc..d4f32a7e5a3 100644 --- a/docs-devsite/vertexai.imagengenerationconfig.md +++ b/docs-devsite/ai.imagengenerationconfig.md @@ -27,11 +27,11 @@ export interface ImagenGenerationConfig | Property | Type | Description | | --- | --- | --- | -| [addWatermark](./vertexai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | (Public Preview) Whether to add an invisible watermark to generated images.If set to true, an invisible SynthID watermark is embedded in generated images to indicate that they are AI generated. If set to false, watermarking will be disabled.For Imagen 3 models, the default value is true; see the addWatermark documentation for more details.When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this will default to true, and cannot be turned off. | -| [aspectRatio](./vertexai.imagengenerationconfig.md#imagengenerationconfigaspectratio) | [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | (Public Preview) The aspect ratio of the generated images. The default value is square 1:1. Supported aspect ratios depend on the Imagen model, see [ImagenAspectRatio](./vertexai.md#imagenaspectratio) for more details. | -| [imageFormat](./vertexai.imagengenerationconfig.md#imagengenerationconfigimageformat) | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) The image format of the generated images. The default is PNG.See [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) for more details. | -| [negativePrompt](./vertexai.imagengenerationconfig.md#imagengenerationconfignegativeprompt) | string | (Public Preview) A description of what should be omitted from the generated images.Support for negative prompts depends on the Imagen model.See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details.This is no longer supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) in versions greater than imagen-3.0-generate-002. | -| [numberOfImages](./vertexai.imagengenerationconfig.md#imagengenerationconfignumberofimages) | number | (Public Preview) The number of images to generate. The default value is 1.The number of sample images that may be generated in each request depends on the model (typically up to 4); see the sampleCount documentation for more details. | +| [addWatermark](./ai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | (Public Preview) Whether to add an invisible watermark to generated images.If set to true, an invisible SynthID watermark is embedded in generated images to indicate that they are AI generated. If set to false, watermarking will be disabled.For Imagen 3 models, the default value is true; see the addWatermark documentation for more details.When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this will default to true, and cannot be turned off. | +| [aspectRatio](./ai.imagengenerationconfig.md#imagengenerationconfigaspectratio) | [ImagenAspectRatio](./ai.md#imagenaspectratio) | (Public Preview) The aspect ratio of the generated images. The default value is square 1:1. Supported aspect ratios depend on the Imagen model, see [ImagenAspectRatio](./ai.md#imagenaspectratio) for more details. | +| [imageFormat](./ai.imagengenerationconfig.md#imagengenerationconfigimageformat) | [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) The image format of the generated images. The default is PNG.See [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) for more details. | +| [negativePrompt](./ai.imagengenerationconfig.md#imagengenerationconfignegativeprompt) | string | (Public Preview) A description of what should be omitted from the generated images.Support for negative prompts depends on the Imagen model.See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details.This is no longer supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)) in versions greater than imagen-3.0-generate-002. | +| [numberOfImages](./ai.imagengenerationconfig.md#imagengenerationconfignumberofimages) | number | (Public Preview) The number of images to generate. The default value is 1.The number of sample images that may be generated in each request depends on the model (typically up to 4); see the sampleCount documentation for more details. | ## ImagenGenerationConfig.addWatermark @@ -44,7 +44,7 @@ If set to `true`, an invisible SynthID watermark is embedded in generate For Imagen 3 models, the default value is `true`; see the addWatermark documentation for more details. -When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this will default to true, and cannot be turned off. +When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this will default to true, and cannot be turned off. Signature: @@ -57,7 +57,7 @@ addWatermark?: boolean; > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > -The aspect ratio of the generated images. The default value is square 1:1. Supported aspect ratios depend on the Imagen model, see [ImagenAspectRatio](./vertexai.md#imagenaspectratio) for more details. +The aspect ratio of the generated images. The default value is square 1:1. Supported aspect ratios depend on the Imagen model, see [ImagenAspectRatio](./ai.md#imagenaspectratio) for more details. Signature: @@ -72,7 +72,7 @@ aspectRatio?: ImagenAspectRatio; The image format of the generated images. The default is PNG. -See [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) for more details. +See [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) for more details. Signature: @@ -91,7 +91,7 @@ Support for negative prompts depends on the Imagen model. See the [documentation](http://firebase.google.com/docs/vertex-ai/model-parameters#imagen) for more details. -This is no longer supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) in versions greater than `imagen-3.0-generate-002`. +This is no longer supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)) in versions greater than `imagen-3.0-generate-002`. Signature: diff --git a/docs-devsite/vertexai.imagengenerationresponse.md b/docs-devsite/ai.imagengenerationresponse.md similarity index 56% rename from docs-devsite/vertexai.imagengenerationresponse.md rename to docs-devsite/ai.imagengenerationresponse.md index d8de93df3ec..54b0ac9b1a9 100644 --- a/docs-devsite/vertexai.imagengenerationresponse.md +++ b/docs-devsite/ai.imagengenerationresponse.md @@ -25,8 +25,8 @@ export interface ImagenGenerationResponse(Public Preview) The reason that images were filtered out. This property will only be defined if one or more images were filtered.Images may be filtered out due to the [ImagenSafetyFilterLevel](./vertexai.md#imagensafetyfilterlevel), [ImagenPersonFilterLevel](./vertexai.md#imagenpersonfilterlevel), or filtering included in the model. The filter levels may be adjusted in your [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface).See the [Responsible AI and usage guidelines for Imagen](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen) for more details. | -| [images](./vertexai.imagengenerationresponse.md#imagengenerationresponseimages) | T\[\] | (Public Preview) The images generated by Imagen.The number of images generated may be fewer than the number requested if one or more were filtered out; see filteredReason. | +| [filteredReason](./ai.imagengenerationresponse.md#imagengenerationresponsefilteredreason) | string | (Public Preview) The reason that images were filtered out. This property will only be defined if one or more images were filtered.Images may be filtered out due to the [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel), [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel), or filtering included in the model. The filter levels may be adjusted in your [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface).See the [Responsible AI and usage guidelines for Imagen](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen) for more details. | +| [images](./ai.imagengenerationresponse.md#imagengenerationresponseimages) | T\[\] | (Public Preview) The images generated by Imagen.The number of images generated may be fewer than the number requested if one or more were filtered out; see filteredReason. | ## ImagenGenerationResponse.filteredReason @@ -35,7 +35,7 @@ export interface ImagenGenerationResponse, [ImagenPersonFilterLevel](./vertexai.md#imagenpersonfilterlevel), or filtering included in the model. The filter levels may be adjusted in your [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface). +Images may be filtered out due to the [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel), [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel), or filtering included in the model. The filter levels may be adjusted in your [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface). See the [Responsible AI and usage guidelines for Imagen](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen) for more details. diff --git a/docs-devsite/vertexai.imagenimageformat.md b/docs-devsite/ai.imagenimageformat.md similarity index 61% rename from docs-devsite/vertexai.imagenimageformat.md rename to docs-devsite/ai.imagenimageformat.md index 68db8bbdae0..bd0bdf1baa7 100644 --- a/docs-devsite/vertexai.imagenimageformat.md +++ b/docs-devsite/ai.imagenimageformat.md @@ -15,7 +15,7 @@ https://github.com/firebase/firebase-js-sdk Defines the image format for images generated by Imagen. -Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface). +Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./ai.imagenmodelparams.md#imagenmodelparams_interface). Signature: @@ -27,15 +27,15 @@ export declare class ImagenImageFormat | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [compressionQuality](./vertexai.imagenimageformat.md#imagenimageformatcompressionquality) | | number | (Public Preview) The level of compression (a number between 0 and 100). | -| [mimeType](./vertexai.imagenimageformat.md#imagenimageformatmimetype) | | string | (Public Preview) The MIME type. | +| [compressionQuality](./ai.imagenimageformat.md#imagenimageformatcompressionquality) | | number | (Public Preview) The level of compression (a number between 0 and 100). | +| [mimeType](./ai.imagenimageformat.md#imagenimageformatmimetype) | | string | (Public Preview) The MIME type. | ## Methods | Method | Modifiers | Description | | --- | --- | --- | -| [jpeg(compressionQuality)](./vertexai.imagenimageformat.md#imagenimageformatjpeg) | static | (Public Preview) Creates an [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) for a JPEG image. | -| [png()](./vertexai.imagenimageformat.md#imagenimageformatpng) | static | (Public Preview) Creates an [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) for a PNG image. | +| [jpeg(compressionQuality)](./ai.imagenimageformat.md#imagenimageformatjpeg) | static | (Public Preview) Creates an [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) for a JPEG image. | +| [png()](./ai.imagenimageformat.md#imagenimageformatpng) | static | (Public Preview) Creates an [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) for a PNG image. | ## ImagenImageFormat.compressionQuality @@ -68,7 +68,7 @@ mimeType: string; > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > -Creates an [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) for a JPEG image. +Creates an [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) for a JPEG image. Signature: @@ -84,16 +84,16 @@ static jpeg(compressionQuality?: number): ImagenImageFormat; Returns: -[ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) +[ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) -An [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) object for a JPEG image. +An [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) object for a JPEG image. ## ImagenImageFormat.png() > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > -Creates an [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) for a PNG image. +Creates an [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) for a PNG image. Signature: @@ -102,9 +102,9 @@ static png(): ImagenImageFormat; ``` Returns: -[ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) +[ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) -An [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) object for a PNG image. +An [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) object for a PNG image. ### Example diff --git a/docs-devsite/vertexai.imageninlineimage.md b/docs-devsite/ai.imageninlineimage.md similarity index 66% rename from docs-devsite/vertexai.imageninlineimage.md rename to docs-devsite/ai.imageninlineimage.md index a72937b5e5d..4bb81cac55d 100644 --- a/docs-devsite/vertexai.imageninlineimage.md +++ b/docs-devsite/ai.imageninlineimage.md @@ -25,8 +25,8 @@ export interface ImagenInlineImage | Property | Type | Description | | --- | --- | --- | -| [bytesBase64Encoded](./vertexai.imageninlineimage.md#imageninlineimagebytesbase64encoded) | string | (Public Preview) The base64-encoded image data. | -| [mimeType](./vertexai.imageninlineimage.md#imageninlineimagemimetype) | string | (Public Preview) The MIME type of the image; either "image/png" or "image/jpeg".To request a different format, set the imageFormat property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface). | +| [bytesBase64Encoded](./ai.imageninlineimage.md#imageninlineimagebytesbase64encoded) | string | (Public Preview) The base64-encoded image data. | +| [mimeType](./ai.imageninlineimage.md#imageninlineimagemimetype) | string | (Public Preview) The MIME type of the image; either "image/png" or "image/jpeg".To request a different format, set the imageFormat property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface). | ## ImagenInlineImage.bytesBase64Encoded @@ -48,7 +48,7 @@ bytesBase64Encoded: string; The MIME type of the image; either `"image/png"` or `"image/jpeg"`. -To request a different format, set the `imageFormat` property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface). +To request a different format, set the `imageFormat` property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface). Signature: diff --git a/docs-devsite/vertexai.imagenmodel.md b/docs-devsite/ai.imagenmodel.md similarity index 62% rename from docs-devsite/vertexai.imagenmodel.md rename to docs-devsite/ai.imagenmodel.md index e69c49b8572..911971e0988 100644 --- a/docs-devsite/vertexai.imagenmodel.md +++ b/docs-devsite/ai.imagenmodel.md @@ -22,34 +22,34 @@ This class provides methods for generating images using the Imagen model. ```typescript export declare class ImagenModel extends AIModel ``` -Extends: [AIModel](./vertexai.aimodel.md#aimodel_class) +Extends: [AIModel](./ai.aimodel.md#aimodel_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(ai, modelParams, requestOptions)](./vertexai.imagenmodel.md#imagenmodelconstructor) | | (Public Preview) Constructs a new instance of the [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class. | +| [(constructor)(ai, modelParams, requestOptions)](./ai.imagenmodel.md#imagenmodelconstructor) | | (Public Preview) Constructs a new instance of the [ImagenModel](./ai.imagenmodel.md#imagenmodel_class) class. | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [generationConfig](./vertexai.imagenmodel.md#imagenmodelgenerationconfig) | | [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) The Imagen generation configuration. | -| [requestOptions](./vertexai.imagenmodel.md#imagenmodelrequestoptions) | | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) \| undefined | (Public Preview) | -| [safetySettings](./vertexai.imagenmodel.md#imagenmodelsafetysettings) | | [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Safety settings for filtering inappropriate content. | +| [generationConfig](./ai.imagenmodel.md#imagenmodelgenerationconfig) | | [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) The Imagen generation configuration. | +| [requestOptions](./ai.imagenmodel.md#imagenmodelrequestoptions) | | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \| undefined | (Public Preview) | +| [safetySettings](./ai.imagenmodel.md#imagenmodelsafetysettings) | | [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Safety settings for filtering inappropriate content. | ## Methods | Method | Modifiers | Description | | --- | --- | --- | -| [generateImages(prompt)](./vertexai.imagenmodel.md#imagenmodelgenerateimages) | | (Public Preview) Generates images using the Imagen model and returns them as base64-encoded strings. | +| [generateImages(prompt)](./ai.imagenmodel.md#imagenmodelgenerateimages) | | (Public Preview) Generates images using the Imagen model and returns them as base64-encoded strings. | ## ImagenModel.(constructor) > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > -Constructs a new instance of the [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class. +Constructs a new instance of the [ImagenModel](./ai.imagenmodel.md#imagenmodel_class) class. Signature: @@ -61,9 +61,9 @@ constructor(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOpti | Parameter | Type | Description | | --- | --- | --- | -| ai | [AI](./vertexai.ai.md#ai_interface) | an [AI](./vertexai.ai.md#ai_interface) instance. | -| modelParams | [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making requests to Imagen. | -| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) \| undefined | Additional options to use when making requests. | +| ai | [AI](./ai.ai.md#ai_interface) | an [AI](./ai.ai.md#ai_interface) instance. | +| modelParams | [ImagenModelParams](./ai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making requests to Imagen. | +| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \| undefined | Additional options to use when making requests. | #### Exceptions @@ -129,9 +129,9 @@ generateImages(prompt: string): PromiseReturns: -Promise<[ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface)<[ImagenInlineImage](./vertexai.imageninlineimage.md#imageninlineimage_interface)>> +Promise<[ImagenGenerationResponse](./ai.imagengenerationresponse.md#imagengenerationresponse_interface)<[ImagenInlineImage](./ai.imageninlineimage.md#imageninlineimage_interface)>> -A promise that resolves to an [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) object containing the generated images. +A promise that resolves to an [ImagenGenerationResponse](./ai.imagengenerationresponse.md#imagengenerationresponse_interface) object containing the generated images. #### Exceptions diff --git a/docs-devsite/vertexai.imagenmodelparams.md b/docs-devsite/ai.imagenmodelparams.md similarity index 63% rename from docs-devsite/vertexai.imagenmodelparams.md rename to docs-devsite/ai.imagenmodelparams.md index 5396a36e4d1..a63345b64e6 100644 --- a/docs-devsite/vertexai.imagenmodelparams.md +++ b/docs-devsite/ai.imagenmodelparams.md @@ -13,7 +13,7 @@ https://github.com/firebase/firebase-js-sdk > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > -Parameters for configuring an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class). +Parameters for configuring an [ImagenModel](./ai.imagenmodel.md#imagenmodel_class). Signature: @@ -25,9 +25,9 @@ export interface ImagenModelParams | Property | Type | Description | | --- | --- | --- | -| [generationConfig](./vertexai.imagenmodelparams.md#imagenmodelparamsgenerationconfig) | [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) Configuration options for generating images with Imagen. | -| [model](./vertexai.imagenmodelparams.md#imagenmodelparamsmodel) | string | (Public Preview) The Imagen model to use for generating images. For example: imagen-3.0-generate-002.Only Imagen 3 models (named imagen-3.0-*) are supported.See [model versions](https://firebase.google.com/docs/vertex-ai/models) for a full list of supported Imagen 3 models. | -| [safetySettings](./vertexai.imagenmodelparams.md#imagenmodelparamssafetysettings) | [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Safety settings for filtering potentially inappropriate content. | +| [generationConfig](./ai.imagenmodelparams.md#imagenmodelparamsgenerationconfig) | [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) Configuration options for generating images with Imagen. | +| [model](./ai.imagenmodelparams.md#imagenmodelparamsmodel) | string | (Public Preview) The Imagen model to use for generating images. For example: imagen-3.0-generate-002.Only Imagen 3 models (named imagen-3.0-*) are supported.See [model versions](https://firebase.google.com/docs/vertex-ai/models) for a full list of supported Imagen 3 models. | +| [safetySettings](./ai.imagenmodelparams.md#imagenmodelparamssafetysettings) | [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Safety settings for filtering potentially inappropriate content. | ## ImagenModelParams.generationConfig diff --git a/docs-devsite/vertexai.imagensafetysettings.md b/docs-devsite/ai.imagensafetysettings.md similarity index 72% rename from docs-devsite/vertexai.imagensafetysettings.md rename to docs-devsite/ai.imagensafetysettings.md index 3cf7931a959..366e615d243 100644 --- a/docs-devsite/vertexai.imagensafetysettings.md +++ b/docs-devsite/ai.imagensafetysettings.md @@ -27,8 +27,8 @@ export interface ImagenSafetySettings | Property | Type | Description | | --- | --- | --- | -| [personFilterLevel](./vertexai.imagensafetysettings.md#imagensafetysettingspersonfilterlevel) | [ImagenPersonFilterLevel](./vertexai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed. | -| [safetyFilterLevel](./vertexai.imagensafetysettings.md#imagensafetysettingssafetyfilterlevel) | [ImagenSafetyFilterLevel](./vertexai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressive to filter out sensitive content from generated images. | +| [personFilterLevel](./ai.imagensafetysettings.md#imagensafetysettingspersonfilterlevel) | [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed. | +| [safetyFilterLevel](./ai.imagensafetysettings.md#imagensafetysettingssafetyfilterlevel) | [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressive to filter out sensitive content from generated images. | ## ImagenSafetySettings.personFilterLevel diff --git a/docs-devsite/vertexai.inlinedatapart.md b/docs-devsite/ai.inlinedatapart.md similarity index 62% rename from docs-devsite/vertexai.inlinedatapart.md rename to docs-devsite/ai.inlinedatapart.md index 0cb064fc357..0dd68edda68 100644 --- a/docs-devsite/vertexai.inlinedatapart.md +++ b/docs-devsite/ai.inlinedatapart.md @@ -22,11 +22,11 @@ export interface InlineDataPart | Property | Type | Description | | --- | --- | --- | -| [functionCall](./vertexai.inlinedatapart.md#inlinedatapartfunctioncall) | never | | -| [functionResponse](./vertexai.inlinedatapart.md#inlinedatapartfunctionresponse) | never | | -| [inlineData](./vertexai.inlinedatapart.md#inlinedatapartinlinedata) | [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | | -| [text](./vertexai.inlinedatapart.md#inlinedataparttext) | never | | -| [videoMetadata](./vertexai.inlinedatapart.md#inlinedatapartvideometadata) | [VideoMetadata](./vertexai.videometadata.md#videometadata_interface) | Applicable if inlineData is a video. | +| [functionCall](./ai.inlinedatapart.md#inlinedatapartfunctioncall) | never | | +| [functionResponse](./ai.inlinedatapart.md#inlinedatapartfunctionresponse) | never | | +| [inlineData](./ai.inlinedatapart.md#inlinedatapartinlinedata) | [GenerativeContentBlob](./ai.generativecontentblob.md#generativecontentblob_interface) | | +| [text](./ai.inlinedatapart.md#inlinedataparttext) | never | | +| [videoMetadata](./ai.inlinedatapart.md#inlinedatapartvideometadata) | [VideoMetadata](./ai.videometadata.md#videometadata_interface) | Applicable if inlineData is a video. | ## InlineDataPart.functionCall diff --git a/docs-devsite/vertexai.integerschema.md b/docs-devsite/ai.integerschema.md similarity index 71% rename from docs-devsite/vertexai.integerschema.md rename to docs-devsite/ai.integerschema.md index 4822bdd618b..4ba96e49ca5 100644 --- a/docs-devsite/vertexai.integerschema.md +++ b/docs-devsite/ai.integerschema.md @@ -17,13 +17,13 @@ Schema class for "integer" types. ```typescript export declare class IntegerSchema extends Schema ``` -Extends: [Schema](./vertexai.schema.md#schema_class) +Extends: [Schema](./ai.schema.md#schema_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(schemaParams)](./vertexai.integerschema.md#integerschemaconstructor) | | Constructs a new instance of the IntegerSchema class | +| [(constructor)(schemaParams)](./ai.integerschema.md#integerschemaconstructor) | | Constructs a new instance of the IntegerSchema class | ## IntegerSchema.(constructor) @@ -39,5 +39,5 @@ constructor(schemaParams?: SchemaParams); | Parameter | Type | Description | | --- | --- | --- | -| schemaParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | +| schemaParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | diff --git a/docs-devsite/ai.md b/docs-devsite/ai.md new file mode 100644 index 00000000000..2f5c8df7c94 --- /dev/null +++ b/docs-devsite/ai.md @@ -0,0 +1,716 @@ +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 %} + +# ai package +The Firebase AI Web SDK. + +## Functions + +| Function | Description | +| --- | --- | +| function(app, ...) | +| [getAI(app, options)](./ai.md#getai_a94a413) | Returns the default [AI](./ai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | +| [getVertexAI(app, options)](./ai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./ai.md#getai_a94a413).Returns a [VertexAI](./ai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. | +| function(ai, ...) | +| [getGenerativeModel(ai, modelParams, requestOptions)](./ai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./ai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | +| [getImagenModel(ai, modelParams, requestOptions)](./ai.md#getimagenmodel_e1f6645) | (Public Preview) Returns an [ImagenModel](./ai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | + +## Classes + +| Class | Description | +| --- | --- | +| [AIError](./ai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. | +| [AIModel](./ai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.Instances of this class are associated with a specific Firebase AI backend (either the Vertex AI Gemini API or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. | +| [ArraySchema](./ai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | +| [Backend](./ai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class): For the Vertex AI Gemini API. | +| [BooleanSchema](./ai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | +| [ChatSession](./ai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | +| [GenerativeModel](./ai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | +| [GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) | Configuration class for the Gemini Developer API (using Google AI).Use this with [AIOptions](./ai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./ai.md#getai_a94a413) to specify the Gemini Developer API as the backend. | +| [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) Defines the image format for images generated by Imagen.Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./ai.imagenmodelparams.md#imagenmodelparams_interface). | +| [ImagenModel](./ai.imagenmodel.md#imagenmodel_class) | (Public Preview) Class for Imagen model APIs.This class provides methods for generating images using the Imagen model. | +| [IntegerSchema](./ai.integerschema.md#integerschema_class) | Schema class for "integer" types. | +| [NumberSchema](./ai.numberschema.md#numberschema_class) | Schema class for "number" types. | +| [ObjectSchema](./ai.objectschema.md#objectschema_class) | Schema class for "object" types. The properties param must be a map of Schema objects. | +| [Schema](./ai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with JSON.stringify() into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) | +| [StringSchema](./ai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. | +| [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Vertex AI Gemini API.Use this with [AIOptions](./ai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./ai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. | + +## Enumerations + +| Enumeration | Description | +| --- | --- | +| [AIErrorCode](./ai.md#aierrorcode) | Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. | +| [BlockReason](./ai.md#blockreason) | Reason that a prompt was blocked. | +| [FinishReason](./ai.md#finishreason) | Reason that a candidate finished. | +| [FunctionCallingMode](./ai.md#functioncallingmode) | | +| [HarmBlockMethod](./ai.md#harmblockmethod) | This property is not supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)). | +| [HarmBlockThreshold](./ai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | +| [HarmCategory](./ai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | +| [HarmProbability](./ai.md#harmprobability) | Probability that a prompt or candidate matches a harm category. | +| [HarmSeverity](./ai.md#harmseverity) | Harm severity levels. | +| [ImagenAspectRatio](./ai.md#imagenaspectratio) | (Public Preview) Aspect ratios for Imagen images.To specify an aspect ratio for generated images, set the aspectRatio property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface).See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. | +| [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed.See the personGeneration documentation for more details. | +| [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | +| [Modality](./ai.md#modality) | Content part modality. | +| [SchemaType](./ai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | + +## Interfaces + +| Interface | Description | +| --- | --- | +| [AI](./ai.ai.md#ai_interface) | An instance of the Firebase AI SDK.Do not create this instance directly. Instead, use [getAI()](./ai.md#getai_a94a413). | +| [AIOptions](./ai.aioptions.md#aioptions_interface) | Options for initializing the AI service using [getAI()](./ai.md#getai_a94a413). This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) and configuring its specific options (like location for Vertex AI). | +| [BaseParams](./ai.baseparams.md#baseparams_interface) | Base parameters for a number of methods. | +| [Citation](./ai.citation.md#citation_interface) | A single citation. | +| [CitationMetadata](./ai.citationmetadata.md#citationmetadata_interface) | Citation metadata that may be found on a [GenerateContentCandidate](./ai.generatecontentcandidate.md#generatecontentcandidate_interface). | +| [Content](./ai.content.md#content_interface) | Content type for both prompts and response candidates. | +| [CountTokensRequest](./ai.counttokensrequest.md#counttokensrequest_interface) | Params for calling [GenerativeModel.countTokens()](./ai.generativemodel.md#generativemodelcounttokens) | +| [CountTokensResponse](./ai.counttokensresponse.md#counttokensresponse_interface) | Response from calling [GenerativeModel.countTokens()](./ai.generativemodel.md#generativemodelcounttokens). | +| [CustomErrorData](./ai.customerrordata.md#customerrordata_interface) | Details object that contains data originating from a bad HTTP response. | +| [Date\_2](./ai.date_2.md#date_2_interface) | Protobuf google.type.Date | +| [EnhancedGenerateContentResponse](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface) | Response object wrapped with helper methods. | +| [ErrorDetails](./ai.errordetails.md#errordetails_interface) | Details object that may be included in an error response. | +| [FileData](./ai.filedata.md#filedata_interface) | Data pointing to a file uploaded on Google Cloud Storage. | +| [FileDataPart](./ai.filedatapart.md#filedatapart_interface) | Content part interface if the part represents [FileData](./ai.filedata.md#filedata_interface) | +| [FunctionCall](./ai.functioncall.md#functioncall_interface) | A predicted [FunctionCall](./ai.functioncall.md#functioncall_interface) returned from the model that contains a string representing the [FunctionDeclaration.name](./ai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing the parameters and their values. | +| [FunctionCallingConfig](./ai.functioncallingconfig.md#functioncallingconfig_interface) | | +| [FunctionCallPart](./ai.functioncallpart.md#functioncallpart_interface) | Content part interface if the part represents a [FunctionCall](./ai.functioncall.md#functioncall_interface). | +| [FunctionDeclaration](./ai.functiondeclaration.md#functiondeclaration_interface) | Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included in this declaration are the function name and parameters. This FunctionDeclaration is a representation of a block of code that can be used as a Tool by the model and executed by the client. | +| [FunctionDeclarationsTool](./ai.functiondeclarationstool.md#functiondeclarationstool_interface) | A FunctionDeclarationsTool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. | +| [FunctionResponse](./ai.functionresponse.md#functionresponse_interface) | The result output from a [FunctionCall](./ai.functioncall.md#functioncall_interface) that contains a string representing the [FunctionDeclaration.name](./ai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall](./ai.functioncall.md#functioncall_interface) made based on model prediction. | +| [FunctionResponsePart](./ai.functionresponsepart.md#functionresponsepart_interface) | Content part interface if the part represents [FunctionResponse](./ai.functionresponse.md#functionresponse_interface). | +| [GenerateContentCandidate](./ai.generatecontentcandidate.md#generatecontentcandidate_interface) | A candidate returned as part of a [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface). | +| [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | Request sent through [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) | +| [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface) | Individual response from [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) and [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream). generateContentStream() will return one in each chunk until the stream is done. | +| [GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface) | Result object returned from [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) call. | +| [GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface) | Result object returned from [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream) call. Iterate over stream to get chunks as they come in and/or use the response promise to get the aggregated response when the stream is done. | +| [GenerationConfig](./ai.generationconfig.md#generationconfig_interface) | Config options for content-related requests | +| [GenerativeContentBlob](./ai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. | +| [GroundingAttribution](./ai.groundingattribution.md#groundingattribution_interface) | | +| [GroundingMetadata](./ai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. | +| [ImagenGCSImage](./ai.imagengcsimage.md#imagengcsimage_interface) | An image generated by Imagen, stored in a Cloud Storage for Firebase bucket.This feature is not available yet. | +| [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) Configuration options for generating images with Imagen.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details. | +| [ImagenGenerationResponse](./ai.imagengenerationresponse.md#imagengenerationresponse_interface) | (Public Preview) The response from a request to generate images with Imagen. | +| [ImagenInlineImage](./ai.imageninlineimage.md#imageninlineimage_interface) | (Public Preview) An image generated by Imagen, represented as inline data. | +| [ImagenModelParams](./ai.imagenmodelparams.md#imagenmodelparams_interface) | (Public Preview) Parameters for configuring an [ImagenModel](./ai.imagenmodel.md#imagenmodel_class). | +| [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Settings for controlling the aggressiveness of filtering out sensitive content.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details. | +| [InlineDataPart](./ai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. | +| [ModalityTokenCount](./ai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. | +| [ModelParams](./ai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_80bd839). | +| [ObjectSchemaInterface](./ai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./ai.objectschema.md#objectschema_class) class. | +| [PromptFeedback](./ai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with blockReason and the relevant safetyRatings. | +| [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_80bd839). | +| [RetrievedContextAttribution](./ai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | | +| [SafetyRating](./ai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./ai.generatecontentcandidate.md#generatecontentcandidate_interface) | +| [SafetySetting](./ai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. | +| [SchemaInterface](./ai.schemainterface.md#schemainterface_interface) | Interface for [Schema](./ai.schema.md#schema_class) class. | +| [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | Params passed to [Schema](./ai.schema.md#schema_class) static methods to create specific [Schema](./ai.schema.md#schema_class) classes. | +| [SchemaRequest](./ai.schemarequest.md#schemarequest_interface) | Final format for [Schema](./ai.schema.md#schema_class) params passed to backend requests. | +| [SchemaShared](./ai.schemashared.md#schemashared_interface) | Basic [Schema](./ai.schema.md#schema_class) properties shared across several Schema-related types. | +| [Segment](./ai.segment.md#segment_interface) | | +| [StartChatParams](./ai.startchatparams.md#startchatparams_interface) | Params for [GenerativeModel.startChat()](./ai.generativemodel.md#generativemodelstartchat). | +| [TextPart](./ai.textpart.md#textpart_interface) | Content part interface if the part represents a text string. | +| [ToolConfig](./ai.toolconfig.md#toolconfig_interface) | Tool config. This config is shared for all tools provided in the request. | +| [UsageMetadata](./ai.usagemetadata.md#usagemetadata_interface) | Usage metadata about a [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface). | +| [VertexAIOptions](./ai.vertexaioptions.md#vertexaioptions_interface) | Options when initializing the Firebase AI SDK. | +| [VideoMetadata](./ai.videometadata.md#videometadata_interface) | Describes the input video content. | +| [WebAttribution](./ai.webattribution.md#webattribution_interface) | | + +## Variables + +| Variable | Description | +| --- | --- | +| [BackendType](./ai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | +| [POSSIBLE\_ROLES](./ai.md#possible_roles) | Possible roles. | +| [ResponseModality](./ai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | +| [VertexAIError](./ai.md#vertexaierror) | Error class for the Firebase AI SDK.For more information, refer to the documentation for the new [AIError](./ai.aierror.md#aierror_class). | +| [VertexAIModel](./ai.md#vertexaimodel) | Base class for Firebase AI model APIs.For more information, refer to the documentation for the new [AIModel](./ai.aimodel.md#aimodel_class). | + +## Type Aliases + +| Type Alias | Description | +| --- | --- | +| [BackendType](./ai.md#backendtype) | Type alias representing valid backend types. It can be either 'VERTEX_AI' or 'GOOGLE_AI'. | +| [Part](./ai.md#part) | Content part - includes text, image/video, or function call/response part types. | +| [ResponseModality](./ai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | +| [Role](./ai.md#role) | Role is the producer of the content. | +| [Tool](./ai.md#tool) | Defines a tool that model can call to access external knowledge. | +| [TypedSchema](./ai.md#typedschema) | A type that includes all specific Schema types. | +| [VertexAI](./ai.md#vertexai) | An instance of the Firebase AI SDK.For more information, refer to the documentation for the new [AI](./ai.ai.md#ai_interface) interface. | + +## function(app, ...) + +### getAI(app, options) {:#getai_a94a413} + +Returns the default [AI](./ai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. + +Signature: + +```typescript +export declare function getAI(app?: FirebaseApp, options?: AIOptions): AI; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | +| options | [AIOptions](./ai.aioptions.md#aioptions_interface) | [AIOptions](./ai.aioptions.md#aioptions_interface) that configure the AI instance. | + +Returns: + +[AI](./ai.ai.md#ai_interface) + +The default [AI](./ai.ai.md#ai_interface) instance for the given [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). + +### Example 1 + + +```javascript +const ai = getAI(app); + +``` + +### Example 2 + + +```javascript +// Get an AI instance configured to use the Gemini Developer API (via Google AI). +const ai = getAI(app, { backend: new GoogleAIBackend() }); + +``` + +### Example 3 + + +```javascript +// Get an AI instance configured to use the Vertex AI Gemini API. +const ai = getAI(app, { backend: new VertexAIBackend() }); + +``` + +### getVertexAI(app, options) {:#getvertexai_04094cf} + +It is recommended to use the new [getAI()](./ai.md#getai_a94a413). + +Returns a [VertexAI](./ai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. + +Signature: + +```typescript +export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | +| options | [VertexAIOptions](./ai.vertexaioptions.md#vertexaioptions_interface) | Options to configure the Vertex AI instance, including the location. | + +Returns: + +[VertexAI](./ai.md#vertexai) + +## function(ai, ...) + +### getGenerativeModel(ai, modelParams, requestOptions) {:#getgenerativemodel_80bd839} + +Returns a [GenerativeModel](./ai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. + +Signature: + +```typescript +export declare function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| ai | [AI](./ai.ai.md#ai_interface) | | +| modelParams | [ModelParams](./ai.modelparams.md#modelparams_interface) | | +| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | | + +Returns: + +[GenerativeModel](./ai.generativemodel.md#generativemodel_class) + +### getImagenModel(ai, modelParams, requestOptions) {:#getimagenmodel_e1f6645} + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Returns an [ImagenModel](./ai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen. + +Only Imagen 3 models (named `imagen-3.0-*`) are supported. + +Signature: + +```typescript +export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| ai | [AI](./ai.ai.md#ai_interface) | An [AI](./ai.ai.md#ai_interface) instance. | +| modelParams | [ImagenModelParams](./ai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making Imagen requests. | +| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. | + +Returns: + +[ImagenModel](./ai.imagenmodel.md#imagenmodel_class) + +#### Exceptions + +If the `apiKey` or `projectId` fields are missing in your Firebase config. + +## BackendType + +An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with. + +These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. + +Signature: + +```typescript +BackendType: { + readonly VERTEX_AI: "VERTEX_AI"; + readonly GOOGLE_AI: "GOOGLE_AI"; +} +``` + +## POSSIBLE\_ROLES + +Possible roles. + +Signature: + +```typescript +POSSIBLE_ROLES: readonly ["user", "model", "function", "system"] +``` + +## ResponseModality + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Generation modalities to be returned in generation responses. + +Signature: + +```typescript +ResponseModality: { + readonly TEXT: "TEXT"; + readonly IMAGE: "IMAGE"; +} +``` + +## VertexAIError + +Error class for the Firebase AI SDK. + +For more information, refer to the documentation for the new [AIError](./ai.aierror.md#aierror_class). + +Signature: + +```typescript +VertexAIError: typeof AIError +``` + +## VertexAIModel + +Base class for Firebase AI model APIs. + +For more information, refer to the documentation for the new [AIModel](./ai.aimodel.md#aimodel_class). + +Signature: + +```typescript +VertexAIModel: typeof AIModel +``` + +## BackendType + +Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. + +Signature: + +```typescript +export type BackendType = (typeof BackendType)[keyof typeof BackendType]; +``` + +## Part + +Content part - includes text, image/video, or function call/response part types. + +Signature: + +```typescript +export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; +``` + +## ResponseModality + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Generation modalities to be returned in generation responses. + +Signature: + +```typescript +export type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality]; +``` + +## Role + +Role is the producer of the content. + +Signature: + +```typescript +export type Role = (typeof POSSIBLE_ROLES)[number]; +``` + +## Tool + +Defines a tool that model can call to access external knowledge. + +Signature: + +```typescript +export declare type Tool = FunctionDeclarationsTool; +``` + +## TypedSchema + +A type that includes all specific Schema types. + +Signature: + +```typescript +export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; +``` + +## VertexAI + +An instance of the Firebase AI SDK. + +For more information, refer to the documentation for the new [AI](./ai.ai.md#ai_interface) interface. + +Signature: + +```typescript +export type VertexAI = AI; +``` + +## AIErrorCode + +Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. + +Signature: + +```typescript +export declare const enum AIErrorCode +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| API\_NOT\_ENABLED | "api-not-enabled" | An error due to the Firebase API not being enabled in the Console. | +| ERROR | "error" | A generic error occurred. | +| FETCH\_ERROR | "fetch-error" | An error occurred while performing a fetch. | +| INVALID\_CONTENT | "invalid-content" | An error associated with a Content object. | +| INVALID\_SCHEMA | "invalid-schema" | An error due to invalid Schema input. | +| NO\_API\_KEY | "no-api-key" | An error occurred due to a missing Firebase API key. | +| NO\_APP\_ID | "no-app-id" | An error occured due to a missing Firebase app ID. | +| NO\_MODEL | "no-model" | An error occurred due to a model name not being specified during initialization. | +| NO\_PROJECT\_ID | "no-project-id" | An error occurred due to a missing project ID. | +| PARSE\_FAILED | "parse-failed" | An error occurred while parsing. | +| REQUEST\_ERROR | "request-error" | An error occurred in a request. | +| RESPONSE\_ERROR | "response-error" | An error occurred in a response. | +| UNSUPPORTED | "unsupported" | An error occured due an attempt to use an unsupported feature. | + +## BlockReason + +Reason that a prompt was blocked. + +Signature: + +```typescript +export declare enum BlockReason +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| BLOCKLIST | "BLOCKLIST" | Content was blocked because it contained terms from the terminology blocklist. | +| OTHER | "OTHER" | Content was blocked, but the reason is uncategorized. | +| PROHIBITED\_CONTENT | "PROHIBITED_CONTENT" | Content was blocked due to prohibited content. | +| SAFETY | "SAFETY" | Content was blocked by safety settings. | + +## FinishReason + +Reason that a candidate finished. + +Signature: + +```typescript +export declare enum FinishReason +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| BLOCKLIST | "BLOCKLIST" | The candidate content contained forbidden terms. | +| MALFORMED\_FUNCTION\_CALL | "MALFORMED_FUNCTION_CALL" | The function call generated by the model was invalid. | +| MAX\_TOKENS | "MAX_TOKENS" | The maximum number of tokens as specified in the request was reached. | +| OTHER | "OTHER" | Unknown reason. | +| PROHIBITED\_CONTENT | "PROHIBITED_CONTENT" | The candidate content potentially contained prohibited content. | +| RECITATION | "RECITATION" | The candidate content was flagged for recitation reasons. | +| SAFETY | "SAFETY" | The candidate content was flagged for safety reasons. | +| SPII | "SPII" | The candidate content potentially contained Sensitive Personally Identifiable Information (SPII). | +| STOP | "STOP" | Natural stop point of the model or provided stop sequence. | + +## FunctionCallingMode + + +Signature: + +```typescript +export declare enum FunctionCallingMode +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| ANY | "ANY" | Model is constrained to always predicting a function call only. If allowed_function_names is set, the predicted function call will be limited to any one of allowed_function_names, else the predicted function call will be any one of the provided function_declarations. | +| AUTO | "AUTO" | Default model behavior; model decides to predict either a function call or a natural language response. | +| NONE | "NONE" | Model will not predict any function call. Model behavior is same as when not passing any function declarations. | + +## HarmBlockMethod + +This property is not supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)). + +Signature: + +```typescript +export declare enum HarmBlockMethod +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| PROBABILITY | "PROBABILITY" | The harm block method uses the probability score. | +| SEVERITY | "SEVERITY" | The harm block method uses both probability and severity scores. | + +## HarmBlockThreshold + +Threshold above which a prompt or candidate will be blocked. + +Signature: + +```typescript +export declare enum HarmBlockThreshold +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| BLOCK\_LOW\_AND\_ABOVE | "BLOCK_LOW_AND_ABOVE" | Content with NEGLIGIBLE will be allowed. | +| BLOCK\_MEDIUM\_AND\_ABOVE | "BLOCK_MEDIUM_AND_ABOVE" | Content with NEGLIGIBLE and LOW will be allowed. | +| BLOCK\_NONE | "BLOCK_NONE" | All content will be allowed. | +| BLOCK\_ONLY\_HIGH | "BLOCK_ONLY_HIGH" | Content with NEGLIGIBLE, LOW, and MEDIUM will be allowed. | + +## HarmCategory + +Harm categories that would cause prompts or candidates to be blocked. + +Signature: + +```typescript +export declare enum HarmCategory +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| HARM\_CATEGORY\_DANGEROUS\_CONTENT | "HARM_CATEGORY_DANGEROUS_CONTENT" | | +| HARM\_CATEGORY\_HARASSMENT | "HARM_CATEGORY_HARASSMENT" | | +| HARM\_CATEGORY\_HATE\_SPEECH | "HARM_CATEGORY_HATE_SPEECH" | | +| HARM\_CATEGORY\_SEXUALLY\_EXPLICIT | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | | + +## HarmProbability + +Probability that a prompt or candidate matches a harm category. + +Signature: + +```typescript +export declare enum HarmProbability +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| HIGH | "HIGH" | Content has a high chance of being unsafe. | +| LOW | "LOW" | Content has a low chance of being unsafe. | +| MEDIUM | "MEDIUM" | Content has a medium chance of being unsafe. | +| NEGLIGIBLE | "NEGLIGIBLE" | Content has a negligible chance of being unsafe. | + +## HarmSeverity + +Harm severity levels. + +Signature: + +```typescript +export declare enum HarmSeverity +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| HARM\_SEVERITY\_HIGH | "HARM_SEVERITY_HIGH" | High level of harm severity. | +| HARM\_SEVERITY\_LOW | "HARM_SEVERITY_LOW" | Low level of harm severity. | +| HARM\_SEVERITY\_MEDIUM | "HARM_SEVERITY_MEDIUM" | Medium level of harm severity. | +| HARM\_SEVERITY\_NEGLIGIBLE | "HARM_SEVERITY_NEGLIGIBLE" | Negligible level of harm severity. | +| HARM\_SEVERITY\_UNSUPPORTED | "HARM_SEVERITY_UNSUPPORTED" | Harm severity is not supported. | + +## ImagenAspectRatio + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Aspect ratios for Imagen images. + +To specify an aspect ratio for generated images, set the `aspectRatio` property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface). + +See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. + +Signature: + +```typescript +export declare enum ImagenAspectRatio +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| LANDSCAPE\_16x9 | "16:9" | (Public Preview) Landscape (16:9) aspect ratio. | +| LANDSCAPE\_3x4 | "3:4" | (Public Preview) Landscape (3:4) aspect ratio. | +| PORTRAIT\_4x3 | "4:3" | (Public Preview) Portrait (4:3) aspect ratio. | +| PORTRAIT\_9x16 | "9:16" | (Public Preview) Portrait (9:16) aspect ratio. | +| SQUARE | "1:1" | (Public Preview) Square (1:1) aspect ratio. | + +## ImagenPersonFilterLevel + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +A filter level controlling whether generation of images containing people or faces is allowed. + +See the personGeneration documentation for more details. + +Signature: + +```typescript +export declare enum ImagenPersonFilterLevel +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| ALLOW\_ADULT | "allow_adult" | (Public Preview) Allow generation of images containing adults only; images of children are filtered out.Generation of images containing people or faces may require your use case to be reviewed and approved by Cloud support; see the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) for more details. | +| ALLOW\_ALL | "allow_all" | (Public Preview) Allow generation of images containing adults only; images of children are filtered out.Generation of images containing people or faces may require your use case to be reviewed and approved by Cloud support; see the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) for more details. | +| BLOCK\_ALL | "dont_allow" | (Public Preview) Disallow generation of images containing people or faces; images of people are filtered out. | + +## ImagenSafetyFilterLevel + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +A filter level controlling how aggressively to filter sensitive content. + +Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, `violence`, `sexual`, `derogatory`, and `toxic`). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. + +Signature: + +```typescript +export declare enum ImagenSafetyFilterLevel +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| BLOCK\_LOW\_AND\_ABOVE | "block_low_and_above" | (Public Preview) The most aggressive filtering level; most strict blocking. | +| BLOCK\_MEDIUM\_AND\_ABOVE | "block_medium_and_above" | (Public Preview) Blocks some sensitive prompts and responses. | +| BLOCK\_NONE | "block_none" | (Public Preview) The least aggressive filtering level; blocks very few sensitive prompts and responses.Access to this feature is restricted and may require your case to be reviewed and approved by Cloud support. | +| BLOCK\_ONLY\_HIGH | "block_only_high" | (Public Preview) Blocks few sensitive prompts and responses. | + +## Modality + +Content part modality. + +Signature: + +```typescript +export declare enum Modality +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| AUDIO | "AUDIO" | Audio. | +| DOCUMENT | "DOCUMENT" | Document (for example, PDF). | +| IMAGE | "IMAGE" | Image. | +| MODALITY\_UNSPECIFIED | "MODALITY_UNSPECIFIED" | Unspecified modality. | +| TEXT | "TEXT" | Plain text. | +| VIDEO | "VIDEO" | Video. | + +## SchemaType + +Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) + +Signature: + +```typescript +export declare enum SchemaType +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| ARRAY | "array" | Array type. | +| BOOLEAN | "boolean" | Boolean type. | +| INTEGER | "integer" | Integer type. | +| NUMBER | "number" | Number type. | +| OBJECT | "object" | Object type. | +| STRING | "string" | String type. | + diff --git a/docs-devsite/vertexai.modalitytokencount.md b/docs-devsite/ai.modalitytokencount.md similarity index 74% rename from docs-devsite/vertexai.modalitytokencount.md rename to docs-devsite/ai.modalitytokencount.md index d710b51fba6..b1a504dddbc 100644 --- a/docs-devsite/vertexai.modalitytokencount.md +++ b/docs-devsite/ai.modalitytokencount.md @@ -22,8 +22,8 @@ export interface ModalityTokenCount | Property | Type | Description | | --- | --- | --- | -| [modality](./vertexai.modalitytokencount.md#modalitytokencountmodality) | [Modality](./vertexai.md#modality) | The modality associated with this token count. | -| [tokenCount](./vertexai.modalitytokencount.md#modalitytokencounttokencount) | number | The number of tokens counted. | +| [modality](./ai.modalitytokencount.md#modalitytokencountmodality) | [Modality](./ai.md#modality) | The modality associated with this token count. | +| [tokenCount](./ai.modalitytokencount.md#modalitytokencounttokencount) | number | The number of tokens counted. | ## ModalityTokenCount.modality diff --git a/docs-devsite/vertexai.modelparams.md b/docs-devsite/ai.modelparams.md similarity index 57% rename from docs-devsite/vertexai.modelparams.md rename to docs-devsite/ai.modelparams.md index bb8a87d5fb2..a92b2e9035d 100644 --- a/docs-devsite/vertexai.modelparams.md +++ b/docs-devsite/ai.modelparams.md @@ -10,23 +10,23 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # ModelParams interface -Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). +Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_80bd839). Signature: ```typescript export interface ModelParams extends BaseParams ``` -Extends: [BaseParams](./vertexai.baseparams.md#baseparams_interface) +Extends: [BaseParams](./ai.baseparams.md#baseparams_interface) ## Properties | Property | Type | Description | | --- | --- | --- | -| [model](./vertexai.modelparams.md#modelparamsmodel) | string | | -| [systemInstruction](./vertexai.modelparams.md#modelparamssysteminstruction) | string \| [Part](./vertexai.md#part) \| [Content](./vertexai.content.md#content_interface) | | -| [toolConfig](./vertexai.modelparams.md#modelparamstoolconfig) | [ToolConfig](./vertexai.toolconfig.md#toolconfig_interface) | | -| [tools](./vertexai.modelparams.md#modelparamstools) | [Tool](./vertexai.md#tool)\[\] | | +| [model](./ai.modelparams.md#modelparamsmodel) | string | | +| [systemInstruction](./ai.modelparams.md#modelparamssysteminstruction) | string \| [Part](./ai.md#part) \| [Content](./ai.content.md#content_interface) | | +| [toolConfig](./ai.modelparams.md#modelparamstoolconfig) | [ToolConfig](./ai.toolconfig.md#toolconfig_interface) | | +| [tools](./ai.modelparams.md#modelparamstools) | [Tool](./ai.md#tool)\[\] | | ## ModelParams.model diff --git a/docs-devsite/vertexai.numberschema.md b/docs-devsite/ai.numberschema.md similarity index 72% rename from docs-devsite/vertexai.numberschema.md rename to docs-devsite/ai.numberschema.md index 8fdd9374652..4e7800cfb21 100644 --- a/docs-devsite/vertexai.numberschema.md +++ b/docs-devsite/ai.numberschema.md @@ -17,13 +17,13 @@ Schema class for "number" types. ```typescript export declare class NumberSchema extends Schema ``` -Extends: [Schema](./vertexai.schema.md#schema_class) +Extends: [Schema](./ai.schema.md#schema_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(schemaParams)](./vertexai.numberschema.md#numberschemaconstructor) | | Constructs a new instance of the NumberSchema class | +| [(constructor)(schemaParams)](./ai.numberschema.md#numberschemaconstructor) | | Constructs a new instance of the NumberSchema class | ## NumberSchema.(constructor) @@ -39,5 +39,5 @@ constructor(schemaParams?: SchemaParams); | Parameter | Type | Description | | --- | --- | --- | -| schemaParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | +| schemaParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | diff --git a/docs-devsite/vertexai.objectschema.md b/docs-devsite/ai.objectschema.md similarity index 68% rename from docs-devsite/vertexai.objectschema.md rename to docs-devsite/ai.objectschema.md index 8731960b220..2ba358c6b07 100644 --- a/docs-devsite/vertexai.objectschema.md +++ b/docs-devsite/ai.objectschema.md @@ -17,20 +17,20 @@ Schema class for "object" types. The `properties` param must be a map of `Schema ```typescript export declare class ObjectSchema extends Schema ``` -Extends: [Schema](./vertexai.schema.md#schema_class) +Extends: [Schema](./ai.schema.md#schema_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(schemaParams, properties, optionalProperties)](./vertexai.objectschema.md#objectschemaconstructor) | | Constructs a new instance of the ObjectSchema class | +| [(constructor)(schemaParams, properties, optionalProperties)](./ai.objectschema.md#objectschemaconstructor) | | Constructs a new instance of the ObjectSchema class | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [optionalProperties](./vertexai.objectschema.md#objectschemaoptionalproperties) | | string\[\] | | -| [properties](./vertexai.objectschema.md#objectschemaproperties) | | { \[k: string\]: [TypedSchema](./vertexai.md#typedschema); } | | +| [optionalProperties](./ai.objectschema.md#objectschemaoptionalproperties) | | string\[\] | | +| [properties](./ai.objectschema.md#objectschemaproperties) | | { \[k: string\]: [TypedSchema](./ai.md#typedschema); } | | ## ObjectSchema.(constructor) @@ -48,8 +48,8 @@ constructor(schemaParams: SchemaParams, properties: { | Parameter | Type | Description | | --- | --- | --- | -| schemaParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | -| properties | { \[k: string\]: [TypedSchema](./vertexai.md#typedschema); } | | +| schemaParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | +| properties | { \[k: string\]: [TypedSchema](./ai.md#typedschema); } | | | optionalProperties | string\[\] | | ## ObjectSchema.optionalProperties diff --git a/docs-devsite/vertexai.objectschemainterface.md b/docs-devsite/ai.objectschemainterface.md similarity index 62% rename from docs-devsite/vertexai.objectschemainterface.md rename to docs-devsite/ai.objectschemainterface.md index 4eb7a5d80e7..15b1a97f40d 100644 --- a/docs-devsite/vertexai.objectschemainterface.md +++ b/docs-devsite/ai.objectschemainterface.md @@ -10,21 +10,21 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # ObjectSchemaInterface interface -Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. +Interface for [ObjectSchema](./ai.objectschema.md#objectschema_class) class. Signature: ```typescript export interface ObjectSchemaInterface extends SchemaInterface ``` -Extends: [SchemaInterface](./vertexai.schemainterface.md#schemainterface_interface) +Extends: [SchemaInterface](./ai.schemainterface.md#schemainterface_interface) ## Properties | Property | Type | Description | | --- | --- | --- | -| [optionalProperties](./vertexai.objectschemainterface.md#objectschemainterfaceoptionalproperties) | string\[\] | | -| [type](./vertexai.objectschemainterface.md#objectschemainterfacetype) | [SchemaType.OBJECT](./vertexai.md#schematypeobject_enummember) | | +| [optionalProperties](./ai.objectschemainterface.md#objectschemainterfaceoptionalproperties) | string\[\] | | +| [type](./ai.objectschemainterface.md#objectschemainterfacetype) | [SchemaType.OBJECT](./ai.md#schematypeobject_enummember) | | ## ObjectSchemaInterface.optionalProperties diff --git a/docs-devsite/vertexai.promptfeedback.md b/docs-devsite/ai.promptfeedback.md similarity index 60% rename from docs-devsite/vertexai.promptfeedback.md rename to docs-devsite/ai.promptfeedback.md index 08ea4aaf4cf..b874c0e70b1 100644 --- a/docs-devsite/vertexai.promptfeedback.md +++ b/docs-devsite/ai.promptfeedback.md @@ -22,9 +22,9 @@ export interface PromptFeedback | Property | Type | Description | | --- | --- | --- | -| [blockReason](./vertexai.promptfeedback.md#promptfeedbackblockreason) | [BlockReason](./vertexai.md#blockreason) | | -| [blockReasonMessage](./vertexai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | A human-readable description of the blockReason.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | -| [safetyRatings](./vertexai.promptfeedback.md#promptfeedbacksafetyratings) | [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface)\[\] | | +| [blockReason](./ai.promptfeedback.md#promptfeedbackblockreason) | [BlockReason](./ai.md#blockreason) | | +| [blockReasonMessage](./ai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | A human-readable description of the blockReason.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). | +| [safetyRatings](./ai.promptfeedback.md#promptfeedbacksafetyratings) | [SafetyRating](./ai.safetyrating.md#safetyrating_interface)\[\] | | ## PromptFeedback.blockReason @@ -38,7 +38,7 @@ blockReason?: BlockReason; A human-readable description of the `blockReason`. -This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). +This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). Signature: diff --git a/docs-devsite/vertexai.requestoptions.md b/docs-devsite/ai.requestoptions.md similarity index 67% rename from docs-devsite/vertexai.requestoptions.md rename to docs-devsite/ai.requestoptions.md index 3c233d72b90..73aa03c1d25 100644 --- a/docs-devsite/vertexai.requestoptions.md +++ b/docs-devsite/ai.requestoptions.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # RequestOptions interface -Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). +Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_80bd839). Signature: @@ -22,8 +22,8 @@ export interface RequestOptions | Property | Type | Description | | --- | --- | --- | -| [baseUrl](./vertexai.requestoptions.md#requestoptionsbaseurl) | string | Base url for endpoint. Defaults to https://firebasevertexai.googleapis.com | -| [timeout](./vertexai.requestoptions.md#requestoptionstimeout) | number | Request timeout in milliseconds. Defaults to 180 seconds (180000ms). | +| [baseUrl](./ai.requestoptions.md#requestoptionsbaseurl) | string | Base url for endpoint. Defaults to https://firebasevertexai.googleapis.com | +| [timeout](./ai.requestoptions.md#requestoptionstimeout) | number | Request timeout in milliseconds. Defaults to 180 seconds (180000ms). | ## RequestOptions.baseUrl diff --git a/docs-devsite/vertexai.retrievedcontextattribution.md b/docs-devsite/ai.retrievedcontextattribution.md similarity index 77% rename from docs-devsite/vertexai.retrievedcontextattribution.md rename to docs-devsite/ai.retrievedcontextattribution.md index e36bfacb3ec..21b12b79c18 100644 --- a/docs-devsite/vertexai.retrievedcontextattribution.md +++ b/docs-devsite/ai.retrievedcontextattribution.md @@ -21,8 +21,8 @@ export interface RetrievedContextAttribution | Property | Type | Description | | --- | --- | --- | -| [title](./vertexai.retrievedcontextattribution.md#retrievedcontextattributiontitle) | string | | -| [uri](./vertexai.retrievedcontextattribution.md#retrievedcontextattributionuri) | string | | +| [title](./ai.retrievedcontextattribution.md#retrievedcontextattributiontitle) | string | | +| [uri](./ai.retrievedcontextattribution.md#retrievedcontextattributionuri) | string | | ## RetrievedContextAttribution.title diff --git a/docs-devsite/ai.safetyrating.md b/docs-devsite/ai.safetyrating.md new file mode 100644 index 00000000000..86b1549569e --- /dev/null +++ b/docs-devsite/ai.safetyrating.md @@ -0,0 +1,90 @@ +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 %} + +# SafetyRating interface +A safety rating associated with a [GenerateContentCandidate](./ai.generatecontentcandidate.md#generatecontentcandidate_interface) + +Signature: + +```typescript +export interface SafetyRating +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [blocked](./ai.safetyrating.md#safetyratingblocked) | boolean | | +| [category](./ai.safetyrating.md#safetyratingcategory) | [HarmCategory](./ai.md#harmcategory) | | +| [probability](./ai.safetyrating.md#safetyratingprobability) | [HarmProbability](./ai.md#harmprobability) | | +| [probabilityScore](./ai.safetyrating.md#safetyratingprobabilityscore) | number | The probability score of the harm category.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | +| [severity](./ai.safetyrating.md#safetyratingseverity) | [HarmSeverity](./ai.md#harmseverity) | The harm severity level.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to HarmSeverity.UNSUPPORTED. | +| [severityScore](./ai.safetyrating.md#safetyratingseverityscore) | number | The severity score of the harm category.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | + +## SafetyRating.blocked + +Signature: + +```typescript +blocked: boolean; +``` + +## SafetyRating.category + +Signature: + +```typescript +category: HarmCategory; +``` + +## SafetyRating.probability + +Signature: + +```typescript +probability: HarmProbability; +``` + +## SafetyRating.probabilityScore + +The probability score of the harm category. + +This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. + +Signature: + +```typescript +probabilityScore: number; +``` + +## SafetyRating.severity + +The harm severity level. + +This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`. + +Signature: + +```typescript +severity: HarmSeverity; +``` + +## SafetyRating.severityScore + +The severity score of the harm category. + +This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. + +Signature: + +```typescript +severityScore: number; +``` diff --git a/docs-devsite/ai.safetysetting.md b/docs-devsite/ai.safetysetting.md new file mode 100644 index 00000000000..b6c770a5f60 --- /dev/null +++ b/docs-devsite/ai.safetysetting.md @@ -0,0 +1,55 @@ +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 %} + +# SafetySetting interface +Safety setting that can be sent as part of request parameters. + +Signature: + +```typescript +export interface SafetySetting +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [category](./ai.safetysetting.md#safetysettingcategory) | [HarmCategory](./ai.md#harmcategory) | | +| [method](./ai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./ai.md#harmblockmethod) | The harm block method.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), an [AIError](./ai.aierror.md#aierror_class) will be thrown if this property is defined. | +| [threshold](./ai.safetysetting.md#safetysettingthreshold) | [HarmBlockThreshold](./ai.md#harmblockthreshold) | | + +## SafetySetting.category + +Signature: + +```typescript +category: HarmCategory; +``` + +## SafetySetting.method + +The harm block method. + +This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), an [AIError](./ai.aierror.md#aierror_class) will be thrown if this property is defined. + +Signature: + +```typescript +method?: HarmBlockMethod; +``` + +## SafetySetting.threshold + +Signature: + +```typescript +threshold: HarmBlockThreshold; +``` diff --git a/docs-devsite/vertexai.schema.md b/docs-devsite/ai.schema.md similarity index 53% rename from docs-devsite/vertexai.schema.md rename to docs-devsite/ai.schema.md index f4a36c3c506..b0681b0cdf3 100644 --- a/docs-devsite/vertexai.schema.md +++ b/docs-devsite/ai.schema.md @@ -17,35 +17,35 @@ Parent class encompassing all Schema types, with static methods that allow build ```typescript export declare abstract class Schema implements SchemaInterface ``` -Implements: [SchemaInterface](./vertexai.schemainterface.md#schemainterface_interface) +Implements: [SchemaInterface](./ai.schemainterface.md#schemainterface_interface) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(schemaParams)](./vertexai.schema.md#schemaconstructor) | | Constructs a new instance of the Schema class | +| [(constructor)(schemaParams)](./ai.schema.md#schemaconstructor) | | Constructs a new instance of the Schema class | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [description](./vertexai.schema.md#schemadescription) | | string | Optional. The description of the property. | -| [example](./vertexai.schema.md#schemaexample) | | unknown | Optional. The example of the property. | -| [format](./vertexai.schema.md#schemaformat) | | string | Optional. The format of the property. Supported formats:
  • for NUMBER type: "float", "double"
  • for INTEGER type: "int32", "int64"
  • for STRING type: "email", "byte", etc
| -| [nullable](./vertexai.schema.md#schemanullable) | | boolean | Optional. Whether the property is nullable. Defaults to false. | -| [type](./vertexai.schema.md#schematype) | | [SchemaType](./vertexai.md#schematype) | Optional. The type of the property. [SchemaType](./vertexai.md#schematype). | +| [description](./ai.schema.md#schemadescription) | | string | Optional. The description of the property. | +| [example](./ai.schema.md#schemaexample) | | unknown | Optional. The example of the property. | +| [format](./ai.schema.md#schemaformat) | | string | Optional. The format of the property. Supported formats:
  • for NUMBER type: "float", "double"
  • for INTEGER type: "int32", "int64"
  • for STRING type: "email", "byte", etc
| +| [nullable](./ai.schema.md#schemanullable) | | boolean | Optional. Whether the property is nullable. Defaults to false. | +| [type](./ai.schema.md#schematype) | | [SchemaType](./ai.md#schematype) | Optional. The type of the property. [SchemaType](./ai.md#schematype). | ## Methods | Method | Modifiers | Description | | --- | --- | --- | -| [array(arrayParams)](./vertexai.schema.md#schemaarray) | static | | -| [boolean(booleanParams)](./vertexai.schema.md#schemaboolean) | static | | -| [enumString(stringParams)](./vertexai.schema.md#schemaenumstring) | static | | -| [integer(integerParams)](./vertexai.schema.md#schemainteger) | static | | -| [number(numberParams)](./vertexai.schema.md#schemanumber) | static | | -| [object(objectParams)](./vertexai.schema.md#schemaobject) | static | | -| [string(stringParams)](./vertexai.schema.md#schemastring) | static | | +| [array(arrayParams)](./ai.schema.md#schemaarray) | static | | +| [boolean(booleanParams)](./ai.schema.md#schemaboolean) | static | | +| [enumString(stringParams)](./ai.schema.md#schemaenumstring) | static | | +| [integer(integerParams)](./ai.schema.md#schemainteger) | static | | +| [number(numberParams)](./ai.schema.md#schemanumber) | static | | +| [object(objectParams)](./ai.schema.md#schemaobject) | static | | +| [string(stringParams)](./ai.schema.md#schemastring) | static | | ## Schema.(constructor) @@ -61,7 +61,7 @@ constructor(schemaParams: SchemaInterface); | Parameter | Type | Description | | --- | --- | --- | -| schemaParams | [SchemaInterface](./vertexai.schemainterface.md#schemainterface_interface) | | +| schemaParams | [SchemaInterface](./ai.schemainterface.md#schemainterface_interface) | | ## Schema.description @@ -105,7 +105,7 @@ nullable: boolean; ## Schema.type -Optional. The type of the property. [SchemaType](./vertexai.md#schematype). +Optional. The type of the property. [SchemaType](./ai.md#schematype). Signature: @@ -127,11 +127,11 @@ static array(arrayParams: SchemaParams & { | Parameter | Type | Description | | --- | --- | --- | -| arrayParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) & { items: [Schema](./vertexai.schema.md#schema_class); } | | +| arrayParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) & { items: [Schema](./ai.schema.md#schema_class); } | | Returns: -[ArraySchema](./vertexai.arrayschema.md#arrayschema_class) +[ArraySchema](./ai.arrayschema.md#arrayschema_class) ## Schema.boolean() @@ -145,11 +145,11 @@ static boolean(booleanParams?: SchemaParams): BooleanSchema; | Parameter | Type | Description | | --- | --- | --- | -| booleanParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | +| booleanParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | Returns: -[BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) +[BooleanSchema](./ai.booleanschema.md#booleanschema_class) ## Schema.enumString() @@ -165,11 +165,11 @@ static enumString(stringParams: SchemaParams & { | Parameter | Type | Description | | --- | --- | --- | -| stringParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) & { enum: string\[\]; } | | +| stringParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) & { enum: string\[\]; } | | Returns: -[StringSchema](./vertexai.stringschema.md#stringschema_class) +[StringSchema](./ai.stringschema.md#stringschema_class) ## Schema.integer() @@ -183,11 +183,11 @@ static integer(integerParams?: SchemaParams): IntegerSchema; | Parameter | Type | Description | | --- | --- | --- | -| integerParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | +| integerParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | Returns: -[IntegerSchema](./vertexai.integerschema.md#integerschema_class) +[IntegerSchema](./ai.integerschema.md#integerschema_class) ## Schema.number() @@ -201,11 +201,11 @@ static number(numberParams?: SchemaParams): NumberSchema; | Parameter | Type | Description | | --- | --- | --- | -| numberParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | +| numberParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | Returns: -[NumberSchema](./vertexai.numberschema.md#numberschema_class) +[NumberSchema](./ai.numberschema.md#numberschema_class) ## Schema.object() @@ -224,11 +224,11 @@ static object(objectParams: SchemaParams & { | Parameter | Type | Description | | --- | --- | --- | -| objectParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) & { properties: { \[k: string\]: [Schema](./vertexai.schema.md#schema_class); }; optionalProperties?: string\[\]; } | | +| objectParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) & { properties: { \[k: string\]: [Schema](./ai.schema.md#schema_class); }; optionalProperties?: string\[\]; } | | Returns: -[ObjectSchema](./vertexai.objectschema.md#objectschema_class) +[ObjectSchema](./ai.objectschema.md#objectschema_class) ## Schema.string() @@ -242,9 +242,9 @@ static string(stringParams?: SchemaParams): StringSchema; | Parameter | Type | Description | | --- | --- | --- | -| stringParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | +| stringParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | Returns: -[StringSchema](./vertexai.stringschema.md#stringschema_class) +[StringSchema](./ai.stringschema.md#stringschema_class) diff --git a/docs-devsite/vertexai.schemainterface.md b/docs-devsite/ai.schemainterface.md similarity index 55% rename from docs-devsite/vertexai.schemainterface.md rename to docs-devsite/ai.schemainterface.md index c14b561193b..6dd33e69e18 100644 --- a/docs-devsite/vertexai.schemainterface.md +++ b/docs-devsite/ai.schemainterface.md @@ -10,24 +10,24 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # SchemaInterface interface -Interface for [Schema](./vertexai.schema.md#schema_class) class. +Interface for [Schema](./ai.schema.md#schema_class) class. Signature: ```typescript export interface SchemaInterface extends SchemaShared ``` -Extends: [SchemaShared](./vertexai.schemashared.md#schemashared_interface)<[SchemaInterface](./vertexai.schemainterface.md#schemainterface_interface)> +Extends: [SchemaShared](./ai.schemashared.md#schemashared_interface)<[SchemaInterface](./ai.schemainterface.md#schemainterface_interface)> ## Properties | Property | Type | Description | | --- | --- | --- | -| [type](./vertexai.schemainterface.md#schemainterfacetype) | [SchemaType](./vertexai.md#schematype) | The type of the property. [SchemaType](./vertexai.md#schematype). | +| [type](./ai.schemainterface.md#schemainterfacetype) | [SchemaType](./ai.md#schematype) | The type of the property. [SchemaType](./ai.md#schematype). | ## SchemaInterface.type -The type of the property. [SchemaType](./vertexai.md#schematype). +The type of the property. [SchemaType](./ai.md#schematype). Signature: diff --git a/docs-devsite/vertexai.schemaparams.md b/docs-devsite/ai.schemaparams.md similarity index 58% rename from docs-devsite/vertexai.schemaparams.md rename to docs-devsite/ai.schemaparams.md index 8e4a41f6bdc..3f9626306c2 100644 --- a/docs-devsite/vertexai.schemaparams.md +++ b/docs-devsite/ai.schemaparams.md @@ -10,12 +10,12 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # SchemaParams interface -Params passed to [Schema](./vertexai.schema.md#schema_class) static methods to create specific [Schema](./vertexai.schema.md#schema_class) classes. +Params passed to [Schema](./ai.schema.md#schema_class) static methods to create specific [Schema](./ai.schema.md#schema_class) classes. Signature: ```typescript export interface SchemaParams extends SchemaShared ``` -Extends: [SchemaShared](./vertexai.schemashared.md#schemashared_interface)<[SchemaInterface](./vertexai.schemainterface.md#schemainterface_interface)> +Extends: [SchemaShared](./ai.schemashared.md#schemashared_interface)<[SchemaInterface](./ai.schemainterface.md#schemainterface_interface)> diff --git a/docs-devsite/vertexai.schemarequest.md b/docs-devsite/ai.schemarequest.md similarity index 53% rename from docs-devsite/vertexai.schemarequest.md rename to docs-devsite/ai.schemarequest.md index c382c2a6297..e71d24a6b1a 100644 --- a/docs-devsite/vertexai.schemarequest.md +++ b/docs-devsite/ai.schemarequest.md @@ -10,21 +10,21 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # SchemaRequest interface -Final format for [Schema](./vertexai.schema.md#schema_class) params passed to backend requests. +Final format for [Schema](./ai.schema.md#schema_class) params passed to backend requests. Signature: ```typescript export interface SchemaRequest extends SchemaShared ``` -Extends: [SchemaShared](./vertexai.schemashared.md#schemashared_interface)<[SchemaRequest](./vertexai.schemarequest.md#schemarequest_interface)> +Extends: [SchemaShared](./ai.schemashared.md#schemashared_interface)<[SchemaRequest](./ai.schemarequest.md#schemarequest_interface)> ## Properties | Property | Type | Description | | --- | --- | --- | -| [required](./vertexai.schemarequest.md#schemarequestrequired) | string\[\] | Optional. Array of required property. | -| [type](./vertexai.schemarequest.md#schemarequesttype) | [SchemaType](./vertexai.md#schematype) | The type of the property. [SchemaType](./vertexai.md#schematype). | +| [required](./ai.schemarequest.md#schemarequestrequired) | string\[\] | Optional. Array of required property. | +| [type](./ai.schemarequest.md#schemarequesttype) | [SchemaType](./ai.md#schematype) | The type of the property. [SchemaType](./ai.md#schematype). | ## SchemaRequest.required @@ -38,7 +38,7 @@ required?: string[]; ## SchemaRequest.type -The type of the property. [SchemaType](./vertexai.md#schematype). +The type of the property. [SchemaType](./ai.md#schematype). Signature: diff --git a/docs-devsite/vertexai.schemashared.md b/docs-devsite/ai.schemashared.md similarity index 51% rename from docs-devsite/vertexai.schemashared.md rename to docs-devsite/ai.schemashared.md index 4fdf8941438..eba57f82935 100644 --- a/docs-devsite/vertexai.schemashared.md +++ b/docs-devsite/ai.schemashared.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # SchemaShared interface -Basic [Schema](./vertexai.schema.md#schema_class) properties shared across several Schema-related types. +Basic [Schema](./ai.schema.md#schema_class) properties shared across several Schema-related types. Signature: @@ -22,13 +22,13 @@ export interface SchemaShared | Property | Type | Description | | --- | --- | --- | -| [description](./vertexai.schemashared.md#schemashareddescription) | string | Optional. The description of the property. | -| [enum](./vertexai.schemashared.md#schemasharedenum) | string\[\] | Optional. The enum of the property. | -| [example](./vertexai.schemashared.md#schemasharedexample) | unknown | Optional. The example of the property. | -| [format](./vertexai.schemashared.md#schemasharedformat) | string | Optional. The format of the property. When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this must be either 'enum' or 'date-time', otherwise requests will fail. | -| [items](./vertexai.schemashared.md#schemashareditems) | T | Optional. The items of the property. | -| [nullable](./vertexai.schemashared.md#schemasharednullable) | boolean | Optional. Whether the property is nullable. | -| [properties](./vertexai.schemashared.md#schemasharedproperties) | { \[k: string\]: T; } | Optional. Map of Schema objects. | +| [description](./ai.schemashared.md#schemashareddescription) | string | Optional. The description of the property. | +| [enum](./ai.schemashared.md#schemasharedenum) | string\[\] | Optional. The enum of the property. | +| [example](./ai.schemashared.md#schemasharedexample) | unknown | Optional. The example of the property. | +| [format](./ai.schemashared.md#schemasharedformat) | string | Optional. The format of the property. When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this must be either 'enum' or 'date-time', otherwise requests will fail. | +| [items](./ai.schemashared.md#schemashareditems) | T | Optional. The items of the property. | +| [nullable](./ai.schemashared.md#schemasharednullable) | boolean | Optional. Whether the property is nullable. | +| [properties](./ai.schemashared.md#schemasharedproperties) | { \[k: string\]: T; } | Optional. Map of Schema objects. | ## SchemaShared.description @@ -62,7 +62,7 @@ example?: unknown; ## SchemaShared.format -Optional. The format of the property. When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this must be either `'enum'` or `'date-time'`, otherwise requests will fail. +Optional. The format of the property. When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)), this must be either `'enum'` or `'date-time'`, otherwise requests will fail. Signature: diff --git a/docs-devsite/vertexai.segment.md b/docs-devsite/ai.segment.md similarity index 77% rename from docs-devsite/vertexai.segment.md rename to docs-devsite/ai.segment.md index db61f00a149..69f4aaf8407 100644 --- a/docs-devsite/vertexai.segment.md +++ b/docs-devsite/ai.segment.md @@ -21,9 +21,9 @@ export interface Segment | Property | Type | Description | | --- | --- | --- | -| [endIndex](./vertexai.segment.md#segmentendindex) | number | | -| [partIndex](./vertexai.segment.md#segmentpartindex) | number | | -| [startIndex](./vertexai.segment.md#segmentstartindex) | number | | +| [endIndex](./ai.segment.md#segmentendindex) | number | | +| [partIndex](./ai.segment.md#segmentpartindex) | number | | +| [startIndex](./ai.segment.md#segmentstartindex) | number | | ## Segment.endIndex diff --git a/docs-devsite/vertexai.startchatparams.md b/docs-devsite/ai.startchatparams.md similarity index 54% rename from docs-devsite/vertexai.startchatparams.md rename to docs-devsite/ai.startchatparams.md index e07bbd91d82..2d039bbe868 100644 --- a/docs-devsite/vertexai.startchatparams.md +++ b/docs-devsite/ai.startchatparams.md @@ -10,23 +10,23 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # StartChatParams interface -Params for [GenerativeModel.startChat()](./vertexai.generativemodel.md#generativemodelstartchat). +Params for [GenerativeModel.startChat()](./ai.generativemodel.md#generativemodelstartchat). Signature: ```typescript export interface StartChatParams extends BaseParams ``` -Extends: [BaseParams](./vertexai.baseparams.md#baseparams_interface) +Extends: [BaseParams](./ai.baseparams.md#baseparams_interface) ## Properties | Property | Type | Description | | --- | --- | --- | -| [history](./vertexai.startchatparams.md#startchatparamshistory) | [Content](./vertexai.content.md#content_interface)\[\] | | -| [systemInstruction](./vertexai.startchatparams.md#startchatparamssysteminstruction) | string \| [Part](./vertexai.md#part) \| [Content](./vertexai.content.md#content_interface) | | -| [toolConfig](./vertexai.startchatparams.md#startchatparamstoolconfig) | [ToolConfig](./vertexai.toolconfig.md#toolconfig_interface) | | -| [tools](./vertexai.startchatparams.md#startchatparamstools) | [Tool](./vertexai.md#tool)\[\] | | +| [history](./ai.startchatparams.md#startchatparamshistory) | [Content](./ai.content.md#content_interface)\[\] | | +| [systemInstruction](./ai.startchatparams.md#startchatparamssysteminstruction) | string \| [Part](./ai.md#part) \| [Content](./ai.content.md#content_interface) | | +| [toolConfig](./ai.startchatparams.md#startchatparamstoolconfig) | [ToolConfig](./ai.toolconfig.md#toolconfig_interface) | | +| [tools](./ai.startchatparams.md#startchatparamstools) | [Tool](./ai.md#tool)\[\] | | ## StartChatParams.history diff --git a/docs-devsite/vertexai.stringschema.md b/docs-devsite/ai.stringschema.md similarity index 72% rename from docs-devsite/vertexai.stringschema.md rename to docs-devsite/ai.stringschema.md index bfafe0fe9df..c3ab8f13a6f 100644 --- a/docs-devsite/vertexai.stringschema.md +++ b/docs-devsite/ai.stringschema.md @@ -17,19 +17,19 @@ Schema class for "string" types. Can be used with or without enum values. ```typescript export declare class StringSchema extends Schema ``` -Extends: [Schema](./vertexai.schema.md#schema_class) +Extends: [Schema](./ai.schema.md#schema_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(schemaParams, enumValues)](./vertexai.stringschema.md#stringschemaconstructor) | | Constructs a new instance of the StringSchema class | +| [(constructor)(schemaParams, enumValues)](./ai.stringschema.md#stringschemaconstructor) | | Constructs a new instance of the StringSchema class | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [enum](./vertexai.stringschema.md#stringschemaenum) | | string\[\] | | +| [enum](./ai.stringschema.md#stringschemaenum) | | string\[\] | | ## StringSchema.(constructor) @@ -45,7 +45,7 @@ constructor(schemaParams?: SchemaParams, enumValues?: string[]); | Parameter | Type | Description | | --- | --- | --- | -| schemaParams | [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | | +| schemaParams | [SchemaParams](./ai.schemaparams.md#schemaparams_interface) | | | enumValues | string\[\] | | ## StringSchema.enum diff --git a/docs-devsite/vertexai.textpart.md b/docs-devsite/ai.textpart.md similarity index 74% rename from docs-devsite/vertexai.textpart.md rename to docs-devsite/ai.textpart.md index afee40a369d..2057d95d32e 100644 --- a/docs-devsite/vertexai.textpart.md +++ b/docs-devsite/ai.textpart.md @@ -22,10 +22,10 @@ export interface TextPart | Property | Type | Description | | --- | --- | --- | -| [functionCall](./vertexai.textpart.md#textpartfunctioncall) | never | | -| [functionResponse](./vertexai.textpart.md#textpartfunctionresponse) | never | | -| [inlineData](./vertexai.textpart.md#textpartinlinedata) | never | | -| [text](./vertexai.textpart.md#textparttext) | string | | +| [functionCall](./ai.textpart.md#textpartfunctioncall) | never | | +| [functionResponse](./ai.textpart.md#textpartfunctionresponse) | never | | +| [inlineData](./ai.textpart.md#textpartinlinedata) | never | | +| [text](./ai.textpart.md#textparttext) | string | | ## TextPart.functionCall diff --git a/docs-devsite/vertexai.toolconfig.md b/docs-devsite/ai.toolconfig.md similarity index 78% rename from docs-devsite/vertexai.toolconfig.md rename to docs-devsite/ai.toolconfig.md index 30c62c17c01..81bd6ccd8fc 100644 --- a/docs-devsite/vertexai.toolconfig.md +++ b/docs-devsite/ai.toolconfig.md @@ -22,7 +22,7 @@ export interface ToolConfig | Property | Type | Description | | --- | --- | --- | -| [functionCallingConfig](./vertexai.toolconfig.md#toolconfigfunctioncallingconfig) | [FunctionCallingConfig](./vertexai.functioncallingconfig.md#functioncallingconfig_interface) | | +| [functionCallingConfig](./ai.toolconfig.md#toolconfigfunctioncallingconfig) | [FunctionCallingConfig](./ai.functioncallingconfig.md#functioncallingconfig_interface) | | ## ToolConfig.functionCallingConfig diff --git a/docs-devsite/vertexai.usagemetadata.md b/docs-devsite/ai.usagemetadata.md similarity index 56% rename from docs-devsite/vertexai.usagemetadata.md rename to docs-devsite/ai.usagemetadata.md index 176878235d5..4211fea72b4 100644 --- a/docs-devsite/vertexai.usagemetadata.md +++ b/docs-devsite/ai.usagemetadata.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # UsageMetadata interface -Usage metadata about a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). +Usage metadata about a [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface). Signature: @@ -22,11 +22,11 @@ export interface UsageMetadata | Property | Type | Description | | --- | --- | --- | -| [candidatesTokenCount](./vertexai.usagemetadata.md#usagemetadatacandidatestokencount) | number | | -| [candidatesTokensDetails](./vertexai.usagemetadata.md#usagemetadatacandidatestokensdetails) | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface)\[\] | | -| [promptTokenCount](./vertexai.usagemetadata.md#usagemetadataprompttokencount) | number | | -| [promptTokensDetails](./vertexai.usagemetadata.md#usagemetadataprompttokensdetails) | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface)\[\] | | -| [totalTokenCount](./vertexai.usagemetadata.md#usagemetadatatotaltokencount) | number | | +| [candidatesTokenCount](./ai.usagemetadata.md#usagemetadatacandidatestokencount) | number | | +| [candidatesTokensDetails](./ai.usagemetadata.md#usagemetadatacandidatestokensdetails) | [ModalityTokenCount](./ai.modalitytokencount.md#modalitytokencount_interface)\[\] | | +| [promptTokenCount](./ai.usagemetadata.md#usagemetadataprompttokencount) | number | | +| [promptTokensDetails](./ai.usagemetadata.md#usagemetadataprompttokensdetails) | [ModalityTokenCount](./ai.modalitytokencount.md#modalitytokencount_interface)\[\] | | +| [totalTokenCount](./ai.usagemetadata.md#usagemetadatatotaltokencount) | number | | ## UsageMetadata.candidatesTokenCount diff --git a/docs-devsite/vertexai.vertexaibackend.md b/docs-devsite/ai.vertexaibackend.md similarity index 67% rename from docs-devsite/vertexai.vertexaibackend.md rename to docs-devsite/ai.vertexaibackend.md index ba82c775ca8..88424b75c45 100644 --- a/docs-devsite/vertexai.vertexaibackend.md +++ b/docs-devsite/ai.vertexaibackend.md @@ -12,26 +12,26 @@ https://github.com/firebase/firebase-js-sdk # VertexAIBackend class Configuration class for the Vertex AI Gemini API. -Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. +Use this with [AIOptions](./ai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./ai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. Signature: ```typescript export declare class VertexAIBackend extends Backend ``` -Extends: [Backend](./vertexai.backend.md#backend_class) +Extends: [Backend](./ai.backend.md#backend_class) ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(location)](./vertexai.vertexaibackend.md#vertexaibackendconstructor) | | Creates a configuration object for the Vertex AI backend. | +| [(constructor)(location)](./ai.vertexaibackend.md#vertexaibackendconstructor) | | Creates a configuration object for the Vertex AI backend. | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [location](./vertexai.vertexaibackend.md#vertexaibackendlocation) | | string | The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations#available-locations) for a list of supported locations. | +| [location](./ai.vertexaibackend.md#vertexaibackendlocation) | | string | The region identifier. See [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations#available-locations) for a list of supported locations. | ## VertexAIBackend.(constructor) diff --git a/docs-devsite/vertexai.vertexaioptions.md b/docs-devsite/ai.vertexaioptions.md similarity index 88% rename from docs-devsite/vertexai.vertexaioptions.md rename to docs-devsite/ai.vertexaioptions.md index 776dfd29374..311fa4785f7 100644 --- a/docs-devsite/vertexai.vertexaioptions.md +++ b/docs-devsite/ai.vertexaioptions.md @@ -22,7 +22,7 @@ export interface VertexAIOptions | Property | Type | Description | | --- | --- | --- | -| [location](./vertexai.vertexaioptions.md#vertexaioptionslocation) | string | | +| [location](./ai.vertexaioptions.md#vertexaioptionslocation) | string | | ## VertexAIOptions.location diff --git a/docs-devsite/vertexai.videometadata.md b/docs-devsite/ai.videometadata.md similarity index 75% rename from docs-devsite/vertexai.videometadata.md rename to docs-devsite/ai.videometadata.md index b4f872c4e3d..d63447837be 100644 --- a/docs-devsite/vertexai.videometadata.md +++ b/docs-devsite/ai.videometadata.md @@ -22,8 +22,8 @@ export interface VideoMetadata | Property | Type | Description | | --- | --- | --- | -| [endOffset](./vertexai.videometadata.md#videometadataendoffset) | string | The end offset of the video in protobuf [Duration](https://cloud.google.com/ruby/docs/reference/google-cloud-workflows-v1/latest/Google-Protobuf-Duration#json-mapping) format. | -| [startOffset](./vertexai.videometadata.md#videometadatastartoffset) | string | The start offset of the video in protobuf [Duration](https://cloud.google.com/ruby/docs/reference/google-cloud-workflows-v1/latest/Google-Protobuf-Duration#json-mapping) format. | +| [endOffset](./ai.videometadata.md#videometadataendoffset) | string | The end offset of the video in protobuf [Duration](https://cloud.google.com/ruby/docs/reference/google-cloud-workflows-v1/latest/Google-Protobuf-Duration#json-mapping) format. | +| [startOffset](./ai.videometadata.md#videometadatastartoffset) | string | The start offset of the video in protobuf [Duration](https://cloud.google.com/ruby/docs/reference/google-cloud-workflows-v1/latest/Google-Protobuf-Duration#json-mapping) format. | ## VideoMetadata.endOffset diff --git a/docs-devsite/vertexai.webattribution.md b/docs-devsite/ai.webattribution.md similarity index 81% rename from docs-devsite/vertexai.webattribution.md rename to docs-devsite/ai.webattribution.md index bb4fecf874d..2040d9eb82a 100644 --- a/docs-devsite/vertexai.webattribution.md +++ b/docs-devsite/ai.webattribution.md @@ -21,8 +21,8 @@ export interface WebAttribution | Property | Type | Description | | --- | --- | --- | -| [title](./vertexai.webattribution.md#webattributiontitle) | string | | -| [uri](./vertexai.webattribution.md#webattributionuri) | string | | +| [title](./ai.webattribution.md#webattributiontitle) | string | | +| [uri](./ai.webattribution.md#webattributionuri) | string | | ## WebAttribution.title diff --git a/docs-devsite/index.md b/docs-devsite/index.md index af34d0d0250..47ec0be16ba 100644 --- a/docs-devsite/index.md +++ b/docs-devsite/index.md @@ -15,6 +15,7 @@ https://github.com/firebase/firebase-js-sdk | Package | Description | | --- | --- | +| [@firebase/ai](./ai.md#ai_package) | The Firebase AI Web SDK. | | [@firebase/analytics](./analytics.md#analytics_package) | The Firebase Analytics Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/app](./app.md#app_package) | Firebase App | | [@firebase/app-check](./app-check.md#app-check_package) | The Firebase App Check Web SDK. | @@ -27,5 +28,4 @@ https://github.com/firebase/firebase-js-sdk | [@firebase/performance](./performance.md#performance_package) | The Firebase Performance Monitoring Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/remote-config](./remote-config.md#remote-config_package) | The Firebase Remote Config Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/storage](./storage.md#storage_package) | Cloud Storage for Firebase | -| [@firebase/vertexai](./vertexai.md#vertexai_package) | The Firebase AI Web SDK. | diff --git a/docs-devsite/vertexai.ai.md b/docs-devsite/vertexai.ai.md deleted file mode 100644 index 661bf0b4fe3..00000000000 --- a/docs-devsite/vertexai.ai.md +++ /dev/null @@ -1,64 +0,0 @@ -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 %} - -# AI interface -An instance of the Firebase AI SDK. - -Do not create this instance directly. Instead, use [getAI()](./vertexai.md#getai_a94a413). - -Signature: - -```typescript -export interface AI -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [app](./vertexai.ai.md#aiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./vertexai.ai.md#ai_interface) instance is associated with. | -| [backend](./vertexai.ai.md#aibackend) | [Backend](./vertexai.backend.md#backend_class) | A [Backend](./vertexai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) or the Vertex AI Gemini API (using [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). | -| [location](./vertexai.ai.md#ailocation) | string | The location configured for this AI service instance, relevant for Vertex AI backends. | - -## AI.app - -The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./vertexai.ai.md#ai_interface) instance is associated with. - -Signature: - -```typescript -app: FirebaseApp; -``` - -## AI.backend - -A [Backend](./vertexai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)) or the Vertex AI Gemini API (using [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). - -Signature: - -```typescript -backend: Backend; -``` - -## AI.location - -> Warning: This API is now obsolete. -> -> use `AI.backend.location` instead. -> - -The location configured for this AI service instance, relevant for Vertex AI backends. - -Signature: - -```typescript -location: string; -``` diff --git a/docs-devsite/vertexai.counttokensresponse.md b/docs-devsite/vertexai.counttokensresponse.md deleted file mode 100644 index b304ccb82a0..00000000000 --- a/docs-devsite/vertexai.counttokensresponse.md +++ /dev/null @@ -1,59 +0,0 @@ -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 %} - -# CountTokensResponse interface -Response from calling [GenerativeModel.countTokens()](./vertexai.generativemodel.md#generativemodelcounttokens). - -Signature: - -```typescript -export interface CountTokensResponse -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [promptTokensDetails](./vertexai.counttokensresponse.md#counttokensresponseprompttokensdetails) | [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface)\[\] | The breakdown, by modality, of how many tokens are consumed by the prompt. | -| [totalBillableCharacters](./vertexai.counttokensresponse.md#counttokensresponsetotalbillablecharacters) | number | The total number of billable characters counted across all instances from the request.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | -| [totalTokens](./vertexai.counttokensresponse.md#counttokensresponsetotaltokens) | number | The total number of tokens counted across all instances from the request. | - -## CountTokensResponse.promptTokensDetails - -The breakdown, by modality, of how many tokens are consumed by the prompt. - -Signature: - -```typescript -promptTokensDetails?: ModalityTokenCount[]; -``` - -## CountTokensResponse.totalBillableCharacters - -The total number of billable characters counted across all instances from the request. - -This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. - -Signature: - -```typescript -totalBillableCharacters?: number; -``` - -## CountTokensResponse.totalTokens - -The total number of tokens counted across all instances from the request. - -Signature: - -```typescript -totalTokens: number; -``` diff --git a/docs-devsite/vertexai.enhancedgeneratecontentresponse.md b/docs-devsite/vertexai.enhancedgeneratecontentresponse.md deleted file mode 100644 index b557219bf84..00000000000 --- a/docs-devsite/vertexai.enhancedgeneratecontentresponse.md +++ /dev/null @@ -1,56 +0,0 @@ -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 %} - -# EnhancedGenerateContentResponse interface -Response object wrapped with helper methods. - -Signature: - -```typescript -export interface EnhancedGenerateContentResponse extends GenerateContentResponse -``` -Extends: [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface) - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [functionCalls](./vertexai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponsefunctioncalls) | () => [FunctionCall](./vertexai.functioncall.md#functioncall_interface)\[\] \| undefined | | -| [inlineDataParts](./vertexai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponseinlinedataparts) | () => [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface)\[\] \| undefined | Aggregates and returns all [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface)s from the [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface)'s first candidate. | -| [text](./vertexai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponsetext) | () => string | Returns the text string from the response, if available. Throws if the prompt or candidate was blocked. | - -## EnhancedGenerateContentResponse.functionCalls - -Signature: - -```typescript -functionCalls: () => FunctionCall[] | undefined; -``` - -## EnhancedGenerateContentResponse.inlineDataParts - -Aggregates and returns all [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface)s from the [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface)'s first candidate. - -Signature: - -```typescript -inlineDataParts: () => InlineDataPart[] | undefined; -``` - -## EnhancedGenerateContentResponse.text - -Returns the text string from the response, if available. Throws if the prompt or candidate was blocked. - -Signature: - -```typescript -text: () => string; -``` diff --git a/docs-devsite/vertexai.functiondeclarationstool.md b/docs-devsite/vertexai.functiondeclarationstool.md deleted file mode 100644 index 2eff3138d8d..00000000000 --- a/docs-devsite/vertexai.functiondeclarationstool.md +++ /dev/null @@ -1,35 +0,0 @@ -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 %} - -# FunctionDeclarationsTool interface -A `FunctionDeclarationsTool` is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. - -Signature: - -```typescript -export declare interface FunctionDeclarationsTool -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [functionDeclarations](./vertexai.functiondeclarationstool.md#functiondeclarationstoolfunctiondeclarations) | [FunctionDeclaration](./vertexai.functiondeclaration.md#functiondeclaration_interface)\[\] | Optional. One or more function declarations to be passed to the model along with the current user query. Model may decide to call a subset of these functions by populating [FunctionCall](./vertexai.functioncall.md#functioncall_interface) in the response. User should provide a [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface) for each function call in the next turn. Based on the function responses, the model will generate the final response back to the user. Maximum 64 function declarations can be provided. | - -## FunctionDeclarationsTool.functionDeclarations - -Optional. One or more function declarations to be passed to the model along with the current user query. Model may decide to call a subset of these functions by populating [FunctionCall](./vertexai.functioncall.md#functioncall_interface) in the response. User should provide a [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface) for each function call in the next turn. Based on the function responses, the model will generate the final response back to the user. Maximum 64 function declarations can be provided. - -Signature: - -```typescript -functionDeclarations?: FunctionDeclaration[]; -``` diff --git a/docs-devsite/vertexai.generatecontentresponse.md b/docs-devsite/vertexai.generatecontentresponse.md deleted file mode 100644 index 304674c9b6f..00000000000 --- a/docs-devsite/vertexai.generatecontentresponse.md +++ /dev/null @@ -1,51 +0,0 @@ -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 %} - -# GenerateContentResponse interface -Individual response from [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) and [GenerativeModel.generateContentStream()](./vertexai.generativemodel.md#generativemodelgeneratecontentstream). `generateContentStream()` will return one in each chunk until the stream is done. - -Signature: - -```typescript -export interface GenerateContentResponse -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [candidates](./vertexai.generatecontentresponse.md#generatecontentresponsecandidates) | [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface)\[\] | | -| [promptFeedback](./vertexai.generatecontentresponse.md#generatecontentresponsepromptfeedback) | [PromptFeedback](./vertexai.promptfeedback.md#promptfeedback_interface) | | -| [usageMetadata](./vertexai.generatecontentresponse.md#generatecontentresponseusagemetadata) | [UsageMetadata](./vertexai.usagemetadata.md#usagemetadata_interface) | | - -## GenerateContentResponse.candidates - -Signature: - -```typescript -candidates?: GenerateContentCandidate[]; -``` - -## GenerateContentResponse.promptFeedback - -Signature: - -```typescript -promptFeedback?: PromptFeedback; -``` - -## GenerateContentResponse.usageMetadata - -Signature: - -```typescript -usageMetadata?: UsageMetadata; -``` diff --git a/docs-devsite/vertexai.generationconfig.md b/docs-devsite/vertexai.generationconfig.md deleted file mode 100644 index 360ef709419..00000000000 --- a/docs-devsite/vertexai.generationconfig.md +++ /dev/null @@ -1,134 +0,0 @@ -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 %} - -# GenerationConfig interface -Config options for content-related requests - -Signature: - -```typescript -export interface GenerationConfig -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [candidateCount](./vertexai.generationconfig.md#generationconfigcandidatecount) | number | | -| [frequencyPenalty](./vertexai.generationconfig.md#generationconfigfrequencypenalty) | number | | -| [maxOutputTokens](./vertexai.generationconfig.md#generationconfigmaxoutputtokens) | number | | -| [presencePenalty](./vertexai.generationconfig.md#generationconfigpresencepenalty) | number | | -| [responseMimeType](./vertexai.generationconfig.md#generationconfigresponsemimetype) | string | Output response MIME type of the generated candidate text. Supported MIME types are text/plain (default, text output), application/json (JSON response in the candidates), and text/x.enum. | -| [responseModalities](./vertexai.generationconfig.md#generationconfigresponsemodalities) | [ResponseModality](./vertexai.md#responsemodality)\[\] | (Public Preview) Generation modalities to be returned in generation responses. | -| [responseSchema](./vertexai.generationconfig.md#generationconfigresponseschema) | [TypedSchema](./vertexai.md#typedschema) \| [SchemaRequest](./vertexai.schemarequest.md#schemarequest_interface) | Output response schema of the generated candidate text. This value can be a class generated with a [Schema](./vertexai.schema.md#schema_class) static method like Schema.string() or Schema.object() or it can be a plain JS object matching the [SchemaRequest](./vertexai.schemarequest.md#schemarequest_interface) interface.
Note: This only applies when the specified responseMIMEType supports a schema; currently this is limited to application/json and text/x.enum. | -| [stopSequences](./vertexai.generationconfig.md#generationconfigstopsequences) | string\[\] | | -| [temperature](./vertexai.generationconfig.md#generationconfigtemperature) | number | | -| [topK](./vertexai.generationconfig.md#generationconfigtopk) | number | | -| [topP](./vertexai.generationconfig.md#generationconfigtopp) | number | | - -## GenerationConfig.candidateCount - -Signature: - -```typescript -candidateCount?: number; -``` - -## GenerationConfig.frequencyPenalty - -Signature: - -```typescript -frequencyPenalty?: number; -``` - -## GenerationConfig.maxOutputTokens - -Signature: - -```typescript -maxOutputTokens?: number; -``` - -## GenerationConfig.presencePenalty - -Signature: - -```typescript -presencePenalty?: number; -``` - -## GenerationConfig.responseMimeType - -Output response MIME type of the generated candidate text. Supported MIME types are `text/plain` (default, text output), `application/json` (JSON response in the candidates), and `text/x.enum`. - -Signature: - -```typescript -responseMimeType?: string; -``` - -## GenerationConfig.responseModalities - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Generation modalities to be returned in generation responses. - -- Multimodal response generation is only supported by some Gemini models and versions; see [model versions](https://firebase.google.com/docs/vertex-ai/models). - Only image generation (`ResponseModality.IMAGE`) is supported. - -Signature: - -```typescript -responseModalities?: ResponseModality[]; -``` - -## GenerationConfig.responseSchema - -Output response schema of the generated candidate text. This value can be a class generated with a [Schema](./vertexai.schema.md#schema_class) static method like `Schema.string()` or `Schema.object()` or it can be a plain JS object matching the [SchemaRequest](./vertexai.schemarequest.md#schemarequest_interface) interface.
Note: This only applies when the specified `responseMIMEType` supports a schema; currently this is limited to `application/json` and `text/x.enum`. - -Signature: - -```typescript -responseSchema?: TypedSchema | SchemaRequest; -``` - -## GenerationConfig.stopSequences - -Signature: - -```typescript -stopSequences?: string[]; -``` - -## GenerationConfig.temperature - -Signature: - -```typescript -temperature?: number; -``` - -## GenerationConfig.topK - -Signature: - -```typescript -topK?: number; -``` - -## GenerationConfig.topP - -Signature: - -```typescript -topP?: number; -``` diff --git a/docs-devsite/vertexai.generativemodel.md b/docs-devsite/vertexai.generativemodel.md deleted file mode 100644 index ba82b65aceb..00000000000 --- a/docs-devsite/vertexai.generativemodel.md +++ /dev/null @@ -1,193 +0,0 @@ -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 %} - -# GenerativeModel class -Class for generative model APIs. - -Signature: - -```typescript -export declare class GenerativeModel extends AIModel -``` -Extends: [AIModel](./vertexai.aimodel.md#aimodel_class) - -## Constructors - -| Constructor | Modifiers | Description | -| --- | --- | --- | -| [(constructor)(ai, modelParams, requestOptions)](./vertexai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the GenerativeModel class | - -## Properties - -| Property | Modifiers | Type | Description | -| --- | --- | --- | --- | -| [generationConfig](./vertexai.generativemodel.md#generativemodelgenerationconfig) | | [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | | -| [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) | | -| [toolConfig](./vertexai.generativemodel.md#generativemodeltoolconfig) | | [ToolConfig](./vertexai.toolconfig.md#toolconfig_interface) | | -| [tools](./vertexai.generativemodel.md#generativemodeltools) | | [Tool](./vertexai.md#tool)\[\] | | - -## Methods - -| Method | Modifiers | Description | -| --- | --- | --- | -| [countTokens(request)](./vertexai.generativemodel.md#generativemodelcounttokens) | | Counts the tokens in the provided request. | -| [generateContent(request)](./vertexai.generativemodel.md#generativemodelgeneratecontent) | | Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | -| [generateContentStream(request)](./vertexai.generativemodel.md#generativemodelgeneratecontentstream) | | Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. | -| [startChat(startChatParams)](./vertexai.generativemodel.md#generativemodelstartchat) | | Gets a new [ChatSession](./vertexai.chatsession.md#chatsession_class) instance which can be used for multi-turn chats. | - -## GenerativeModel.(constructor) - -Constructs a new instance of the `GenerativeModel` class - -Signature: - -```typescript -constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions); -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| ai | [AI](./vertexai.ai.md#ai_interface) | | -| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | -| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | - -## GenerativeModel.generationConfig - -Signature: - -```typescript -generationConfig: GenerationConfig; -``` - -## GenerativeModel.requestOptions - -Signature: - -```typescript -requestOptions?: RequestOptions; -``` - -## GenerativeModel.safetySettings - -Signature: - -```typescript -safetySettings: SafetySetting[]; -``` - -## GenerativeModel.systemInstruction - -Signature: - -```typescript -systemInstruction?: Content; -``` - -## GenerativeModel.toolConfig - -Signature: - -```typescript -toolConfig?: ToolConfig; -``` - -## GenerativeModel.tools - -Signature: - -```typescript -tools?: Tool[]; -``` - -## GenerativeModel.countTokens() - -Counts the tokens in the provided request. - -Signature: - -```typescript -countTokens(request: CountTokensRequest | string | Array): Promise; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| request | [CountTokensRequest](./vertexai.counttokensrequest.md#counttokensrequest_interface) \| string \| Array<string \| [Part](./vertexai.md#part)> | | - -Returns: - -Promise<[CountTokensResponse](./vertexai.counttokensresponse.md#counttokensresponse_interface)> - -## GenerativeModel.generateContent() - -Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). - -Signature: - -```typescript -generateContent(request: GenerateContentRequest | string | Array): Promise; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| request | [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) \| string \| Array<string \| [Part](./vertexai.md#part)> | | - -Returns: - -Promise<[GenerateContentResult](./vertexai.generatecontentresult.md#generatecontentresult_interface)> - -## GenerativeModel.generateContentStream() - -Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. - -Signature: - -```typescript -generateContentStream(request: GenerateContentRequest | string | Array): Promise; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| request | [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) \| string \| Array<string \| [Part](./vertexai.md#part)> | | - -Returns: - -Promise<[GenerateContentStreamResult](./vertexai.generatecontentstreamresult.md#generatecontentstreamresult_interface)> - -## GenerativeModel.startChat() - -Gets a new [ChatSession](./vertexai.chatsession.md#chatsession_class) instance which can be used for multi-turn chats. - -Signature: - -```typescript -startChat(startChatParams?: StartChatParams): ChatSession; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| startChatParams | [StartChatParams](./vertexai.startchatparams.md#startchatparams_interface) | | - -Returns: - -[ChatSession](./vertexai.chatsession.md#chatsession_class) - diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md deleted file mode 100644 index ad6c433fa25..00000000000 --- a/docs-devsite/vertexai.md +++ /dev/null @@ -1,716 +0,0 @@ -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 %} - -# vertexai package -The Firebase AI Web SDK. - -## Functions - -| Function | Description | -| --- | --- | -| function(app, ...) | -| [getAI(app, options)](./vertexai.md#getai_a94a413) | Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | -| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413).Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. | -| function(ai, ...) | -| [getGenerativeModel(ai, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | -| [getImagenModel(ai, modelParams, requestOptions)](./vertexai.md#getimagenmodel_e1f6645) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | - -## Classes - -| Class | Description | -| --- | --- | -| [AIError](./vertexai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. | -| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.Instances of this class are associated with a specific Firebase AI backend (either the Vertex AI Gemini API or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. | -| [ArraySchema](./vertexai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | -| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Vertex AI Gemini API. | -| [BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | -| [ChatSession](./vertexai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | -| [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | -| [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) | Configuration class for the Gemini Developer API (using Google AI).Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini Developer API as the backend. | -| [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) Defines the image format for images generated by Imagen.Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface). | -| [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) | (Public Preview) Class for Imagen model APIs.This class provides methods for generating images using the Imagen model. | -| [IntegerSchema](./vertexai.integerschema.md#integerschema_class) | Schema class for "integer" types. | -| [NumberSchema](./vertexai.numberschema.md#numberschema_class) | Schema class for "number" types. | -| [ObjectSchema](./vertexai.objectschema.md#objectschema_class) | Schema class for "object" types. The properties param must be a map of Schema objects. | -| [Schema](./vertexai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with JSON.stringify() into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) | -| [StringSchema](./vertexai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. | -| [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Vertex AI Gemini API.Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. | - -## Enumerations - -| Enumeration | Description | -| --- | --- | -| [AIErrorCode](./vertexai.md#aierrorcode) | Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. | -| [BlockReason](./vertexai.md#blockreason) | Reason that a prompt was blocked. | -| [FinishReason](./vertexai.md#finishreason) | Reason that a candidate finished. | -| [FunctionCallingMode](./vertexai.md#functioncallingmode) | | -| [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)). | -| [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | -| [HarmCategory](./vertexai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | -| [HarmProbability](./vertexai.md#harmprobability) | Probability that a prompt or candidate matches a harm category. | -| [HarmSeverity](./vertexai.md#harmseverity) | Harm severity levels. | -| [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | (Public Preview) Aspect ratios for Imagen images.To specify an aspect ratio for generated images, set the aspectRatio property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface).See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. | -| [ImagenPersonFilterLevel](./vertexai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed.See the personGeneration documentation for more details. | -| [ImagenSafetyFilterLevel](./vertexai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | -| [Modality](./vertexai.md#modality) | Content part modality. | -| [SchemaType](./vertexai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | - -## Interfaces - -| Interface | Description | -| --- | --- | -| [AI](./vertexai.ai.md#ai_interface) | An instance of the Firebase AI SDK.Do not create this instance directly. Instead, use [getAI()](./vertexai.md#getai_a94a413). | -| [AIOptions](./vertexai.aioptions.md#aioptions_interface) | Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) and configuring its specific options (like location for Vertex AI). | -| [BaseParams](./vertexai.baseparams.md#baseparams_interface) | Base parameters for a number of methods. | -| [Citation](./vertexai.citation.md#citation_interface) | A single citation. | -| [CitationMetadata](./vertexai.citationmetadata.md#citationmetadata_interface) | Citation metadata that may be found on a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface). | -| [Content](./vertexai.content.md#content_interface) | Content type for both prompts and response candidates. | -| [CountTokensRequest](./vertexai.counttokensrequest.md#counttokensrequest_interface) | Params for calling [GenerativeModel.countTokens()](./vertexai.generativemodel.md#generativemodelcounttokens) | -| [CountTokensResponse](./vertexai.counttokensresponse.md#counttokensresponse_interface) | Response from calling [GenerativeModel.countTokens()](./vertexai.generativemodel.md#generativemodelcounttokens). | -| [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) | Details object that contains data originating from a bad HTTP response. | -| [Date\_2](./vertexai.date_2.md#date_2_interface) | Protobuf google.type.Date | -| [EnhancedGenerateContentResponse](./vertexai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface) | Response object wrapped with helper methods. | -| [ErrorDetails](./vertexai.errordetails.md#errordetails_interface) | Details object that may be included in an error response. | -| [FileData](./vertexai.filedata.md#filedata_interface) | Data pointing to a file uploaded on Google Cloud Storage. | -| [FileDataPart](./vertexai.filedatapart.md#filedatapart_interface) | Content part interface if the part represents [FileData](./vertexai.filedata.md#filedata_interface) | -| [FunctionCall](./vertexai.functioncall.md#functioncall_interface) | A predicted [FunctionCall](./vertexai.functioncall.md#functioncall_interface) returned from the model that contains a string representing the [FunctionDeclaration.name](./vertexai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing the parameters and their values. | -| [FunctionCallingConfig](./vertexai.functioncallingconfig.md#functioncallingconfig_interface) | | -| [FunctionCallPart](./vertexai.functioncallpart.md#functioncallpart_interface) | Content part interface if the part represents a [FunctionCall](./vertexai.functioncall.md#functioncall_interface). | -| [FunctionDeclaration](./vertexai.functiondeclaration.md#functiondeclaration_interface) | Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included in this declaration are the function name and parameters. This FunctionDeclaration is a representation of a block of code that can be used as a Tool by the model and executed by the client. | -| [FunctionDeclarationsTool](./vertexai.functiondeclarationstool.md#functiondeclarationstool_interface) | A FunctionDeclarationsTool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. | -| [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface) | The result output from a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) that contains a string representing the [FunctionDeclaration.name](./vertexai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) made based on model prediction. | -| [FunctionResponsePart](./vertexai.functionresponsepart.md#functionresponsepart_interface) | Content part interface if the part represents [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface). | -| [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | A candidate returned as part of a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | -| [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) | Request sent through [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) | -| [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface) | Individual response from [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) and [GenerativeModel.generateContentStream()](./vertexai.generativemodel.md#generativemodelgeneratecontentstream). generateContentStream() will return one in each chunk until the stream is done. | -| [GenerateContentResult](./vertexai.generatecontentresult.md#generatecontentresult_interface) | Result object returned from [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) call. | -| [GenerateContentStreamResult](./vertexai.generatecontentstreamresult.md#generatecontentstreamresult_interface) | Result object returned from [GenerativeModel.generateContentStream()](./vertexai.generativemodel.md#generativemodelgeneratecontentstream) call. Iterate over stream to get chunks as they come in and/or use the response promise to get the aggregated response when the stream is done. | -| [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | Config options for content-related requests | -| [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. | -| [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | | -| [GroundingMetadata](./vertexai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. | -| [ImagenGCSImage](./vertexai.imagengcsimage.md#imagengcsimage_interface) | An image generated by Imagen, stored in a Cloud Storage for Firebase bucket.This feature is not available yet. | -| [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) Configuration options for generating images with Imagen.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details. | -| [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | (Public Preview) The response from a request to generate images with Imagen. | -| [ImagenInlineImage](./vertexai.imageninlineimage.md#imageninlineimage_interface) | (Public Preview) An image generated by Imagen, represented as inline data. | -| [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | (Public Preview) Parameters for configuring an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class). | -| [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Settings for controlling the aggressiveness of filtering out sensitive content.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details. | -| [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. | -| [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. | -| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). | -| [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. | -| [PromptFeedback](./vertexai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with blockReason and the relevant safetyRatings. | -| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). | -| [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | | -| [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | -| [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. | -| [SchemaInterface](./vertexai.schemainterface.md#schemainterface_interface) | Interface for [Schema](./vertexai.schema.md#schema_class) class. | -| [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | Params passed to [Schema](./vertexai.schema.md#schema_class) static methods to create specific [Schema](./vertexai.schema.md#schema_class) classes. | -| [SchemaRequest](./vertexai.schemarequest.md#schemarequest_interface) | Final format for [Schema](./vertexai.schema.md#schema_class) params passed to backend requests. | -| [SchemaShared](./vertexai.schemashared.md#schemashared_interface) | Basic [Schema](./vertexai.schema.md#schema_class) properties shared across several Schema-related types. | -| [Segment](./vertexai.segment.md#segment_interface) | | -| [StartChatParams](./vertexai.startchatparams.md#startchatparams_interface) | Params for [GenerativeModel.startChat()](./vertexai.generativemodel.md#generativemodelstartchat). | -| [TextPart](./vertexai.textpart.md#textpart_interface) | Content part interface if the part represents a text string. | -| [ToolConfig](./vertexai.toolconfig.md#toolconfig_interface) | Tool config. This config is shared for all tools provided in the request. | -| [UsageMetadata](./vertexai.usagemetadata.md#usagemetadata_interface) | Usage metadata about a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | -| [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | Options when initializing the Firebase AI SDK. | -| [VideoMetadata](./vertexai.videometadata.md#videometadata_interface) | Describes the input video content. | -| [WebAttribution](./vertexai.webattribution.md#webattribution_interface) | | - -## Variables - -| Variable | Description | -| --- | --- | -| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | -| [POSSIBLE\_ROLES](./vertexai.md#possible_roles) | Possible roles. | -| [ResponseModality](./vertexai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | -| [VertexAIError](./vertexai.md#vertexaierror) | Error class for the Firebase AI SDK.For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). | -| [VertexAIModel](./vertexai.md#vertexaimodel) | Base class for Firebase AI model APIs.For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). | - -## Type Aliases - -| Type Alias | Description | -| --- | --- | -| [BackendType](./vertexai.md#backendtype) | Type alias representing valid backend types. It can be either 'VERTEX_AI' or 'GOOGLE_AI'. | -| [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. | -| [ResponseModality](./vertexai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | -| [Role](./vertexai.md#role) | Role is the producer of the content. | -| [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. | -| [TypedSchema](./vertexai.md#typedschema) | A type that includes all specific Schema types. | -| [VertexAI](./vertexai.md#vertexai) | An instance of the Firebase AI SDK.For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface) interface. | - -## function(app, ...) - -### getAI(app, options) {:#getai_a94a413} - -Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. - -Signature: - -```typescript -export declare function getAI(app?: FirebaseApp, options?: AIOptions): AI; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | -| options | [AIOptions](./vertexai.aioptions.md#aioptions_interface) | [AIOptions](./vertexai.aioptions.md#aioptions_interface) that configure the AI instance. | - -Returns: - -[AI](./vertexai.ai.md#ai_interface) - -The default [AI](./vertexai.ai.md#ai_interface) instance for the given [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). - -### Example 1 - - -```javascript -const ai = getAI(app); - -``` - -### Example 2 - - -```javascript -// Get an AI instance configured to use the Gemini Developer API (via Google AI). -const ai = getAI(app, { backend: new GoogleAIBackend() }); - -``` - -### Example 3 - - -```javascript -// Get an AI instance configured to use the Vertex AI Gemini API. -const ai = getAI(app, { backend: new VertexAIBackend() }); - -``` - -### getVertexAI(app, options) {:#getvertexai_04094cf} - -It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413). - -Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. - -Signature: - -```typescript -export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | -| options | [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | Options to configure the Vertex AI instance, including the location. | - -Returns: - -[VertexAI](./vertexai.md#vertexai) - -## function(ai, ...) - -### getGenerativeModel(ai, modelParams, requestOptions) {:#getgenerativemodel_80bd839} - -Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. - -Signature: - -```typescript -export declare function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| ai | [AI](./vertexai.ai.md#ai_interface) | | -| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | -| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | - -Returns: - -[GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) - -### getImagenModel(ai, modelParams, requestOptions) {:#getimagenmodel_e1f6645} - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen. - -Only Imagen 3 models (named `imagen-3.0-*`) are supported. - -Signature: - -```typescript -export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| ai | [AI](./vertexai.ai.md#ai_interface) | An [AI](./vertexai.ai.md#ai_interface) instance. | -| modelParams | [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making Imagen requests. | -| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. | - -Returns: - -[ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) - -#### Exceptions - -If the `apiKey` or `projectId` fields are missing in your Firebase config. - -## BackendType - -An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with. - -These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. - -Signature: - -```typescript -BackendType: { - readonly VERTEX_AI: "VERTEX_AI"; - readonly GOOGLE_AI: "GOOGLE_AI"; -} -``` - -## POSSIBLE\_ROLES - -Possible roles. - -Signature: - -```typescript -POSSIBLE_ROLES: readonly ["user", "model", "function", "system"] -``` - -## ResponseModality - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Generation modalities to be returned in generation responses. - -Signature: - -```typescript -ResponseModality: { - readonly TEXT: "TEXT"; - readonly IMAGE: "IMAGE"; -} -``` - -## VertexAIError - -Error class for the Firebase AI SDK. - -For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). - -Signature: - -```typescript -VertexAIError: typeof AIError -``` - -## VertexAIModel - -Base class for Firebase AI model APIs. - -For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). - -Signature: - -```typescript -VertexAIModel: typeof AIModel -``` - -## BackendType - -Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. - -Signature: - -```typescript -export type BackendType = (typeof BackendType)[keyof typeof BackendType]; -``` - -## Part - -Content part - includes text, image/video, or function call/response part types. - -Signature: - -```typescript -export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; -``` - -## ResponseModality - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Generation modalities to be returned in generation responses. - -Signature: - -```typescript -export type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality]; -``` - -## Role - -Role is the producer of the content. - -Signature: - -```typescript -export type Role = (typeof POSSIBLE_ROLES)[number]; -``` - -## Tool - -Defines a tool that model can call to access external knowledge. - -Signature: - -```typescript -export declare type Tool = FunctionDeclarationsTool; -``` - -## TypedSchema - -A type that includes all specific Schema types. - -Signature: - -```typescript -export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; -``` - -## VertexAI - -An instance of the Firebase AI SDK. - -For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface) interface. - -Signature: - -```typescript -export type VertexAI = AI; -``` - -## AIErrorCode - -Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. - -Signature: - -```typescript -export declare const enum AIErrorCode -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| API\_NOT\_ENABLED | "api-not-enabled" | An error due to the Firebase API not being enabled in the Console. | -| ERROR | "error" | A generic error occurred. | -| FETCH\_ERROR | "fetch-error" | An error occurred while performing a fetch. | -| INVALID\_CONTENT | "invalid-content" | An error associated with a Content object. | -| INVALID\_SCHEMA | "invalid-schema" | An error due to invalid Schema input. | -| NO\_API\_KEY | "no-api-key" | An error occurred due to a missing Firebase API key. | -| NO\_APP\_ID | "no-app-id" | An error occured due to a missing Firebase app ID. | -| NO\_MODEL | "no-model" | An error occurred due to a model name not being specified during initialization. | -| NO\_PROJECT\_ID | "no-project-id" | An error occurred due to a missing project ID. | -| PARSE\_FAILED | "parse-failed" | An error occurred while parsing. | -| REQUEST\_ERROR | "request-error" | An error occurred in a request. | -| RESPONSE\_ERROR | "response-error" | An error occurred in a response. | -| UNSUPPORTED | "unsupported" | An error occured due an attempt to use an unsupported feature. | - -## BlockReason - -Reason that a prompt was blocked. - -Signature: - -```typescript -export declare enum BlockReason -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCKLIST | "BLOCKLIST" | Content was blocked because it contained terms from the terminology blocklist. | -| OTHER | "OTHER" | Content was blocked, but the reason is uncategorized. | -| PROHIBITED\_CONTENT | "PROHIBITED_CONTENT" | Content was blocked due to prohibited content. | -| SAFETY | "SAFETY" | Content was blocked by safety settings. | - -## FinishReason - -Reason that a candidate finished. - -Signature: - -```typescript -export declare enum FinishReason -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCKLIST | "BLOCKLIST" | The candidate content contained forbidden terms. | -| MALFORMED\_FUNCTION\_CALL | "MALFORMED_FUNCTION_CALL" | The function call generated by the model was invalid. | -| MAX\_TOKENS | "MAX_TOKENS" | The maximum number of tokens as specified in the request was reached. | -| OTHER | "OTHER" | Unknown reason. | -| PROHIBITED\_CONTENT | "PROHIBITED_CONTENT" | The candidate content potentially contained prohibited content. | -| RECITATION | "RECITATION" | The candidate content was flagged for recitation reasons. | -| SAFETY | "SAFETY" | The candidate content was flagged for safety reasons. | -| SPII | "SPII" | The candidate content potentially contained Sensitive Personally Identifiable Information (SPII). | -| STOP | "STOP" | Natural stop point of the model or provided stop sequence. | - -## FunctionCallingMode - - -Signature: - -```typescript -export declare enum FunctionCallingMode -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ANY | "ANY" | Model is constrained to always predicting a function call only. If allowed_function_names is set, the predicted function call will be limited to any one of allowed_function_names, else the predicted function call will be any one of the provided function_declarations. | -| AUTO | "AUTO" | Default model behavior; model decides to predict either a function call or a natural language response. | -| NONE | "NONE" | Model will not predict any function call. Model behavior is same as when not passing any function declarations. | - -## HarmBlockMethod - -This property is not supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)). - -Signature: - -```typescript -export declare enum HarmBlockMethod -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| PROBABILITY | "PROBABILITY" | The harm block method uses the probability score. | -| SEVERITY | "SEVERITY" | The harm block method uses both probability and severity scores. | - -## HarmBlockThreshold - -Threshold above which a prompt or candidate will be blocked. - -Signature: - -```typescript -export declare enum HarmBlockThreshold -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCK\_LOW\_AND\_ABOVE | "BLOCK_LOW_AND_ABOVE" | Content with NEGLIGIBLE will be allowed. | -| BLOCK\_MEDIUM\_AND\_ABOVE | "BLOCK_MEDIUM_AND_ABOVE" | Content with NEGLIGIBLE and LOW will be allowed. | -| BLOCK\_NONE | "BLOCK_NONE" | All content will be allowed. | -| BLOCK\_ONLY\_HIGH | "BLOCK_ONLY_HIGH" | Content with NEGLIGIBLE, LOW, and MEDIUM will be allowed. | - -## HarmCategory - -Harm categories that would cause prompts or candidates to be blocked. - -Signature: - -```typescript -export declare enum HarmCategory -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HARM\_CATEGORY\_DANGEROUS\_CONTENT | "HARM_CATEGORY_DANGEROUS_CONTENT" | | -| HARM\_CATEGORY\_HARASSMENT | "HARM_CATEGORY_HARASSMENT" | | -| HARM\_CATEGORY\_HATE\_SPEECH | "HARM_CATEGORY_HATE_SPEECH" | | -| HARM\_CATEGORY\_SEXUALLY\_EXPLICIT | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | | - -## HarmProbability - -Probability that a prompt or candidate matches a harm category. - -Signature: - -```typescript -export declare enum HarmProbability -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HIGH | "HIGH" | Content has a high chance of being unsafe. | -| LOW | "LOW" | Content has a low chance of being unsafe. | -| MEDIUM | "MEDIUM" | Content has a medium chance of being unsafe. | -| NEGLIGIBLE | "NEGLIGIBLE" | Content has a negligible chance of being unsafe. | - -## HarmSeverity - -Harm severity levels. - -Signature: - -```typescript -export declare enum HarmSeverity -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HARM\_SEVERITY\_HIGH | "HARM_SEVERITY_HIGH" | High level of harm severity. | -| HARM\_SEVERITY\_LOW | "HARM_SEVERITY_LOW" | Low level of harm severity. | -| HARM\_SEVERITY\_MEDIUM | "HARM_SEVERITY_MEDIUM" | Medium level of harm severity. | -| HARM\_SEVERITY\_NEGLIGIBLE | "HARM_SEVERITY_NEGLIGIBLE" | Negligible level of harm severity. | -| HARM\_SEVERITY\_UNSUPPORTED | "HARM_SEVERITY_UNSUPPORTED" | Harm severity is not supported. | - -## ImagenAspectRatio - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Aspect ratios for Imagen images. - -To specify an aspect ratio for generated images, set the `aspectRatio` property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface). - -See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. - -Signature: - -```typescript -export declare enum ImagenAspectRatio -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| LANDSCAPE\_16x9 | "16:9" | (Public Preview) Landscape (16:9) aspect ratio. | -| LANDSCAPE\_3x4 | "3:4" | (Public Preview) Landscape (3:4) aspect ratio. | -| PORTRAIT\_4x3 | "4:3" | (Public Preview) Portrait (4:3) aspect ratio. | -| PORTRAIT\_9x16 | "9:16" | (Public Preview) Portrait (9:16) aspect ratio. | -| SQUARE | "1:1" | (Public Preview) Square (1:1) aspect ratio. | - -## ImagenPersonFilterLevel - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -A filter level controlling whether generation of images containing people or faces is allowed. - -See the personGeneration documentation for more details. - -Signature: - -```typescript -export declare enum ImagenPersonFilterLevel -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ALLOW\_ADULT | "allow_adult" | (Public Preview) Allow generation of images containing adults only; images of children are filtered out.Generation of images containing people or faces may require your use case to be reviewed and approved by Cloud support; see the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) for more details. | -| ALLOW\_ALL | "allow_all" | (Public Preview) Allow generation of images containing adults only; images of children are filtered out.Generation of images containing people or faces may require your use case to be reviewed and approved by Cloud support; see the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) for more details. | -| BLOCK\_ALL | "dont_allow" | (Public Preview) Disallow generation of images containing people or faces; images of people are filtered out. | - -## ImagenSafetyFilterLevel - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -A filter level controlling how aggressively to filter sensitive content. - -Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, `violence`, `sexual`, `derogatory`, and `toxic`). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. - -Signature: - -```typescript -export declare enum ImagenSafetyFilterLevel -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCK\_LOW\_AND\_ABOVE | "block_low_and_above" | (Public Preview) The most aggressive filtering level; most strict blocking. | -| BLOCK\_MEDIUM\_AND\_ABOVE | "block_medium_and_above" | (Public Preview) Blocks some sensitive prompts and responses. | -| BLOCK\_NONE | "block_none" | (Public Preview) The least aggressive filtering level; blocks very few sensitive prompts and responses.Access to this feature is restricted and may require your case to be reviewed and approved by Cloud support. | -| BLOCK\_ONLY\_HIGH | "block_only_high" | (Public Preview) Blocks few sensitive prompts and responses. | - -## Modality - -Content part modality. - -Signature: - -```typescript -export declare enum Modality -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| AUDIO | "AUDIO" | Audio. | -| DOCUMENT | "DOCUMENT" | Document (for example, PDF). | -| IMAGE | "IMAGE" | Image. | -| MODALITY\_UNSPECIFIED | "MODALITY_UNSPECIFIED" | Unspecified modality. | -| TEXT | "TEXT" | Plain text. | -| VIDEO | "VIDEO" | Video. | - -## SchemaType - -Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) - -Signature: - -```typescript -export declare enum SchemaType -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ARRAY | "array" | Array type. | -| BOOLEAN | "boolean" | Boolean type. | -| INTEGER | "integer" | Integer type. | -| NUMBER | "number" | Number type. | -| OBJECT | "object" | Object type. | -| STRING | "string" | String type. | - diff --git a/docs-devsite/vertexai.safetyrating.md b/docs-devsite/vertexai.safetyrating.md deleted file mode 100644 index ebe5003c662..00000000000 --- a/docs-devsite/vertexai.safetyrating.md +++ /dev/null @@ -1,90 +0,0 @@ -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 %} - -# SafetyRating interface -A safety rating associated with a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) - -Signature: - -```typescript -export interface SafetyRating -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [blocked](./vertexai.safetyrating.md#safetyratingblocked) | boolean | | -| [category](./vertexai.safetyrating.md#safetyratingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | -| [probability](./vertexai.safetyrating.md#safetyratingprobability) | [HarmProbability](./vertexai.md#harmprobability) | | -| [probabilityScore](./vertexai.safetyrating.md#safetyratingprobabilityscore) | number | The probability score of the harm category.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | -| [severity](./vertexai.safetyrating.md#safetyratingseverity) | [HarmSeverity](./vertexai.md#harmseverity) | The harm severity level.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to HarmSeverity.UNSUPPORTED. | -| [severityScore](./vertexai.safetyrating.md#safetyratingseverityscore) | number | The severity score of the harm category.This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. | - -## SafetyRating.blocked - -Signature: - -```typescript -blocked: boolean; -``` - -## SafetyRating.category - -Signature: - -```typescript -category: HarmCategory; -``` - -## SafetyRating.probability - -Signature: - -```typescript -probability: HarmProbability; -``` - -## SafetyRating.probabilityScore - -The probability score of the harm category. - -This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. - -Signature: - -```typescript -probabilityScore: number; -``` - -## SafetyRating.severity - -The harm severity level. - -This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`. - -Signature: - -```typescript -severity: HarmSeverity; -``` - -## SafetyRating.severityScore - -The severity score of the harm category. - -This property is only supported when using the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), this property is not supported and will default to 0. - -Signature: - -```typescript -severityScore: number; -``` diff --git a/docs-devsite/vertexai.safetysetting.md b/docs-devsite/vertexai.safetysetting.md deleted file mode 100644 index a91843faaa5..00000000000 --- a/docs-devsite/vertexai.safetysetting.md +++ /dev/null @@ -1,55 +0,0 @@ -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 %} - -# SafetySetting interface -Safety setting that can be sent as part of request parameters. - -Signature: - -```typescript -export interface SafetySetting -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [category](./vertexai.safetysetting.md#safetysettingcategory) | [HarmCategory](./vertexai.md#harmcategory) | | -| [method](./vertexai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./vertexai.md#harmblockmethod) | The harm block method.This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), an [AIError](./vertexai.aierror.md#aierror_class) will be thrown if this property is defined. | -| [threshold](./vertexai.safetysetting.md#safetysettingthreshold) | [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | | - -## SafetySetting.category - -Signature: - -```typescript -category: HarmCategory; -``` - -## SafetySetting.method - -The harm block method. - -This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)). When using the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)), an [AIError](./vertexai.aierror.md#aierror_class) will be thrown if this property is defined. - -Signature: - -```typescript -method?: HarmBlockMethod; -``` - -## SafetySetting.threshold - -Signature: - -```typescript -threshold: HarmBlockThreshold; -``` From 9f81d48d069c6c98126285aa4a40a88d56a3e342 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 9 May 2025 11:06:10 -0400 Subject: [PATCH 23/32] format --- scripts/docgen/docgen.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/docgen/docgen.ts b/scripts/docgen/docgen.ts index 5d0ebd9088e..cbfefb43138 100644 --- a/scripts/docgen/docgen.ts +++ b/scripts/docgen/docgen.ts @@ -60,7 +60,7 @@ const PREFERRED_PARAMS = [ 'performance', 'remoteConfig', 'storage', - 'vertexAI' // TODO (dlarocque-ai) + 'AI' ]; let authApiReportOriginal: string; @@ -133,7 +133,7 @@ function cleanup() { } catch (e) { console.error( 'Error cleaning up files on exit - ' + - 'check for temp modifications to md and json files.' + 'check for temp modifications to md and json files.' ); console.error(e); } From cb745af6a49fcb3c464d3cb435fdc0256d13971b Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 9 May 2025 15:02:06 -0400 Subject: [PATCH 24/32] add deprecation notices in docs --- common/api-review/ai.api.md | 10 ++++---- docs-devsite/ai.ai.md | 6 ++--- docs-devsite/ai.md | 44 +++++++++++++++++++++------------ packages/ai/src/api.ts | 18 +++++++++----- packages/ai/src/constants.ts | 3 --- packages/ai/src/public-types.ts | 10 +++++--- 6 files changed, 54 insertions(+), 37 deletions(-) diff --git a/common/api-review/ai.api.md b/common/api-review/ai.api.md index 7b6b42182c1..d096d4c27f6 100644 --- a/common/api-review/ai.api.md +++ b/common/api-review/ai.api.md @@ -13,7 +13,7 @@ import { FirebaseError } from '@firebase/util'; export interface AI { app: FirebaseApp; backend: Backend; - // @deprecated + // @deprecated (undocumented) location: string; } @@ -423,7 +423,7 @@ export function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOpti // @beta export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; -// @public +// @public @deprecated (undocumented) export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; // @public @@ -916,7 +916,7 @@ export interface UsageMetadata { totalTokenCount: number; } -// @public +// @public @deprecated (undocumented) export type VertexAI = AI; // @public @@ -925,10 +925,10 @@ export class VertexAIBackend extends Backend { readonly location: string; } -// @public +// @public @deprecated (undocumented) export const VertexAIError: typeof AIError; -// @public +// @public @deprecated (undocumented) export const VertexAIModel: typeof AIModel; // @public diff --git a/docs-devsite/ai.ai.md b/docs-devsite/ai.ai.md index bc06122edf6..d4127ffb7e8 100644 --- a/docs-devsite/ai.ai.md +++ b/docs-devsite/ai.ai.md @@ -26,7 +26,7 @@ export interface AI | --- | --- | --- | | [app](./ai.ai.md#aiapp) | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) this [AI](./ai.ai.md#ai_interface) instance is associated with. | | [backend](./ai.ai.md#aibackend) | [Backend](./ai.backend.md#backend_class) | A [Backend](./ai.backend.md#backend_class) instance that specifies the configuration for the target backend, either the Gemini Developer API (using [GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)) or the Vertex AI Gemini API (using [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)). | -| [location](./ai.ai.md#ailocation) | string | The location configured for this AI service instance, relevant for Vertex AI backends. | +| [location](./ai.ai.md#ailocation) | string | | ## AI.app @@ -54,8 +54,8 @@ backend: Backend; > > use `AI.backend.location` instead. > - -The location configured for this AI service instance, relevant for Vertex AI backends. +> The location configured for this AI service instance, relevant for Vertex AI backends. +> Signature: diff --git a/docs-devsite/ai.md b/docs-devsite/ai.md index 2f5c8df7c94..c476a293a92 100644 --- a/docs-devsite/ai.md +++ b/docs-devsite/ai.md @@ -18,7 +18,7 @@ The Firebase AI Web SDK. | --- | --- | | function(app, ...) | | [getAI(app, options)](./ai.md#getai_a94a413) | Returns the default [AI](./ai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | -| [getVertexAI(app, options)](./ai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./ai.md#getai_a94a413).Returns a [VertexAI](./ai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. | +| [getVertexAI(app, options)](./ai.md#getvertexai_04094cf) | | | function(ai, ...) | | [getGenerativeModel(ai, modelParams, requestOptions)](./ai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./ai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | | [getImagenModel(ai, modelParams, requestOptions)](./ai.md#getimagenmodel_e1f6645) | (Public Preview) Returns an [ImagenModel](./ai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | @@ -132,8 +132,8 @@ The Firebase AI Web SDK. | [BackendType](./ai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | | [POSSIBLE\_ROLES](./ai.md#possible_roles) | Possible roles. | | [ResponseModality](./ai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | -| [VertexAIError](./ai.md#vertexaierror) | Error class for the Firebase AI SDK.For more information, refer to the documentation for the new [AIError](./ai.aierror.md#aierror_class). | -| [VertexAIModel](./ai.md#vertexaimodel) | Base class for Firebase AI model APIs.For more information, refer to the documentation for the new [AIModel](./ai.aimodel.md#aimodel_class). | +| [VertexAIError](./ai.md#vertexaierror) | | +| [VertexAIModel](./ai.md#vertexaimodel) | | ## Type Aliases @@ -145,7 +145,7 @@ The Firebase AI Web SDK. | [Role](./ai.md#role) | Role is the producer of the content. | | [Tool](./ai.md#tool) | Defines a tool that model can call to access external knowledge. | | [TypedSchema](./ai.md#typedschema) | A type that includes all specific Schema types. | -| [VertexAI](./ai.md#vertexai) | An instance of the Firebase AI SDK.For more information, refer to the documentation for the new [AI](./ai.ai.md#ai_interface) interface. | +| [VertexAI](./ai.md#vertexai) | | ## function(app, ...) @@ -200,9 +200,12 @@ const ai = getAI(app, { backend: new VertexAIBackend() }); ### getVertexAI(app, options) {:#getvertexai_04094cf} -It is recommended to use the new [getAI()](./ai.md#getai_a94a413). - -Returns a [VertexAI](./ai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. +> Warning: This API is now obsolete. +> +> Use the new [getAI()](./ai.md#getai_a94a413) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). +> +> Returns a [VertexAI](./ai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. +> Signature: @@ -319,9 +322,12 @@ ResponseModality: { ## VertexAIError -Error class for the Firebase AI SDK. - -For more information, refer to the documentation for the new [AIError](./ai.aierror.md#aierror_class). +> Warning: This API is now obsolete. +> +> Use the new [AIError](./ai.aierror.md#aierror_class) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). +> +> Error class for the Firebase AI SDK. +> Signature: @@ -331,9 +337,12 @@ VertexAIError: typeof AIError ## VertexAIModel -Base class for Firebase AI model APIs. - -For more information, refer to the documentation for the new [AIModel](./ai.aimodel.md#aimodel_class). +> Warning: This API is now obsolete. +> +> Use the new [AIModel](./ai.aimodel.md#aimodel_class) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). +> +> Base class for Firebase AI model APIs. +> Signature: @@ -406,9 +415,12 @@ export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanS ## VertexAI -An instance of the Firebase AI SDK. - -For more information, refer to the documentation for the new [AI](./ai.ai.md#ai_interface) interface. +> Warning: This API is now obsolete. +> +> Use the new [AI](./ai.ai.md#ai_interface) instead. The Vertex AI in Firebase SDK has been replaced with the Firebase AI SDK to accommodate the evolving set of supported features and services. For migration details, see the [migration guide](https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk). +> +> An instance of the Firebase AI SDK. +> Signature: diff --git a/packages/ai/src/api.ts b/packages/ai/src/api.ts index 06bd747746a..8c717ee3578 100644 --- a/packages/ai/src/api.ts +++ b/packages/ai/src/api.ts @@ -41,19 +41,23 @@ export { Backend, VertexAIBackend, GoogleAIBackend } from './backend'; export { AIErrorCode as VertexAIErrorCode }; /** + * @deprecated Use the new {@link AIModel} instead. The Vertex AI in Firebase SDK has been + * replaced with the Firebase AI SDK to accommodate the evolving set of supported features and + * services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}. + * * Base class for Firebase AI model APIs. * - * For more information, refer to the documentation for the new {@link AIModel}. - * * @public */ export const VertexAIModel = AIModel; /** + * @deprecated Use the new {@link AIError} instead. The Vertex AI in Firebase SDK has been + * replaced with the Firebase AI SDK to accommodate the evolving set of supported features and + * services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}. + * * Error class for the Firebase AI SDK. - * - * For more information, refer to the documentation for the new {@link AIError}. - * + * * @public */ export const VertexAIError = AIError; @@ -65,7 +69,9 @@ declare module '@firebase/component' { } /** - * It is recommended to use the new {@link getAI | getAI()}. + * @deprecated Use the new {@link getAI | getAI()} instead. The Vertex AI in Firebase SDK has been + * replaced with the Firebase AI SDK to accommodate the evolving set of supported features and + * services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}. * * Returns a {@link VertexAI} instance for the given app, configured to use the * Vertex AI Gemini API. This instance will be diff --git a/packages/ai/src/constants.ts b/packages/ai/src/constants.ts index 6339ce63017..cb54567735a 100644 --- a/packages/ai/src/constants.ts +++ b/packages/ai/src/constants.ts @@ -17,9 +17,6 @@ import { version } from '../package.json'; -// TODO (v12): Remove this -export const VERTEX_TYPE = 'vertexAI'; - export const AI_TYPE = 'AI'; export const DEFAULT_LOCATION = 'us-central1'; diff --git a/packages/ai/src/public-types.ts b/packages/ai/src/public-types.ts index a82f930b9a8..e53ecee9431 100644 --- a/packages/ai/src/public-types.ts +++ b/packages/ai/src/public-types.ts @@ -21,9 +21,11 @@ import { Backend } from './backend'; export * from './types'; /** - * An instance of the Firebase AI SDK. + * @deprecated Use the new {@link AI | AI} instead. The Vertex AI in Firebase SDK has been + * replaced with the Firebase AI SDK to accommodate the evolving set of supported features and + * services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}. * - * For more information, refer to the documentation for the new {@link AI} interface. + * An instance of the Firebase AI SDK. * * @public */ @@ -57,9 +59,9 @@ export interface AI { */ backend: Backend; /** - * The location configured for this AI service instance, relevant for Vertex AI backends. - * * @deprecated use `AI.backend.location` instead. + * + * The location configured for this AI service instance, relevant for Vertex AI backends. */ location: string; } From b0e8c4fddb6473f0b69ffc21a679883d2fbc0e5f Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 9 May 2025 15:18:42 -0400 Subject: [PATCH 25/32] Update docgen script --- scripts/docgen/docgen.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/docgen/docgen.ts b/scripts/docgen/docgen.ts index cbfefb43138..811570decd1 100644 --- a/scripts/docgen/docgen.ts +++ b/scripts/docgen/docgen.ts @@ -60,7 +60,7 @@ const PREFERRED_PARAMS = [ 'performance', 'remoteConfig', 'storage', - 'AI' + 'ai' ]; let authApiReportOriginal: string; From 0ec80d96ce6a1f3ab45118c5f76dbc85222defd4 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 9 May 2025 16:25:23 -0400 Subject: [PATCH 26/32] Update npm tokens in workflows --- .github/workflows/canary-deploy.yml | 2 +- .github/workflows/prerelease-manual-deploy.yml | 2 +- .github/workflows/release-prod.yml | 2 +- .github/workflows/release-staging.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/canary-deploy.yml b/.github/workflows/canary-deploy.yml index 2a9a6a803a6..318db24f667 100644 --- a/.github/workflows/canary-deploy.yml +++ b/.github/workflows/canary-deploy.yml @@ -71,7 +71,7 @@ jobs: NPM_TOKEN_STORAGE: ${{secrets.NPM_TOKEN_STORAGE}} NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} - NPM_TOKEN_VERTEXAI: ${{secrets.NPM_TOKEN_VERTEXAI}} + NPM_TOKEN_AI: ${{secrets.NPM_TOKEN_AI}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/prerelease-manual-deploy.yml b/.github/workflows/prerelease-manual-deploy.yml index e5ccabdd144..d1ab281634c 100644 --- a/.github/workflows/prerelease-manual-deploy.yml +++ b/.github/workflows/prerelease-manual-deploy.yml @@ -74,7 +74,7 @@ jobs: NPM_TOKEN_STORAGE: ${{secrets.NPM_TOKEN_STORAGE}} NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} - NPM_TOKEN_VERTEXAI: ${{secrets.NPM_TOKEN_VERTEXAI}} + NPM_TOKEN_AI: ${{secrets.NPM_TOKEN_AI}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/release-prod.yml b/.github/workflows/release-prod.yml index f5a5b808629..3ae667df6be 100644 --- a/.github/workflows/release-prod.yml +++ b/.github/workflows/release-prod.yml @@ -84,7 +84,7 @@ jobs: NPM_TOKEN_STORAGE: ${{secrets.NPM_TOKEN_STORAGE}} NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} - NPM_TOKEN_VERTEXAI: ${{secrets.NPM_TOKEN_VERTEXAI}} + NPM_TOKEN_AI: ${{secrets.NPM_TOKEN_AI}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml index c4adefb44a8..2f5cf5eeb38 100644 --- a/.github/workflows/release-staging.yml +++ b/.github/workflows/release-staging.yml @@ -110,7 +110,7 @@ jobs: NPM_TOKEN_STORAGE: ${{secrets.NPM_TOKEN_STORAGE}} NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} - NPM_TOKEN_VERTEXAI: ${{secrets.NPM_TOKEN_VERTEXAI}} + NPM_TOKEN_AI: ${{secrets.NPM_TOKEN_AI}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} From 59118722678c724fb1c933461a6028ad55ae4a24 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 9 May 2025 16:34:49 -0400 Subject: [PATCH 27/32] Formatting --- packages/ai/src/api.ts | 6 +++--- packages/ai/src/public-types.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ai/src/api.ts b/packages/ai/src/api.ts index 8c717ee3578..d2229c067fc 100644 --- a/packages/ai/src/api.ts +++ b/packages/ai/src/api.ts @@ -44,7 +44,7 @@ export { AIErrorCode as VertexAIErrorCode }; * @deprecated Use the new {@link AIModel} instead. The Vertex AI in Firebase SDK has been * replaced with the Firebase AI SDK to accommodate the evolving set of supported features and * services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}. - * + * * Base class for Firebase AI model APIs. * * @public @@ -55,9 +55,9 @@ export const VertexAIModel = AIModel; * @deprecated Use the new {@link AIError} instead. The Vertex AI in Firebase SDK has been * replaced with the Firebase AI SDK to accommodate the evolving set of supported features and * services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}. - * + * * Error class for the Firebase AI SDK. - * + * * @public */ export const VertexAIError = AIError; diff --git a/packages/ai/src/public-types.ts b/packages/ai/src/public-types.ts index e53ecee9431..91350e4fb50 100644 --- a/packages/ai/src/public-types.ts +++ b/packages/ai/src/public-types.ts @@ -60,7 +60,7 @@ export interface AI { backend: Backend; /** * @deprecated use `AI.backend.location` instead. - * + * * The location configured for this AI service instance, relevant for Vertex AI backends. */ location: string; From 9529e08e30df53927633bc5fc0127a878ab6d305 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Sun, 11 May 2025 12:21:06 -0400 Subject: [PATCH 28/32] docs fixes --- docs-devsite/_toc.yaml | 149 +++++++++++++++++++++++ docs-devsite/index.md | 1 + docs-devsite/vertexai.aimodel.md | 2 +- docs-devsite/vertexai.backend.md | 4 +- docs-devsite/vertexai.googleaibackend.md | 2 +- docs-devsite/vertexai.md | 6 +- packages/vertexai/src/backend.ts | 13 +- packages/vertexai/src/models/ai-model.ts | 3 +- packages/vertexai/src/public-types.ts | 2 +- 9 files changed, 165 insertions(+), 17 deletions(-) diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index c507b44ce99..ee0235b3627 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -1,6 +1,155 @@ toc: - title: firebase path: /docs/reference/js/index +- title: ai + path: /docs/reference/js/ai.md + section: + - title: AI + path: /docs/reference/js/ai.ai.md + - title: AIError + path: /docs/reference/js/ai.aierror.md + - title: AIModel + path: /docs/reference/js/ai.aimodel.md + - title: AIOptions + path: /docs/reference/js/ai.aioptions.md + - title: ArraySchema + path: /docs/reference/js/ai.arrayschema.md + - title: Backend + path: /docs/reference/js/ai.backend.md + - title: BaseParams + path: /docs/reference/js/ai.baseparams.md + - title: BooleanSchema + path: /docs/reference/js/ai.booleanschema.md + - title: ChatSession + path: /docs/reference/js/ai.chatsession.md + - title: Citation + path: /docs/reference/js/ai.citation.md + - title: CitationMetadata + path: /docs/reference/js/ai.citationmetadata.md + - title: Content + path: /docs/reference/js/ai.content.md + - title: CountTokensRequest + path: /docs/reference/js/ai.counttokensrequest.md + - title: CountTokensResponse + path: /docs/reference/js/ai.counttokensresponse.md + - title: CustomErrorData + path: /docs/reference/js/ai.customerrordata.md + - title: Date_2 + path: /docs/reference/js/ai.date_2.md + - title: EnhancedGenerateContentResponse + path: /docs/reference/js/ai.enhancedgeneratecontentresponse.md + - title: ErrorDetails + path: /docs/reference/js/ai.errordetails.md + - title: FileData + path: /docs/reference/js/ai.filedata.md + - title: FileDataPart + path: /docs/reference/js/ai.filedatapart.md + - title: FunctionCall + path: /docs/reference/js/ai.functioncall.md + - title: FunctionCallingConfig + path: /docs/reference/js/ai.functioncallingconfig.md + - title: FunctionCallPart + path: /docs/reference/js/ai.functioncallpart.md + - title: FunctionDeclaration + path: /docs/reference/js/ai.functiondeclaration.md + - title: FunctionDeclarationsTool + path: /docs/reference/js/ai.functiondeclarationstool.md + - title: FunctionResponse + path: /docs/reference/js/ai.functionresponse.md + - title: FunctionResponsePart + path: /docs/reference/js/ai.functionresponsepart.md + - title: GenerateContentCandidate + path: /docs/reference/js/ai.generatecontentcandidate.md + - title: GenerateContentRequest + path: /docs/reference/js/ai.generatecontentrequest.md + - title: GenerateContentResponse + path: /docs/reference/js/ai.generatecontentresponse.md + - title: GenerateContentResult + path: /docs/reference/js/ai.generatecontentresult.md + - title: GenerateContentStreamResult + path: /docs/reference/js/ai.generatecontentstreamresult.md + - title: GenerationConfig + path: /docs/reference/js/ai.generationconfig.md + - title: GenerativeContentBlob + path: /docs/reference/js/ai.generativecontentblob.md + - title: GenerativeModel + path: /docs/reference/js/ai.generativemodel.md + - title: GoogleAIBackend + path: /docs/reference/js/ai.googleaibackend.md + - title: GroundingAttribution + path: /docs/reference/js/ai.groundingattribution.md + - title: GroundingMetadata + path: /docs/reference/js/ai.groundingmetadata.md + - title: ImagenGCSImage + path: /docs/reference/js/ai.imagengcsimage.md + - title: ImagenGenerationConfig + path: /docs/reference/js/ai.imagengenerationconfig.md + - title: ImagenGenerationResponse + path: /docs/reference/js/ai.imagengenerationresponse.md + - title: ImagenImageFormat + path: /docs/reference/js/ai.imagenimageformat.md + - title: ImagenInlineImage + path: /docs/reference/js/ai.imageninlineimage.md + - title: ImagenModel + path: /docs/reference/js/ai.imagenmodel.md + - title: ImagenModelParams + path: /docs/reference/js/ai.imagenmodelparams.md + - title: ImagenSafetySettings + path: /docs/reference/js/ai.imagensafetysettings.md + - title: InlineDataPart + path: /docs/reference/js/ai.inlinedatapart.md + - title: IntegerSchema + path: /docs/reference/js/ai.integerschema.md + - title: ModalityTokenCount + path: /docs/reference/js/ai.modalitytokencount.md + - title: ModelParams + path: /docs/reference/js/ai.modelparams.md + - title: NumberSchema + path: /docs/reference/js/ai.numberschema.md + - title: ObjectSchema + path: /docs/reference/js/ai.objectschema.md + - title: ObjectSchemaInterface + path: /docs/reference/js/ai.objectschemainterface.md + - title: PromptFeedback + path: /docs/reference/js/ai.promptfeedback.md + - title: RequestOptions + path: /docs/reference/js/ai.requestoptions.md + - title: RetrievedContextAttribution + path: /docs/reference/js/ai.retrievedcontextattribution.md + - title: SafetyRating + path: /docs/reference/js/ai.safetyrating.md + - title: SafetySetting + path: /docs/reference/js/ai.safetysetting.md + - title: Schema + path: /docs/reference/js/ai.schema.md + - title: SchemaInterface + path: /docs/reference/js/ai.schemainterface.md + - title: SchemaParams + path: /docs/reference/js/ai.schemaparams.md + - title: SchemaRequest + path: /docs/reference/js/ai.schemarequest.md + - title: SchemaShared + path: /docs/reference/js/ai.schemashared.md + - title: Segment + path: /docs/reference/js/ai.segment.md + - title: StartChatParams + path: /docs/reference/js/ai.startchatparams.md + - title: StringSchema + path: /docs/reference/js/ai.stringschema.md + - title: TextPart + path: /docs/reference/js/ai.textpart.md + - title: ToolConfig + path: /docs/reference/js/ai.toolconfig.md + - title: UsageMetadata + path: /docs/reference/js/ai.usagemetadata.md + - title: VertexAIBackend + path: /docs/reference/js/ai.vertexaibackend.md + - title: VertexAIOptions + path: /docs/reference/js/ai.vertexaioptions.md + - title: VideoMetadata + path: /docs/reference/js/ai.videometadata.md + - title: WebAttribution + path: /docs/reference/js/ai.webattribution.md - title: analytics path: /docs/reference/js/analytics.md section: diff --git a/docs-devsite/index.md b/docs-devsite/index.md index af34d0d0250..9c8cb7b089e 100644 --- a/docs-devsite/index.md +++ b/docs-devsite/index.md @@ -15,6 +15,7 @@ https://github.com/firebase/firebase-js-sdk | Package | Description | | --- | --- | +| [@firebase/ai](./ai.md#ai_package) | The Firebase AI Web SDK. | | [@firebase/analytics](./analytics.md#analytics_package) | The Firebase Analytics Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/app](./app.md#app_package) | Firebase App | | [@firebase/app-check](./app-check.md#app-check_package) | The Firebase App Check Web SDK. | diff --git a/docs-devsite/vertexai.aimodel.md b/docs-devsite/vertexai.aimodel.md index bddc9c8b985..0ff091a0d03 100644 --- a/docs-devsite/vertexai.aimodel.md +++ b/docs-devsite/vertexai.aimodel.md @@ -12,7 +12,7 @@ https://github.com/firebase/firebase-js-sdk # AIModel class Base class for Firebase AI model APIs. -Instances of this class are associated with a specific Firebase AI backend (either the Vertex AI Gemini API or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. +Instances of this class are associated with a specific Firebase AI [Backend](./vertexai.backend.md#backend_class) and provide methods for interacting with the configured generative model. The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `AIModel` class. diff --git a/docs-devsite/vertexai.backend.md b/docs-devsite/vertexai.backend.md index fe568087c77..e6a2606901e 100644 --- a/docs-devsite/vertexai.backend.md +++ b/docs-devsite/vertexai.backend.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # Backend class -Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Vertex AI Gemini API. +Abstract base class representing the configuration for an AI service backend. This class should not be instantiated directly. Use its subclasses; [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) for the Gemini Developer API (via [Google AI](https://ai.google/)), and [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) for the Vertex AI Gemini API. Signature: @@ -44,7 +44,7 @@ protected constructor(type: BackendType); | Parameter | Type | Description | | --- | --- | --- | -| type | [BackendType](./vertexai.md#backendtype) | The specific backend type constant (e.g., BackendType.GOOGLE\_AI). | +| type | [BackendType](./vertexai.md#backendtype) | The backend type. | ## Backend.backendType diff --git a/docs-devsite/vertexai.googleaibackend.md b/docs-devsite/vertexai.googleaibackend.md index 79b115f78cd..33371c1450f 100644 --- a/docs-devsite/vertexai.googleaibackend.md +++ b/docs-devsite/vertexai.googleaibackend.md @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # GoogleAIBackend class -Configuration class for the Gemini Developer API (using Google AI). +Configuration class for the Gemini Developer API (using [Google AI](https://ai.google/)). Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini Developer API as the backend. diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index ad6c433fa25..4b437c2751f 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -28,13 +28,13 @@ The Firebase AI Web SDK. | Class | Description | | --- | --- | | [AIError](./vertexai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. | -| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.Instances of this class are associated with a specific Firebase AI backend (either the Vertex AI Gemini API or the Gemini Developer API via Google AI) and provide methods for interacting with the configured generative model. | +| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.Instances of this class are associated with a specific Firebase AI [Backend](./vertexai.backend.md#backend_class) and provide methods for interacting with the configured generative model. | | [ArraySchema](./vertexai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | -| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend, determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. This class should not be instantiated directly. Use its subclasses: - [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class): For the Gemini Developer API (via Google AI). - [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class): For the Vertex AI Gemini API. | +| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend. This class should not be instantiated directly. Use its subclasses; [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) for the Gemini Developer API (via [Google AI](https://ai.google/)), and [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) for the Vertex AI Gemini API. | | [BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | | [ChatSession](./vertexai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | | [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | -| [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) | Configuration class for the Gemini Developer API (using Google AI).Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini Developer API as the backend. | +| [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) | Configuration class for the Gemini Developer API (using [Google AI](https://ai.google/)).Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini Developer API as the backend. | | [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) Defines the image format for images generated by Imagen.Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface). | | [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) | (Public Preview) Class for Imagen model APIs.This class provides methods for generating images using the Imagen model. | | [IntegerSchema](./vertexai.integerschema.md#integerschema_class) | Schema class for "integer" types. | diff --git a/packages/vertexai/src/backend.ts b/packages/vertexai/src/backend.ts index 7dc80ac3b02..ce944020f4f 100644 --- a/packages/vertexai/src/backend.ts +++ b/packages/vertexai/src/backend.ts @@ -19,11 +19,10 @@ import { DEFAULT_LOCATION } from './constants'; import { BackendType } from './public-types'; /** - * Abstract base class representing the configuration for an AI service backend, - * determining whether to use the Gemini Developer API (via Google AI) or the Vertex AI Gemini API. - * This class should not be instantiated directly. Use its subclasses: - * - {@link GoogleAIBackend}: For the Gemini Developer API (via Google AI). - * - {@link VertexAIBackend}: For the Vertex AI Gemini API. + * Abstract base class representing the configuration for an AI service backend. + * This class should not be instantiated directly. Use its subclasses; {@link GoogleAIBackend} for + * the Gemini Developer API (via {@link https://ai.google/ | Google AI}), and + * {@link VertexAIBackend} for the Vertex AI Gemini API. * * @public */ @@ -35,7 +34,7 @@ export abstract class Backend { /** * Protected constructor for use by subclasses. - * @param type - The specific backend type constant (e.g., BackendType.GOOGLE_AI). + * @param type - The backend type. */ protected constructor(type: BackendType) { this.backendType = type; @@ -43,7 +42,7 @@ export abstract class Backend { } /** - * Configuration class for the Gemini Developer API (using Google AI). + * Configuration class for the Gemini Developer API (using {@link https://ai.google/ | Google AI}). * * Use this with {@link AIOptions} when initializing the AI service via * {@link getAI | getAI()} to specify the Gemini Developer API as the backend. diff --git a/packages/vertexai/src/models/ai-model.ts b/packages/vertexai/src/models/ai-model.ts index 1d93fc557a9..084dbe329cc 100644 --- a/packages/vertexai/src/models/ai-model.ts +++ b/packages/vertexai/src/models/ai-model.ts @@ -24,8 +24,7 @@ import { _isFirebaseServerApp } from '@firebase/app'; /** * Base class for Firebase AI model APIs. * - * Instances of this class are associated with a specific Firebase AI backend - * (either the Vertex AI Gemini API or the Gemini Developer API via Google AI) + * Instances of this class are associated with a specific Firebase AI {@link Backend} * and provide methods for interacting with the configured generative model. * * @public diff --git a/packages/vertexai/src/public-types.ts b/packages/vertexai/src/public-types.ts index a82f930b9a8..b12615a81ed 100644 --- a/packages/vertexai/src/public-types.ts +++ b/packages/vertexai/src/public-types.ts @@ -84,7 +84,7 @@ export const BackendType = { VERTEX_AI: 'VERTEX_AI', /** - * Identifies the backend service for the Gemini Developer API (via Google AI). + * Identifies the backend service for the Gemini Developer API ({@link https://ai.google/ | Google AI}). * Use this constant when creating a {@link GoogleAIBackend} configuration. */ GOOGLE_AI: 'GOOGLE_AI' From c4878c1785103d70c725bafb473f56329a1447ba Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Sun, 11 May 2025 14:04:41 -0400 Subject: [PATCH 29/32] update toc --- docs-devsite/_toc.yaml | 149 ----------------------------------------- docs-devsite/index.md | 1 - 2 files changed, 150 deletions(-) diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index ee0235b3627..c507b44ce99 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -1,155 +1,6 @@ toc: - title: firebase path: /docs/reference/js/index -- title: ai - path: /docs/reference/js/ai.md - section: - - title: AI - path: /docs/reference/js/ai.ai.md - - title: AIError - path: /docs/reference/js/ai.aierror.md - - title: AIModel - path: /docs/reference/js/ai.aimodel.md - - title: AIOptions - path: /docs/reference/js/ai.aioptions.md - - title: ArraySchema - path: /docs/reference/js/ai.arrayschema.md - - title: Backend - path: /docs/reference/js/ai.backend.md - - title: BaseParams - path: /docs/reference/js/ai.baseparams.md - - title: BooleanSchema - path: /docs/reference/js/ai.booleanschema.md - - title: ChatSession - path: /docs/reference/js/ai.chatsession.md - - title: Citation - path: /docs/reference/js/ai.citation.md - - title: CitationMetadata - path: /docs/reference/js/ai.citationmetadata.md - - title: Content - path: /docs/reference/js/ai.content.md - - title: CountTokensRequest - path: /docs/reference/js/ai.counttokensrequest.md - - title: CountTokensResponse - path: /docs/reference/js/ai.counttokensresponse.md - - title: CustomErrorData - path: /docs/reference/js/ai.customerrordata.md - - title: Date_2 - path: /docs/reference/js/ai.date_2.md - - title: EnhancedGenerateContentResponse - path: /docs/reference/js/ai.enhancedgeneratecontentresponse.md - - title: ErrorDetails - path: /docs/reference/js/ai.errordetails.md - - title: FileData - path: /docs/reference/js/ai.filedata.md - - title: FileDataPart - path: /docs/reference/js/ai.filedatapart.md - - title: FunctionCall - path: /docs/reference/js/ai.functioncall.md - - title: FunctionCallingConfig - path: /docs/reference/js/ai.functioncallingconfig.md - - title: FunctionCallPart - path: /docs/reference/js/ai.functioncallpart.md - - title: FunctionDeclaration - path: /docs/reference/js/ai.functiondeclaration.md - - title: FunctionDeclarationsTool - path: /docs/reference/js/ai.functiondeclarationstool.md - - title: FunctionResponse - path: /docs/reference/js/ai.functionresponse.md - - title: FunctionResponsePart - path: /docs/reference/js/ai.functionresponsepart.md - - title: GenerateContentCandidate - path: /docs/reference/js/ai.generatecontentcandidate.md - - title: GenerateContentRequest - path: /docs/reference/js/ai.generatecontentrequest.md - - title: GenerateContentResponse - path: /docs/reference/js/ai.generatecontentresponse.md - - title: GenerateContentResult - path: /docs/reference/js/ai.generatecontentresult.md - - title: GenerateContentStreamResult - path: /docs/reference/js/ai.generatecontentstreamresult.md - - title: GenerationConfig - path: /docs/reference/js/ai.generationconfig.md - - title: GenerativeContentBlob - path: /docs/reference/js/ai.generativecontentblob.md - - title: GenerativeModel - path: /docs/reference/js/ai.generativemodel.md - - title: GoogleAIBackend - path: /docs/reference/js/ai.googleaibackend.md - - title: GroundingAttribution - path: /docs/reference/js/ai.groundingattribution.md - - title: GroundingMetadata - path: /docs/reference/js/ai.groundingmetadata.md - - title: ImagenGCSImage - path: /docs/reference/js/ai.imagengcsimage.md - - title: ImagenGenerationConfig - path: /docs/reference/js/ai.imagengenerationconfig.md - - title: ImagenGenerationResponse - path: /docs/reference/js/ai.imagengenerationresponse.md - - title: ImagenImageFormat - path: /docs/reference/js/ai.imagenimageformat.md - - title: ImagenInlineImage - path: /docs/reference/js/ai.imageninlineimage.md - - title: ImagenModel - path: /docs/reference/js/ai.imagenmodel.md - - title: ImagenModelParams - path: /docs/reference/js/ai.imagenmodelparams.md - - title: ImagenSafetySettings - path: /docs/reference/js/ai.imagensafetysettings.md - - title: InlineDataPart - path: /docs/reference/js/ai.inlinedatapart.md - - title: IntegerSchema - path: /docs/reference/js/ai.integerschema.md - - title: ModalityTokenCount - path: /docs/reference/js/ai.modalitytokencount.md - - title: ModelParams - path: /docs/reference/js/ai.modelparams.md - - title: NumberSchema - path: /docs/reference/js/ai.numberschema.md - - title: ObjectSchema - path: /docs/reference/js/ai.objectschema.md - - title: ObjectSchemaInterface - path: /docs/reference/js/ai.objectschemainterface.md - - title: PromptFeedback - path: /docs/reference/js/ai.promptfeedback.md - - title: RequestOptions - path: /docs/reference/js/ai.requestoptions.md - - title: RetrievedContextAttribution - path: /docs/reference/js/ai.retrievedcontextattribution.md - - title: SafetyRating - path: /docs/reference/js/ai.safetyrating.md - - title: SafetySetting - path: /docs/reference/js/ai.safetysetting.md - - title: Schema - path: /docs/reference/js/ai.schema.md - - title: SchemaInterface - path: /docs/reference/js/ai.schemainterface.md - - title: SchemaParams - path: /docs/reference/js/ai.schemaparams.md - - title: SchemaRequest - path: /docs/reference/js/ai.schemarequest.md - - title: SchemaShared - path: /docs/reference/js/ai.schemashared.md - - title: Segment - path: /docs/reference/js/ai.segment.md - - title: StartChatParams - path: /docs/reference/js/ai.startchatparams.md - - title: StringSchema - path: /docs/reference/js/ai.stringschema.md - - title: TextPart - path: /docs/reference/js/ai.textpart.md - - title: ToolConfig - path: /docs/reference/js/ai.toolconfig.md - - title: UsageMetadata - path: /docs/reference/js/ai.usagemetadata.md - - title: VertexAIBackend - path: /docs/reference/js/ai.vertexaibackend.md - - title: VertexAIOptions - path: /docs/reference/js/ai.vertexaioptions.md - - title: VideoMetadata - path: /docs/reference/js/ai.videometadata.md - - title: WebAttribution - path: /docs/reference/js/ai.webattribution.md - title: analytics path: /docs/reference/js/analytics.md section: diff --git a/docs-devsite/index.md b/docs-devsite/index.md index 9c8cb7b089e..af34d0d0250 100644 --- a/docs-devsite/index.md +++ b/docs-devsite/index.md @@ -15,7 +15,6 @@ https://github.com/firebase/firebase-js-sdk | Package | Description | | --- | --- | -| [@firebase/ai](./ai.md#ai_package) | The Firebase AI Web SDK. | | [@firebase/analytics](./analytics.md#analytics_package) | The Firebase Analytics Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/app](./app.md#app_package) | Firebase App | | [@firebase/app-check](./app-check.md#app-check_package) | The Firebase App Check Web SDK. | From ad9782c9a643e6f1eae23fead49adaebaa1c4551 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Sun, 11 May 2025 14:24:24 -0400 Subject: [PATCH 30/32] fix docs --- docs-devsite/_toc.yaml | 298 ++++++++-------- docs-devsite/index.md | 2 +- docs-devsite/vertexai.md | 716 --------------------------------------- 3 files changed, 150 insertions(+), 866 deletions(-) delete mode 100644 docs-devsite/vertexai.md diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index c507b44ce99..b77a6b5910e 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -1,6 +1,155 @@ toc: - title: firebase path: /docs/reference/js/index +- title: ai + path: /docs/reference/js/ai.md + section: + - title: AI + path: /docs/reference/js/ai.ai.md + - title: AIError + path: /docs/reference/js/ai.aierror.md + - title: AIModel + path: /docs/reference/js/ai.aimodel.md + - title: AIOptions + path: /docs/reference/js/ai.aioptions.md + - title: ArraySchema + path: /docs/reference/js/ai.arrayschema.md + - title: Backend + path: /docs/reference/js/ai.backend.md + - title: BaseParams + path: /docs/reference/js/ai.baseparams.md + - title: BooleanSchema + path: /docs/reference/js/ai.booleanschema.md + - title: ChatSession + path: /docs/reference/js/ai.chatsession.md + - title: Citation + path: /docs/reference/js/ai.citation.md + - title: CitationMetadata + path: /docs/reference/js/ai.citationmetadata.md + - title: Content + path: /docs/reference/js/ai.content.md + - title: CountTokensRequest + path: /docs/reference/js/ai.counttokensrequest.md + - title: CountTokensResponse + path: /docs/reference/js/ai.counttokensresponse.md + - title: CustomErrorData + path: /docs/reference/js/ai.customerrordata.md + - title: Date_2 + path: /docs/reference/js/ai.date_2.md + - title: EnhancedGenerateContentResponse + path: /docs/reference/js/ai.enhancedgeneratecontentresponse.md + - title: ErrorDetails + path: /docs/reference/js/ai.errordetails.md + - title: FileData + path: /docs/reference/js/ai.filedata.md + - title: FileDataPart + path: /docs/reference/js/ai.filedatapart.md + - title: FunctionCall + path: /docs/reference/js/ai.functioncall.md + - title: FunctionCallingConfig + path: /docs/reference/js/ai.functioncallingconfig.md + - title: FunctionCallPart + path: /docs/reference/js/ai.functioncallpart.md + - title: FunctionDeclaration + path: /docs/reference/js/ai.functiondeclaration.md + - title: FunctionDeclarationsTool + path: /docs/reference/js/ai.functiondeclarationstool.md + - title: FunctionResponse + path: /docs/reference/js/ai.functionresponse.md + - title: FunctionResponsePart + path: /docs/reference/js/ai.functionresponsepart.md + - title: GenerateContentCandidate + path: /docs/reference/js/ai.generatecontentcandidate.md + - title: GenerateContentRequest + path: /docs/reference/js/ai.generatecontentrequest.md + - title: GenerateContentResponse + path: /docs/reference/js/ai.generatecontentresponse.md + - title: GenerateContentResult + path: /docs/reference/js/ai.generatecontentresult.md + - title: GenerateContentStreamResult + path: /docs/reference/js/ai.generatecontentstreamresult.md + - title: GenerationConfig + path: /docs/reference/js/ai.generationconfig.md + - title: GenerativeContentBlob + path: /docs/reference/js/ai.generativecontentblob.md + - title: GenerativeModel + path: /docs/reference/js/ai.generativemodel.md + - title: GoogleAIBackend + path: /docs/reference/js/ai.googleaibackend.md + - title: GroundingAttribution + path: /docs/reference/js/ai.groundingattribution.md + - title: GroundingMetadata + path: /docs/reference/js/ai.groundingmetadata.md + - title: ImagenGCSImage + path: /docs/reference/js/ai.imagengcsimage.md + - title: ImagenGenerationConfig + path: /docs/reference/js/ai.imagengenerationconfig.md + - title: ImagenGenerationResponse + path: /docs/reference/js/ai.imagengenerationresponse.md + - title: ImagenImageFormat + path: /docs/reference/js/ai.imagenimageformat.md + - title: ImagenInlineImage + path: /docs/reference/js/ai.imageninlineimage.md + - title: ImagenModel + path: /docs/reference/js/ai.imagenmodel.md + - title: ImagenModelParams + path: /docs/reference/js/ai.imagenmodelparams.md + - title: ImagenSafetySettings + path: /docs/reference/js/ai.imagensafetysettings.md + - title: InlineDataPart + path: /docs/reference/js/ai.inlinedatapart.md + - title: IntegerSchema + path: /docs/reference/js/ai.integerschema.md + - title: ModalityTokenCount + path: /docs/reference/js/ai.modalitytokencount.md + - title: ModelParams + path: /docs/reference/js/ai.modelparams.md + - title: NumberSchema + path: /docs/reference/js/ai.numberschema.md + - title: ObjectSchema + path: /docs/reference/js/ai.objectschema.md + - title: ObjectSchemaInterface + path: /docs/reference/js/ai.objectschemainterface.md + - title: PromptFeedback + path: /docs/reference/js/ai.promptfeedback.md + - title: RequestOptions + path: /docs/reference/js/ai.requestoptions.md + - title: RetrievedContextAttribution + path: /docs/reference/js/ai.retrievedcontextattribution.md + - title: SafetyRating + path: /docs/reference/js/ai.safetyrating.md + - title: SafetySetting + path: /docs/reference/js/ai.safetysetting.md + - title: Schema + path: /docs/reference/js/ai.schema.md + - title: SchemaInterface + path: /docs/reference/js/ai.schemainterface.md + - title: SchemaParams + path: /docs/reference/js/ai.schemaparams.md + - title: SchemaRequest + path: /docs/reference/js/ai.schemarequest.md + - title: SchemaShared + path: /docs/reference/js/ai.schemashared.md + - title: Segment + path: /docs/reference/js/ai.segment.md + - title: StartChatParams + path: /docs/reference/js/ai.startchatparams.md + - title: StringSchema + path: /docs/reference/js/ai.stringschema.md + - title: TextPart + path: /docs/reference/js/ai.textpart.md + - title: ToolConfig + path: /docs/reference/js/ai.toolconfig.md + - title: UsageMetadata + path: /docs/reference/js/ai.usagemetadata.md + - title: VertexAIBackend + path: /docs/reference/js/ai.vertexaibackend.md + - title: VertexAIOptions + path: /docs/reference/js/ai.vertexaioptions.md + - title: VideoMetadata + path: /docs/reference/js/ai.videometadata.md + - title: WebAttribution + path: /docs/reference/js/ai.webattribution.md - title: analytics path: /docs/reference/js/analytics.md section: @@ -469,152 +618,3 @@ toc: path: /docs/reference/js/storage.uploadtask.md - title: UploadTaskSnapshot path: /docs/reference/js/storage.uploadtasksnapshot.md -- title: vertexai - path: /docs/reference/js/vertexai.md - section: - - title: AI - path: /docs/reference/js/vertexai.ai.md - - title: AIError - path: /docs/reference/js/vertexai.aierror.md - - title: AIModel - path: /docs/reference/js/vertexai.aimodel.md - - title: AIOptions - path: /docs/reference/js/vertexai.aioptions.md - - title: ArraySchema - path: /docs/reference/js/vertexai.arrayschema.md - - title: Backend - path: /docs/reference/js/vertexai.backend.md - - title: BaseParams - path: /docs/reference/js/vertexai.baseparams.md - - title: BooleanSchema - path: /docs/reference/js/vertexai.booleanschema.md - - title: ChatSession - path: /docs/reference/js/vertexai.chatsession.md - - title: Citation - path: /docs/reference/js/vertexai.citation.md - - title: CitationMetadata - path: /docs/reference/js/vertexai.citationmetadata.md - - title: Content - path: /docs/reference/js/vertexai.content.md - - title: CountTokensRequest - path: /docs/reference/js/vertexai.counttokensrequest.md - - title: CountTokensResponse - path: /docs/reference/js/vertexai.counttokensresponse.md - - title: CustomErrorData - path: /docs/reference/js/vertexai.customerrordata.md - - title: Date_2 - path: /docs/reference/js/vertexai.date_2.md - - title: EnhancedGenerateContentResponse - path: /docs/reference/js/vertexai.enhancedgeneratecontentresponse.md - - title: ErrorDetails - path: /docs/reference/js/vertexai.errordetails.md - - title: FileData - path: /docs/reference/js/vertexai.filedata.md - - title: FileDataPart - path: /docs/reference/js/vertexai.filedatapart.md - - title: FunctionCall - path: /docs/reference/js/vertexai.functioncall.md - - title: FunctionCallingConfig - path: /docs/reference/js/vertexai.functioncallingconfig.md - - title: FunctionCallPart - path: /docs/reference/js/vertexai.functioncallpart.md - - title: FunctionDeclaration - path: /docs/reference/js/vertexai.functiondeclaration.md - - title: FunctionDeclarationsTool - path: /docs/reference/js/vertexai.functiondeclarationstool.md - - title: FunctionResponse - path: /docs/reference/js/vertexai.functionresponse.md - - title: FunctionResponsePart - path: /docs/reference/js/vertexai.functionresponsepart.md - - title: GenerateContentCandidate - path: /docs/reference/js/vertexai.generatecontentcandidate.md - - title: GenerateContentRequest - path: /docs/reference/js/vertexai.generatecontentrequest.md - - title: GenerateContentResponse - path: /docs/reference/js/vertexai.generatecontentresponse.md - - title: GenerateContentResult - path: /docs/reference/js/vertexai.generatecontentresult.md - - title: GenerateContentStreamResult - path: /docs/reference/js/vertexai.generatecontentstreamresult.md - - title: GenerationConfig - path: /docs/reference/js/vertexai.generationconfig.md - - title: GenerativeContentBlob - path: /docs/reference/js/vertexai.generativecontentblob.md - - title: GenerativeModel - path: /docs/reference/js/vertexai.generativemodel.md - - title: GoogleAIBackend - path: /docs/reference/js/vertexai.googleaibackend.md - - title: GroundingAttribution - 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 - path: /docs/reference/js/vertexai.integerschema.md - - title: ModalityTokenCount - path: /docs/reference/js/vertexai.modalitytokencount.md - - title: ModelParams - path: /docs/reference/js/vertexai.modelparams.md - - title: NumberSchema - path: /docs/reference/js/vertexai.numberschema.md - - title: ObjectSchema - path: /docs/reference/js/vertexai.objectschema.md - - title: ObjectSchemaInterface - path: /docs/reference/js/vertexai.objectschemainterface.md - - title: PromptFeedback - path: /docs/reference/js/vertexai.promptfeedback.md - - title: RequestOptions - path: /docs/reference/js/vertexai.requestoptions.md - - title: RetrievedContextAttribution - path: /docs/reference/js/vertexai.retrievedcontextattribution.md - - title: SafetyRating - path: /docs/reference/js/vertexai.safetyrating.md - - title: SafetySetting - path: /docs/reference/js/vertexai.safetysetting.md - - title: Schema - path: /docs/reference/js/vertexai.schema.md - - title: SchemaInterface - path: /docs/reference/js/vertexai.schemainterface.md - - title: SchemaParams - path: /docs/reference/js/vertexai.schemaparams.md - - title: SchemaRequest - path: /docs/reference/js/vertexai.schemarequest.md - - title: SchemaShared - path: /docs/reference/js/vertexai.schemashared.md - - title: Segment - path: /docs/reference/js/vertexai.segment.md - - title: StartChatParams - path: /docs/reference/js/vertexai.startchatparams.md - - title: StringSchema - path: /docs/reference/js/vertexai.stringschema.md - - title: TextPart - path: /docs/reference/js/vertexai.textpart.md - - title: ToolConfig - path: /docs/reference/js/vertexai.toolconfig.md - - title: UsageMetadata - path: /docs/reference/js/vertexai.usagemetadata.md - - title: VertexAIBackend - path: /docs/reference/js/vertexai.vertexaibackend.md - - title: VertexAIOptions - path: /docs/reference/js/vertexai.vertexaioptions.md - - title: VideoMetadata - path: /docs/reference/js/vertexai.videometadata.md - - title: WebAttribution - path: /docs/reference/js/vertexai.webattribution.md diff --git a/docs-devsite/index.md b/docs-devsite/index.md index af34d0d0250..47ec0be16ba 100644 --- a/docs-devsite/index.md +++ b/docs-devsite/index.md @@ -15,6 +15,7 @@ https://github.com/firebase/firebase-js-sdk | Package | Description | | --- | --- | +| [@firebase/ai](./ai.md#ai_package) | The Firebase AI Web SDK. | | [@firebase/analytics](./analytics.md#analytics_package) | The Firebase Analytics Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/app](./app.md#app_package) | Firebase App | | [@firebase/app-check](./app-check.md#app-check_package) | The Firebase App Check Web SDK. | @@ -27,5 +28,4 @@ https://github.com/firebase/firebase-js-sdk | [@firebase/performance](./performance.md#performance_package) | The Firebase Performance Monitoring Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/remote-config](./remote-config.md#remote-config_package) | The Firebase Remote Config Web SDK. This SDK does not work in a Node.js environment. | | [@firebase/storage](./storage.md#storage_package) | Cloud Storage for Firebase | -| [@firebase/vertexai](./vertexai.md#vertexai_package) | The Firebase AI Web SDK. | diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md deleted file mode 100644 index 4b437c2751f..00000000000 --- a/docs-devsite/vertexai.md +++ /dev/null @@ -1,716 +0,0 @@ -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 %} - -# vertexai package -The Firebase AI Web SDK. - -## Functions - -| Function | Description | -| --- | --- | -| function(app, ...) | -| [getAI(app, options)](./vertexai.md#getai_a94a413) | Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. | -| [getVertexAI(app, options)](./vertexai.md#getvertexai_04094cf) | It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413).Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. | -| function(ai, ...) | -| [getGenerativeModel(ai, modelParams, requestOptions)](./vertexai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. | -| [getImagenModel(ai, modelParams, requestOptions)](./vertexai.md#getimagenmodel_e1f6645) | (Public Preview) Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.Only Imagen 3 models (named imagen-3.0-*) are supported. | - -## Classes - -| Class | Description | -| --- | --- | -| [AIError](./vertexai.aierror.md#aierror_class) | Error class for the Firebase AI SDK. | -| [AIModel](./vertexai.aimodel.md#aimodel_class) | Base class for Firebase AI model APIs.Instances of this class are associated with a specific Firebase AI [Backend](./vertexai.backend.md#backend_class) and provide methods for interacting with the configured generative model. | -| [ArraySchema](./vertexai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The items param should refer to the type of item that can be a member of the array. | -| [Backend](./vertexai.backend.md#backend_class) | Abstract base class representing the configuration for an AI service backend. This class should not be instantiated directly. Use its subclasses; [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) for the Gemini Developer API (via [Google AI](https://ai.google/)), and [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) for the Vertex AI Gemini API. | -| [BooleanSchema](./vertexai.booleanschema.md#booleanschema_class) | Schema class for "boolean" types. | -| [ChatSession](./vertexai.chatsession.md#chatsession_class) | ChatSession class that enables sending chat messages and stores history of sent and received messages so far. | -| [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) | Class for generative model APIs. | -| [GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) | Configuration class for the Gemini Developer API (using [Google AI](https://ai.google/)).Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Gemini Developer API as the backend. | -| [ImagenImageFormat](./vertexai.imagenimageformat.md#imagenimageformat_class) | (Public Preview) Defines the image format for images generated by Imagen.Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface). | -| [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) | (Public Preview) Class for Imagen model APIs.This class provides methods for generating images using the Imagen model. | -| [IntegerSchema](./vertexai.integerschema.md#integerschema_class) | Schema class for "integer" types. | -| [NumberSchema](./vertexai.numberschema.md#numberschema_class) | Schema class for "number" types. | -| [ObjectSchema](./vertexai.objectschema.md#objectschema_class) | Schema class for "object" types. The properties param must be a map of Schema objects. | -| [Schema](./vertexai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with JSON.stringify() into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) | -| [StringSchema](./vertexai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. | -| [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Vertex AI Gemini API.Use this with [AIOptions](./vertexai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./vertexai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. | - -## Enumerations - -| Enumeration | Description | -| --- | --- | -| [AIErrorCode](./vertexai.md#aierrorcode) | Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. | -| [BlockReason](./vertexai.md#blockreason) | Reason that a prompt was blocked. | -| [FinishReason](./vertexai.md#finishreason) | Reason that a candidate finished. | -| [FunctionCallingMode](./vertexai.md#functioncallingmode) | | -| [HarmBlockMethod](./vertexai.md#harmblockmethod) | This property is not supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)). | -| [HarmBlockThreshold](./vertexai.md#harmblockthreshold) | Threshold above which a prompt or candidate will be blocked. | -| [HarmCategory](./vertexai.md#harmcategory) | Harm categories that would cause prompts or candidates to be blocked. | -| [HarmProbability](./vertexai.md#harmprobability) | Probability that a prompt or candidate matches a harm category. | -| [HarmSeverity](./vertexai.md#harmseverity) | Harm severity levels. | -| [ImagenAspectRatio](./vertexai.md#imagenaspectratio) | (Public Preview) Aspect ratios for Imagen images.To specify an aspect ratio for generated images, set the aspectRatio property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface).See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. | -| [ImagenPersonFilterLevel](./vertexai.md#imagenpersonfilterlevel) | (Public Preview) A filter level controlling whether generation of images containing people or faces is allowed.See the personGeneration documentation for more details. | -| [ImagenSafetyFilterLevel](./vertexai.md#imagensafetyfilterlevel) | (Public Preview) A filter level controlling how aggressively to filter sensitive content.Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, violence, sexual, derogatory, and toxic). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. | -| [Modality](./vertexai.md#modality) | Content part modality. | -| [SchemaType](./vertexai.md#schematype) | Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) | - -## Interfaces - -| Interface | Description | -| --- | --- | -| [AI](./vertexai.ai.md#ai_interface) | An instance of the Firebase AI SDK.Do not create this instance directly. Instead, use [getAI()](./vertexai.md#getai_a94a413). | -| [AIOptions](./vertexai.aioptions.md#aioptions_interface) | Options for initializing the AI service using [getAI()](./vertexai.md#getai_a94a413). This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) and configuring its specific options (like location for Vertex AI). | -| [BaseParams](./vertexai.baseparams.md#baseparams_interface) | Base parameters for a number of methods. | -| [Citation](./vertexai.citation.md#citation_interface) | A single citation. | -| [CitationMetadata](./vertexai.citationmetadata.md#citationmetadata_interface) | Citation metadata that may be found on a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface). | -| [Content](./vertexai.content.md#content_interface) | Content type for both prompts and response candidates. | -| [CountTokensRequest](./vertexai.counttokensrequest.md#counttokensrequest_interface) | Params for calling [GenerativeModel.countTokens()](./vertexai.generativemodel.md#generativemodelcounttokens) | -| [CountTokensResponse](./vertexai.counttokensresponse.md#counttokensresponse_interface) | Response from calling [GenerativeModel.countTokens()](./vertexai.generativemodel.md#generativemodelcounttokens). | -| [CustomErrorData](./vertexai.customerrordata.md#customerrordata_interface) | Details object that contains data originating from a bad HTTP response. | -| [Date\_2](./vertexai.date_2.md#date_2_interface) | Protobuf google.type.Date | -| [EnhancedGenerateContentResponse](./vertexai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponse_interface) | Response object wrapped with helper methods. | -| [ErrorDetails](./vertexai.errordetails.md#errordetails_interface) | Details object that may be included in an error response. | -| [FileData](./vertexai.filedata.md#filedata_interface) | Data pointing to a file uploaded on Google Cloud Storage. | -| [FileDataPart](./vertexai.filedatapart.md#filedatapart_interface) | Content part interface if the part represents [FileData](./vertexai.filedata.md#filedata_interface) | -| [FunctionCall](./vertexai.functioncall.md#functioncall_interface) | A predicted [FunctionCall](./vertexai.functioncall.md#functioncall_interface) returned from the model that contains a string representing the [FunctionDeclaration.name](./vertexai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing the parameters and their values. | -| [FunctionCallingConfig](./vertexai.functioncallingconfig.md#functioncallingconfig_interface) | | -| [FunctionCallPart](./vertexai.functioncallpart.md#functioncallpart_interface) | Content part interface if the part represents a [FunctionCall](./vertexai.functioncall.md#functioncall_interface). | -| [FunctionDeclaration](./vertexai.functiondeclaration.md#functiondeclaration_interface) | Structured representation of a function declaration as defined by the [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included in this declaration are the function name and parameters. This FunctionDeclaration is a representation of a block of code that can be used as a Tool by the model and executed by the client. | -| [FunctionDeclarationsTool](./vertexai.functiondeclarationstool.md#functiondeclarationstool_interface) | A FunctionDeclarationsTool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. | -| [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface) | The result output from a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) that contains a string representing the [FunctionDeclaration.name](./vertexai.functiondeclaration.md#functiondeclarationname) and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a [FunctionCall](./vertexai.functioncall.md#functioncall_interface) made based on model prediction. | -| [FunctionResponsePart](./vertexai.functionresponsepart.md#functionresponsepart_interface) | Content part interface if the part represents [FunctionResponse](./vertexai.functionresponse.md#functionresponse_interface). | -| [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | A candidate returned as part of a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | -| [GenerateContentRequest](./vertexai.generatecontentrequest.md#generatecontentrequest_interface) | Request sent through [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) | -| [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface) | Individual response from [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) and [GenerativeModel.generateContentStream()](./vertexai.generativemodel.md#generativemodelgeneratecontentstream). generateContentStream() will return one in each chunk until the stream is done. | -| [GenerateContentResult](./vertexai.generatecontentresult.md#generatecontentresult_interface) | Result object returned from [GenerativeModel.generateContent()](./vertexai.generativemodel.md#generativemodelgeneratecontent) call. | -| [GenerateContentStreamResult](./vertexai.generatecontentstreamresult.md#generatecontentstreamresult_interface) | Result object returned from [GenerativeModel.generateContentStream()](./vertexai.generativemodel.md#generativemodelgeneratecontentstream) call. Iterate over stream to get chunks as they come in and/or use the response promise to get the aggregated response when the stream is done. | -| [GenerationConfig](./vertexai.generationconfig.md#generationconfig_interface) | Config options for content-related requests | -| [GenerativeContentBlob](./vertexai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. | -| [GroundingAttribution](./vertexai.groundingattribution.md#groundingattribution_interface) | | -| [GroundingMetadata](./vertexai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. | -| [ImagenGCSImage](./vertexai.imagengcsimage.md#imagengcsimage_interface) | An image generated by Imagen, stored in a Cloud Storage for Firebase bucket.This feature is not available yet. | -| [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface) | (Public Preview) Configuration options for generating images with Imagen.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details. | -| [ImagenGenerationResponse](./vertexai.imagengenerationresponse.md#imagengenerationresponse_interface) | (Public Preview) The response from a request to generate images with Imagen. | -| [ImagenInlineImage](./vertexai.imageninlineimage.md#imageninlineimage_interface) | (Public Preview) An image generated by Imagen, represented as inline data. | -| [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | (Public Preview) Parameters for configuring an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class). | -| [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) Settings for controlling the aggressiveness of filtering out sensitive content.See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details. | -| [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. | -| [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. | -| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). | -| [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. | -| [PromptFeedback](./vertexai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with blockReason and the relevant safetyRatings. | -| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_80bd839). | -| [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | | -| [SafetyRating](./vertexai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./vertexai.generatecontentcandidate.md#generatecontentcandidate_interface) | -| [SafetySetting](./vertexai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. | -| [SchemaInterface](./vertexai.schemainterface.md#schemainterface_interface) | Interface for [Schema](./vertexai.schema.md#schema_class) class. | -| [SchemaParams](./vertexai.schemaparams.md#schemaparams_interface) | Params passed to [Schema](./vertexai.schema.md#schema_class) static methods to create specific [Schema](./vertexai.schema.md#schema_class) classes. | -| [SchemaRequest](./vertexai.schemarequest.md#schemarequest_interface) | Final format for [Schema](./vertexai.schema.md#schema_class) params passed to backend requests. | -| [SchemaShared](./vertexai.schemashared.md#schemashared_interface) | Basic [Schema](./vertexai.schema.md#schema_class) properties shared across several Schema-related types. | -| [Segment](./vertexai.segment.md#segment_interface) | | -| [StartChatParams](./vertexai.startchatparams.md#startchatparams_interface) | Params for [GenerativeModel.startChat()](./vertexai.generativemodel.md#generativemodelstartchat). | -| [TextPart](./vertexai.textpart.md#textpart_interface) | Content part interface if the part represents a text string. | -| [ToolConfig](./vertexai.toolconfig.md#toolconfig_interface) | Tool config. This config is shared for all tools provided in the request. | -| [UsageMetadata](./vertexai.usagemetadata.md#usagemetadata_interface) | Usage metadata about a [GenerateContentResponse](./vertexai.generatecontentresponse.md#generatecontentresponse_interface). | -| [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | Options when initializing the Firebase AI SDK. | -| [VideoMetadata](./vertexai.videometadata.md#videometadata_interface) | Describes the input video content. | -| [WebAttribution](./vertexai.webattribution.md#webattribution_interface) | | - -## Variables - -| Variable | Description | -| --- | --- | -| [BackendType](./vertexai.md#backendtype) | An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with.These values are assigned to the backendType property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. | -| [POSSIBLE\_ROLES](./vertexai.md#possible_roles) | Possible roles. | -| [ResponseModality](./vertexai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | -| [VertexAIError](./vertexai.md#vertexaierror) | Error class for the Firebase AI SDK.For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). | -| [VertexAIModel](./vertexai.md#vertexaimodel) | Base class for Firebase AI model APIs.For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). | - -## Type Aliases - -| Type Alias | Description | -| --- | --- | -| [BackendType](./vertexai.md#backendtype) | Type alias representing valid backend types. It can be either 'VERTEX_AI' or 'GOOGLE_AI'. | -| [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. | -| [ResponseModality](./vertexai.md#responsemodality) | (Public Preview) Generation modalities to be returned in generation responses. | -| [Role](./vertexai.md#role) | Role is the producer of the content. | -| [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. | -| [TypedSchema](./vertexai.md#typedschema) | A type that includes all specific Schema types. | -| [VertexAI](./vertexai.md#vertexai) | An instance of the Firebase AI SDK.For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface) interface. | - -## function(app, ...) - -### getAI(app, options) {:#getai_a94a413} - -Returns the default [AI](./vertexai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). If no instance exists, initializes a new instance with the default settings. - -Signature: - -```typescript -export declare function getAI(app?: FirebaseApp, options?: AIOptions): AI; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | -| options | [AIOptions](./vertexai.aioptions.md#aioptions_interface) | [AIOptions](./vertexai.aioptions.md#aioptions_interface) that configure the AI instance. | - -Returns: - -[AI](./vertexai.ai.md#ai_interface) - -The default [AI](./vertexai.ai.md#ai_interface) instance for the given [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface). - -### Example 1 - - -```javascript -const ai = getAI(app); - -``` - -### Example 2 - - -```javascript -// Get an AI instance configured to use the Gemini Developer API (via Google AI). -const ai = getAI(app, { backend: new GoogleAIBackend() }); - -``` - -### Example 3 - - -```javascript -// Get an AI instance configured to use the Vertex AI Gemini API. -const ai = getAI(app, { backend: new VertexAIBackend() }); - -``` - -### getVertexAI(app, options) {:#getvertexai_04094cf} - -It is recommended to use the new [getAI()](./vertexai.md#getai_a94a413). - -Returns a [VertexAI](./vertexai.md#vertexai) instance for the given app, configured to use the Vertex AI Gemini API. This instance will be configured to use the Vertex AI Gemini API. - -Signature: - -```typescript -export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| app | [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) | The [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface) to use. | -| options | [VertexAIOptions](./vertexai.vertexaioptions.md#vertexaioptions_interface) | Options to configure the Vertex AI instance, including the location. | - -Returns: - -[VertexAI](./vertexai.md#vertexai) - -## function(ai, ...) - -### getGenerativeModel(ai, modelParams, requestOptions) {:#getgenerativemodel_80bd839} - -Returns a [GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. - -Signature: - -```typescript -export declare function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| ai | [AI](./vertexai.ai.md#ai_interface) | | -| modelParams | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | | -| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | | - -Returns: - -[GenerativeModel](./vertexai.generativemodel.md#generativemodel_class) - -### getImagenModel(ai, modelParams, requestOptions) {:#getimagenmodel_e1f6645} - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Returns an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen. - -Only Imagen 3 models (named `imagen-3.0-*`) are supported. - -Signature: - -```typescript -export declare function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| ai | [AI](./vertexai.ai.md#ai_interface) | An [AI](./vertexai.ai.md#ai_interface) instance. | -| modelParams | [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters to use when making Imagen requests. | -| requestOptions | [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. | - -Returns: - -[ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class) - -#### Exceptions - -If the `apiKey` or `projectId` fields are missing in your Firebase config. - -## BackendType - -An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Vertex AI Gemini API or Gemini Developer API) the SDK will communicate with. - -These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class) or [VertexAIBackend](./vertexai.vertexaibackend.md#vertexaibackend_class)) to identify which service to target. - -Signature: - -```typescript -BackendType: { - readonly VERTEX_AI: "VERTEX_AI"; - readonly GOOGLE_AI: "GOOGLE_AI"; -} -``` - -## POSSIBLE\_ROLES - -Possible roles. - -Signature: - -```typescript -POSSIBLE_ROLES: readonly ["user", "model", "function", "system"] -``` - -## ResponseModality - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Generation modalities to be returned in generation responses. - -Signature: - -```typescript -ResponseModality: { - readonly TEXT: "TEXT"; - readonly IMAGE: "IMAGE"; -} -``` - -## VertexAIError - -Error class for the Firebase AI SDK. - -For more information, refer to the documentation for the new [AIError](./vertexai.aierror.md#aierror_class). - -Signature: - -```typescript -VertexAIError: typeof AIError -``` - -## VertexAIModel - -Base class for Firebase AI model APIs. - -For more information, refer to the documentation for the new [AIModel](./vertexai.aimodel.md#aimodel_class). - -Signature: - -```typescript -VertexAIModel: typeof AIModel -``` - -## BackendType - -Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. - -Signature: - -```typescript -export type BackendType = (typeof BackendType)[keyof typeof BackendType]; -``` - -## Part - -Content part - includes text, image/video, or function call/response part types. - -Signature: - -```typescript -export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; -``` - -## ResponseModality - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Generation modalities to be returned in generation responses. - -Signature: - -```typescript -export type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality]; -``` - -## Role - -Role is the producer of the content. - -Signature: - -```typescript -export type Role = (typeof POSSIBLE_ROLES)[number]; -``` - -## Tool - -Defines a tool that model can call to access external knowledge. - -Signature: - -```typescript -export declare type Tool = FunctionDeclarationsTool; -``` - -## TypedSchema - -A type that includes all specific Schema types. - -Signature: - -```typescript -export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; -``` - -## VertexAI - -An instance of the Firebase AI SDK. - -For more information, refer to the documentation for the new [AI](./vertexai.ai.md#ai_interface) interface. - -Signature: - -```typescript -export type VertexAI = AI; -``` - -## AIErrorCode - -Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. - -Signature: - -```typescript -export declare const enum AIErrorCode -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| API\_NOT\_ENABLED | "api-not-enabled" | An error due to the Firebase API not being enabled in the Console. | -| ERROR | "error" | A generic error occurred. | -| FETCH\_ERROR | "fetch-error" | An error occurred while performing a fetch. | -| INVALID\_CONTENT | "invalid-content" | An error associated with a Content object. | -| INVALID\_SCHEMA | "invalid-schema" | An error due to invalid Schema input. | -| NO\_API\_KEY | "no-api-key" | An error occurred due to a missing Firebase API key. | -| NO\_APP\_ID | "no-app-id" | An error occured due to a missing Firebase app ID. | -| NO\_MODEL | "no-model" | An error occurred due to a model name not being specified during initialization. | -| NO\_PROJECT\_ID | "no-project-id" | An error occurred due to a missing project ID. | -| PARSE\_FAILED | "parse-failed" | An error occurred while parsing. | -| REQUEST\_ERROR | "request-error" | An error occurred in a request. | -| RESPONSE\_ERROR | "response-error" | An error occurred in a response. | -| UNSUPPORTED | "unsupported" | An error occured due an attempt to use an unsupported feature. | - -## BlockReason - -Reason that a prompt was blocked. - -Signature: - -```typescript -export declare enum BlockReason -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCKLIST | "BLOCKLIST" | Content was blocked because it contained terms from the terminology blocklist. | -| OTHER | "OTHER" | Content was blocked, but the reason is uncategorized. | -| PROHIBITED\_CONTENT | "PROHIBITED_CONTENT" | Content was blocked due to prohibited content. | -| SAFETY | "SAFETY" | Content was blocked by safety settings. | - -## FinishReason - -Reason that a candidate finished. - -Signature: - -```typescript -export declare enum FinishReason -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCKLIST | "BLOCKLIST" | The candidate content contained forbidden terms. | -| MALFORMED\_FUNCTION\_CALL | "MALFORMED_FUNCTION_CALL" | The function call generated by the model was invalid. | -| MAX\_TOKENS | "MAX_TOKENS" | The maximum number of tokens as specified in the request was reached. | -| OTHER | "OTHER" | Unknown reason. | -| PROHIBITED\_CONTENT | "PROHIBITED_CONTENT" | The candidate content potentially contained prohibited content. | -| RECITATION | "RECITATION" | The candidate content was flagged for recitation reasons. | -| SAFETY | "SAFETY" | The candidate content was flagged for safety reasons. | -| SPII | "SPII" | The candidate content potentially contained Sensitive Personally Identifiable Information (SPII). | -| STOP | "STOP" | Natural stop point of the model or provided stop sequence. | - -## FunctionCallingMode - - -Signature: - -```typescript -export declare enum FunctionCallingMode -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ANY | "ANY" | Model is constrained to always predicting a function call only. If allowed_function_names is set, the predicted function call will be limited to any one of allowed_function_names, else the predicted function call will be any one of the provided function_declarations. | -| AUTO | "AUTO" | Default model behavior; model decides to predict either a function call or a natural language response. | -| NONE | "NONE" | Model will not predict any function call. Model behavior is same as when not passing any function declarations. | - -## HarmBlockMethod - -This property is not supported in the Gemini Developer API ([GoogleAIBackend](./vertexai.googleaibackend.md#googleaibackend_class)). - -Signature: - -```typescript -export declare enum HarmBlockMethod -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| PROBABILITY | "PROBABILITY" | The harm block method uses the probability score. | -| SEVERITY | "SEVERITY" | The harm block method uses both probability and severity scores. | - -## HarmBlockThreshold - -Threshold above which a prompt or candidate will be blocked. - -Signature: - -```typescript -export declare enum HarmBlockThreshold -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCK\_LOW\_AND\_ABOVE | "BLOCK_LOW_AND_ABOVE" | Content with NEGLIGIBLE will be allowed. | -| BLOCK\_MEDIUM\_AND\_ABOVE | "BLOCK_MEDIUM_AND_ABOVE" | Content with NEGLIGIBLE and LOW will be allowed. | -| BLOCK\_NONE | "BLOCK_NONE" | All content will be allowed. | -| BLOCK\_ONLY\_HIGH | "BLOCK_ONLY_HIGH" | Content with NEGLIGIBLE, LOW, and MEDIUM will be allowed. | - -## HarmCategory - -Harm categories that would cause prompts or candidates to be blocked. - -Signature: - -```typescript -export declare enum HarmCategory -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HARM\_CATEGORY\_DANGEROUS\_CONTENT | "HARM_CATEGORY_DANGEROUS_CONTENT" | | -| HARM\_CATEGORY\_HARASSMENT | "HARM_CATEGORY_HARASSMENT" | | -| HARM\_CATEGORY\_HATE\_SPEECH | "HARM_CATEGORY_HATE_SPEECH" | | -| HARM\_CATEGORY\_SEXUALLY\_EXPLICIT | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | | - -## HarmProbability - -Probability that a prompt or candidate matches a harm category. - -Signature: - -```typescript -export declare enum HarmProbability -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HIGH | "HIGH" | Content has a high chance of being unsafe. | -| LOW | "LOW" | Content has a low chance of being unsafe. | -| MEDIUM | "MEDIUM" | Content has a medium chance of being unsafe. | -| NEGLIGIBLE | "NEGLIGIBLE" | Content has a negligible chance of being unsafe. | - -## HarmSeverity - -Harm severity levels. - -Signature: - -```typescript -export declare enum HarmSeverity -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| HARM\_SEVERITY\_HIGH | "HARM_SEVERITY_HIGH" | High level of harm severity. | -| HARM\_SEVERITY\_LOW | "HARM_SEVERITY_LOW" | Low level of harm severity. | -| HARM\_SEVERITY\_MEDIUM | "HARM_SEVERITY_MEDIUM" | Medium level of harm severity. | -| HARM\_SEVERITY\_NEGLIGIBLE | "HARM_SEVERITY_NEGLIGIBLE" | Negligible level of harm severity. | -| HARM\_SEVERITY\_UNSUPPORTED | "HARM_SEVERITY_UNSUPPORTED" | Harm severity is not supported. | - -## ImagenAspectRatio - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Aspect ratios for Imagen images. - -To specify an aspect ratio for generated images, set the `aspectRatio` property in your [ImagenGenerationConfig](./vertexai.imagengenerationconfig.md#imagengenerationconfig_interface). - -See the the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios. - -Signature: - -```typescript -export declare enum ImagenAspectRatio -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| LANDSCAPE\_16x9 | "16:9" | (Public Preview) Landscape (16:9) aspect ratio. | -| LANDSCAPE\_3x4 | "3:4" | (Public Preview) Landscape (3:4) aspect ratio. | -| PORTRAIT\_4x3 | "4:3" | (Public Preview) Portrait (4:3) aspect ratio. | -| PORTRAIT\_9x16 | "9:16" | (Public Preview) Portrait (9:16) aspect ratio. | -| SQUARE | "1:1" | (Public Preview) Square (1:1) aspect ratio. | - -## ImagenPersonFilterLevel - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -A filter level controlling whether generation of images containing people or faces is allowed. - -See the personGeneration documentation for more details. - -Signature: - -```typescript -export declare enum ImagenPersonFilterLevel -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ALLOW\_ADULT | "allow_adult" | (Public Preview) Allow generation of images containing adults only; images of children are filtered out.Generation of images containing people or faces may require your use case to be reviewed and approved by Cloud support; see the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) for more details. | -| ALLOW\_ALL | "allow_all" | (Public Preview) Allow generation of images containing adults only; images of children are filtered out.Generation of images containing people or faces may require your use case to be reviewed and approved by Cloud support; see the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen) for more details. | -| BLOCK\_ALL | "dont_allow" | (Public Preview) Disallow generation of images containing people or faces; images of people are filtered out. | - -## ImagenSafetyFilterLevel - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -A filter level controlling how aggressively to filter sensitive content. - -Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI are assessed against a list of safety filters, which include 'harmful categories' (for example, `violence`, `sexual`, `derogatory`, and `toxic`). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) and the [Responsible AI and usage guidelines](https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters) for more details. - -Signature: - -```typescript -export declare enum ImagenSafetyFilterLevel -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| BLOCK\_LOW\_AND\_ABOVE | "block_low_and_above" | (Public Preview) The most aggressive filtering level; most strict blocking. | -| BLOCK\_MEDIUM\_AND\_ABOVE | "block_medium_and_above" | (Public Preview) Blocks some sensitive prompts and responses. | -| BLOCK\_NONE | "block_none" | (Public Preview) The least aggressive filtering level; blocks very few sensitive prompts and responses.Access to this feature is restricted and may require your case to be reviewed and approved by Cloud support. | -| BLOCK\_ONLY\_HIGH | "block_only_high" | (Public Preview) Blocks few sensitive prompts and responses. | - -## Modality - -Content part modality. - -Signature: - -```typescript -export declare enum Modality -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| AUDIO | "AUDIO" | Audio. | -| DOCUMENT | "DOCUMENT" | Document (for example, PDF). | -| IMAGE | "IMAGE" | Image. | -| MODALITY\_UNSPECIFIED | "MODALITY_UNSPECIFIED" | Unspecified modality. | -| TEXT | "TEXT" | Plain text. | -| VIDEO | "VIDEO" | Video. | - -## SchemaType - -Contains the list of OpenAPI data types as defined by the [OpenAPI specification](https://swagger.io/docs/specification/data-models/data-types/) - -Signature: - -```typescript -export declare enum SchemaType -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| ARRAY | "array" | Array type. | -| BOOLEAN | "boolean" | Boolean type. | -| INTEGER | "integer" | Integer type. | -| NUMBER | "number" | Number type. | -| OBJECT | "object" | Object type. | -| STRING | "string" | String type. | - From e4d99ba7f61dc16d6f833306e7d9c11905f1d18c Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Mon, 12 May 2025 16:19:14 -0400 Subject: [PATCH 31/32] formatting --- packages/firebase/ai/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase/ai/index.ts b/packages/firebase/ai/index.ts index 4e8133e1862..ea092d0f6e9 100644 --- a/packages/firebase/ai/index.ts +++ b/packages/firebase/ai/index.ts @@ -15,4 +15,4 @@ * limitations under the License. */ -export * from '@firebase/ai' \ No newline at end of file +export * from '@firebase/ai'; From 5a60ac35ea5034e27958dcd16314569ed71d9002 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Mon, 12 May 2025 16:23:52 -0400 Subject: [PATCH 32/32] Update changesets to use new @firebase/ai tag --- .changeset/fast-mangos-chew.md | 2 +- .changeset/perfect-camels-try.md | 2 +- .changeset/tall-zoos-stare.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.changeset/fast-mangos-chew.md b/.changeset/fast-mangos-chew.md index c5d2e4b4d1f..4e1f7ab3121 100644 --- a/.changeset/fast-mangos-chew.md +++ b/.changeset/fast-mangos-chew.md @@ -1,5 +1,5 @@ --- -'@firebase/vertexai': patch +'@firebase/ai': patch --- Pass `GenerativeModel`'s `BaseParams` to created chat sessions. This fixes an issue where `GenerationConfig` would not be inherited from `ChatSession`. diff --git a/.changeset/perfect-camels-try.md b/.changeset/perfect-camels-try.md index 409a598531d..52292807f0a 100644 --- a/.changeset/perfect-camels-try.md +++ b/.changeset/perfect-camels-try.md @@ -1,6 +1,6 @@ --- 'firebase': minor -'@firebase/vertexai': minor +'@firebase/ai': minor --- Add support for Gemini multimodal output diff --git a/.changeset/tall-zoos-stare.md b/.changeset/tall-zoos-stare.md index 2711107986c..96d480762ea 100644 --- a/.changeset/tall-zoos-stare.md +++ b/.changeset/tall-zoos-stare.md @@ -1,6 +1,6 @@ --- 'firebase': minor -'@firebase/vertexai': minor +'@firebase/ai': minor --- Add support for the Gemini Developer API, enabling usage in a free tier, and add new `AI` API to accomodate new product naming.