From fce2470e8703c05a564278d7f9ded35bc7ac89ed Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 27 May 2025 11:09:19 -0400 Subject: [PATCH] feat!(ai): remove vertexai APIs BREAKING CHANGE --- common/api-review/ai.api.md | 24 +----- docs-devsite/_toc.yaml | 2 - docs-devsite/ai.md | 76 ----------------- docs-devsite/ai.vertexaioptions.md | 33 ------- packages/ai/src/api.ts | 57 +------------ .../ai/src/backwards-compatbility.test.ts | 85 ------------------- packages/ai/src/public-types.ts | 20 ----- 7 files changed, 3 insertions(+), 294 deletions(-) delete mode 100644 docs-devsite/ai.vertexaioptions.md delete mode 100644 packages/ai/src/backwards-compatbility.test.ts diff --git a/common/api-review/ai.api.md b/common/api-review/ai.api.md index 523b51d7533..3e3295832ae 100644 --- a/common/api-review/ai.api.md +++ b/common/api-review/ai.api.md @@ -27,7 +27,7 @@ export class AIError extends FirebaseError { } // @public -const enum AIErrorCode { +export const enum AIErrorCode { API_NOT_ENABLED = "api-not-enabled", ERROR = "error", FETCH_ERROR = "fetch-error", @@ -43,10 +43,6 @@ const enum AIErrorCode { UNSUPPORTED = "unsupported" } -export { AIErrorCode } - -export { AIErrorCode as VertexAIErrorCode } - // @public export abstract class AIModel { // @internal @@ -423,9 +419,6 @@ export function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOpti // @beta export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel; -// @public @deprecated (undocumented) -export function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions): VertexAI; - // @public export class GoogleAIBackend extends Backend { constructor(); @@ -921,27 +914,12 @@ export interface UsageMetadata { totalTokenCount: number; } -// @public @deprecated (undocumented) -export type VertexAI = AI; - // @public export class VertexAIBackend extends Backend { constructor(location?: string); readonly location: string; } -// @public @deprecated (undocumented) -export const VertexAIError: typeof AIError; - -// @public @deprecated (undocumented) -export const VertexAIModel: typeof AIModel; - -// @public -export interface VertexAIOptions { - // (undocumented) - location?: string; -} - // @public export interface VideoMetadata { endOffset: string; diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index b77a6b5910e..b53ecc0ffd7 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -144,8 +144,6 @@ toc: 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 diff --git a/docs-devsite/ai.md b/docs-devsite/ai.md index 286c8351fd7..cc1e34e6daf 100644 --- a/docs-devsite/ai.md +++ b/docs-devsite/ai.md @@ -18,7 +18,6 @@ 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) | | | 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. | @@ -121,7 +120,6 @@ The Firebase AI Web SDK. | [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) | | @@ -132,8 +130,6 @@ 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) | | -| [VertexAIModel](./ai.md#vertexaimodel) | | ## Type Aliases @@ -145,7 +141,6 @@ 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) | | ## function(app, ...) @@ -198,32 +193,6 @@ const ai = getAI(app, { backend: new VertexAIBackend() }); ``` -### getVertexAI(app, options) {:#getvertexai_04094cf} - -> 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: - -```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} @@ -320,36 +289,6 @@ ResponseModality: { } ``` -## VertexAIError - -> 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: - -```typescript -VertexAIError: typeof AIError -``` - -## VertexAIModel - -> 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: - -```typescript -VertexAIModel: typeof AIModel -``` - ## BackendType Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`. @@ -413,21 +352,6 @@ A type that includes all specific Schema types. export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; ``` -## VertexAI - -> 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: - -```typescript -export type VertexAI = AI; -``` - ## AIErrorCode Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. diff --git a/docs-devsite/ai.vertexaioptions.md b/docs-devsite/ai.vertexaioptions.md deleted file mode 100644 index 311fa4785f7..00000000000 --- a/docs-devsite/ai.vertexaioptions.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 %} - -# VertexAIOptions interface -Options when initializing the Firebase AI SDK. - -Signature: - -```typescript -export interface VertexAIOptions -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [location](./ai.vertexaioptions.md#vertexaioptionslocation) | string | | - -## VertexAIOptions.location - -Signature: - -```typescript -location?: string; -``` diff --git a/packages/ai/src/api.ts b/packages/ai/src/api.ts index d2229c067fc..e9264262145 100644 --- a/packages/ai/src/api.ts +++ b/packages/ai/src/api.ts @@ -20,7 +20,7 @@ import { Provider } from '@firebase/component'; import { getModularInstance } from '@firebase/util'; import { AI_TYPE } from './constants'; import { AIService } from './service'; -import { AI, AIOptions, VertexAI, VertexAIOptions } from './public-types'; +import { AI, AIOptions } from './public-types'; import { ImagenModelParams, ModelParams, @@ -30,7 +30,7 @@ import { import { AIError } from './errors'; import { AIModel, GenerativeModel, ImagenModel } from './models'; import { encodeInstanceIdentifier } from './helpers'; -import { GoogleAIBackend, VertexAIBackend } from './backend'; +import { GoogleAIBackend } from './backend'; export { ChatSession } from './methods/chat-session'; export * from './requests/schema-builder'; @@ -38,65 +38,12 @@ export { ImagenImageFormat } from './requests/imagen-image-format'; export { AIModel, GenerativeModel, ImagenModel, AIError }; 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. - * - * @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. - * - * @public - */ -export const VertexAIError = AIError; - declare module '@firebase/component' { interface NameServiceMapping { [AI_TYPE]: AIService; } } -/** - * @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 - * 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. - * - * @public - */ -export function getVertexAI( - app: FirebaseApp = getApp(), - options?: VertexAIOptions -): VertexAI { - app = getModularInstance(app); - // Dependencies - const AIProvider: Provider<'AI'> = _getProvider(app, AI_TYPE); - - const backend = new VertexAIBackend(options?.location); - const identifier = encodeInstanceIdentifier(backend); - return AIProvider.getImmediate({ - identifier - }); -} - /** * 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 diff --git a/packages/ai/src/backwards-compatbility.test.ts b/packages/ai/src/backwards-compatbility.test.ts deleted file mode 100644 index 62463009b24..00000000000 --- a/packages/ai/src/backwards-compatbility.test.ts +++ /dev/null @@ -1,85 +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 { expect } from 'chai'; -import { - AIError, - AIModel, - GenerativeModel, - VertexAIError, - VertexAIErrorCode, - VertexAIModel, - getGenerativeModel, - getImagenModel -} from './api'; -import { AI, VertexAI, AIErrorCode } from './public-types'; -import { VertexAIBackend } from './backend'; - -function assertAssignable(): void {} - -const fakeAI: AI = { - app: { - name: 'DEFAULT', - automaticDataCollectionEnabled: true, - options: { - apiKey: 'key', - projectId: 'my-project', - appId: 'app-id' - } - }, - backend: new VertexAIBackend('us-central1'), - location: 'us-central1' -}; - -const fakeVertexAI: VertexAI = fakeAI; - -describe('backwards-compatible types', () => { - it('AI is backwards compatible with VertexAI', () => { - assertAssignable(); - }); - it('AIError is backwards compatible with VertexAIError', () => { - assertAssignable(); - const err = new VertexAIError(VertexAIErrorCode.ERROR, ''); - expect(err).instanceOf(AIError); - expect(err).instanceOf(VertexAIError); - }); - it('AIErrorCode is backwards compatible with VertexAIErrorCode', () => { - assertAssignable(); - const errCode = AIErrorCode.ERROR; - expect(errCode).to.equal(VertexAIErrorCode.ERROR); - }); - it('AIModel is backwards compatible with VertexAIModel', () => { - assertAssignable(); - - const model = new GenerativeModel(fakeAI, { model: 'model-name' }); - expect(model).to.be.instanceOf(AIModel); - expect(model).to.be.instanceOf(VertexAIModel); - }); -}); - -describe('backward-compatible functions', () => { - it('getGenerativeModel', () => { - const model = getGenerativeModel(fakeVertexAI, { model: 'model-name' }); - 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(AIModel); - expect(model).to.be.instanceOf(VertexAIModel); - }); -}); diff --git a/packages/ai/src/public-types.ts b/packages/ai/src/public-types.ts index 7a5b7dc3997..57812f20c1e 100644 --- a/packages/ai/src/public-types.ts +++ b/packages/ai/src/public-types.ts @@ -20,26 +20,6 @@ import { Backend } from './backend'; export * from './types'; -/** - * @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}. - * - * An instance of the Firebase AI SDK. - * - * @public - */ -export type VertexAI = AI; - -/** - * Options when initializing the Firebase AI SDK. - * - * @public - */ -export interface VertexAIOptions { - location?: string; -} - /** * An instance of the Firebase AI SDK. *