mirror of
https://github.com/hanzoai/firebase-js-sdk.git
synced 2026-09-24 16:59:10 +00:00
feat(ai): Add AgentPlatformBackend and deprecate VertexAIBackend (#10184)
This commit is contained in:
committed by
GitHub
parent
722b4d5ebe
commit
811a603573
@@ -0,0 +1,8 @@
|
||||
---
|
||||
'@firebase/ai': minor
|
||||
'firebase': minor
|
||||
---
|
||||
|
||||
Deprecated `VertexAIBackend` in favor of `AgentPlatformBackend` to reflect the renaming of Vertex AI to Gemini Enterprise Agent Platform.
|
||||
|
||||
The only difference for `AgentPlatformBackend` is the default [location for accessing the model](https://firebase.google.com/docs/ai-logic/locations?api=vertex). The default location for `AgentPlatformBackend` is `global`, whereas the default location for `VertexAIBackend` is `us-central1`. To use `us-central1` with `AgentPlatformBackend`, specify `getAI(app, { backend: new AgentPlatformBackend('us-central1') })` when initializing the SDK. However, note that most new Gemini models do not support `us-central1`.
|
||||
@@ -9,6 +9,16 @@ import { FirebaseApp } from '@firebase/app';
|
||||
import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
|
||||
import { FirebaseError } from '@firebase/util';
|
||||
|
||||
// @public
|
||||
export class AgentPlatformBackend extends Backend {
|
||||
constructor(location?: string);
|
||||
// @internal (undocumented)
|
||||
_getModelPath(project: string, model: string): string;
|
||||
// @internal (undocumented)
|
||||
_getTemplatePath(project: string, templateId: string): string;
|
||||
readonly location: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface AI {
|
||||
app: FirebaseApp;
|
||||
@@ -108,6 +118,7 @@ export abstract class Backend {
|
||||
|
||||
// @public
|
||||
export const BackendType: {
|
||||
readonly AGENT_PLATFORM: "AGENT_PLATFORM";
|
||||
readonly VERTEX_AI: "VERTEX_AI";
|
||||
readonly GOOGLE_AI: "GOOGLE_AI";
|
||||
};
|
||||
@@ -1712,7 +1723,7 @@ export interface UsageMetadata {
|
||||
totalTokenCount: number;
|
||||
}
|
||||
|
||||
// @public
|
||||
// @public @deprecated
|
||||
export class VertexAIBackend extends Backend {
|
||||
constructor(location?: string);
|
||||
// @internal (undocumented)
|
||||
|
||||
@@ -4,6 +4,8 @@ toc:
|
||||
- title: ai
|
||||
path: /docs/reference/js/ai.md
|
||||
section:
|
||||
- title: AgentPlatformBackend
|
||||
path: /docs/reference/js/ai.agentplatformbackend.md
|
||||
- title: AI
|
||||
path: /docs/reference/js/ai.ai.md
|
||||
- title: AIError
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
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 %}
|
||||
|
||||
# AgentPlatformBackend class
|
||||
Configuration class for the Agent Platform 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 Agent Platform Gemini API as the backend.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare class AgentPlatformBackend extends Backend
|
||||
```
|
||||
<b>Extends:</b> [Backend](./ai.backend.md#backend_class)
|
||||
|
||||
## Constructors
|
||||
|
||||
| Constructor | Modifiers | Description |
|
||||
| --- | --- | --- |
|
||||
| [(constructor)(location)](./ai.agentplatformbackend.md#agentplatformbackendconstructor) | | Creates a configuration object for the Agent Platform backend. |
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Modifiers | Type | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [location](./ai.agentplatformbackend.md#agentplatformbackendlocation) | | string | The region identifier. See [Agent Platform locations](https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations) for a list of supported locations. |
|
||||
|
||||
## AgentPlatformBackend.(constructor)
|
||||
|
||||
Creates a configuration object for the Agent Platform backend.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
constructor(location?: string);
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| location | string | The region identifier, defaulting to <code>global</code>; see [Agent Platform locations](https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations) for a list of supported locations. |
|
||||
|
||||
## AgentPlatformBackend.location
|
||||
|
||||
The region identifier. See [Agent Platform locations](https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations) for a list of supported locations.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
readonly location: string;
|
||||
```
|
||||
@@ -25,7 +25,7 @@ export interface AI
|
||||
| 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)<!-- -->). |
|
||||
| [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 Agent Platform Gemini API (using [AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->). |
|
||||
| [location](./ai.ai.md#ailocation) | string | |
|
||||
| [options](./ai.ai.md#aioptions) | [AIOptions](./ai.aioptions.md#aioptions_interface) | Options applied to this [AI](./ai.ai.md#ai_interface) instance. |
|
||||
|
||||
@@ -41,7 +41,7 @@ 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)<!-- -->).
|
||||
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 Agent Platform Gemini API (using [AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -55,7 +55,7 @@ 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 Agent Platform Gemini API backends.
|
||||
>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
|
||||
{% endcomment %}
|
||||
|
||||
# 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).
|
||||
Options for initializing the AI service using [getAI()](./ai.md#getai_a94a413)<!-- -->. This allows specifying which backend to use (Gemini Developer API or Agent Platform Gemini API) and configuring its specific options (like location for Agent Platform).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -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](./ai.googleaibackend.md#googleaibackend_class) for the Gemini Developer API (via [Google AI](https://ai.google/)<!-- -->), and [VertexAIBackend](./ai.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](./ai.googleaibackend.md#googleaibackend_class) for the Gemini Developer API (via [Google AI](https://ai.google/)<!-- -->) and [AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class) for the Agent Platform Gemini API.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ export interface Citation
|
||||
| --- | --- | --- |
|
||||
| [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)<!-- -->). |
|
||||
| [publicationDate](./ai.citation.md#citationpublicationdate) | Date | The publication date of the cited source, if available.<!-- -->This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_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)<!-- -->). |
|
||||
| [title](./ai.citation.md#citationtitle) | string | The title of the cited source, if available.<!-- -->This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_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](./ai.vertexaibackend.md#vertexaibackend_class)<!-- -->).
|
||||
This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -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](./ai.vertexaibackend.md#vertexaibackend_class)<!-- -->).
|
||||
This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ responseMimeType?: string;
|
||||
|
||||
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.
|
||||
- Multimodal response generation is only supported by some Gemini models and versions; see [model versions](https://firebase.google.com/docs/ai-logic/models)<!-- -->. - Only image generation (`ResponseModality.IMAGE`<!-- -->) is supported.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ https://github.com/firebase/firebase-js-sdk
|
||||
# GoogleMapsTool interface
|
||||
A tool that allows a Gemini model to connect to Google Maps to access and incorporate location-based information into its responses.
|
||||
|
||||
Important: If using Grounding with Google Maps, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
Important: If using Grounding with Google Maps, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -24,13 +24,13 @@ export interface GoogleMapsTool
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [googleMaps](./ai.googlemapstool.md#googlemapstoolgooglemaps) | [GoogleMaps](./ai.googlemaps.md#googlemaps_interface) | Specifies the Google Maps configuration.<!-- -->When using this feature, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
| [googleMaps](./ai.googlemapstool.md#googlemapstoolgooglemaps) | [GoogleMaps](./ai.googlemaps.md#googlemaps_interface) | Specifies the Google Maps configuration.<!-- -->When using this feature, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
|
||||
## GoogleMapsTool.googleMaps
|
||||
|
||||
Specifies the Google Maps configuration.
|
||||
|
||||
When using this feature, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
When using this feature, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ https://github.com/firebase/firebase-js-sdk
|
||||
# GoogleSearchTool interface
|
||||
A tool that allows a Gemini model to connect to Google Search to access and incorporate up-to-date information from the web into its responses.
|
||||
|
||||
Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -24,13 +24,13 @@ export interface GoogleSearchTool
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [googleSearch](./ai.googlesearchtool.md#googlesearchtoolgooglesearch) | [GoogleSearch](./ai.googlesearch.md#googlesearch_interface) | Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options.<!-- -->When using this feature, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
| [googleSearch](./ai.googlesearchtool.md#googlesearchtoolgooglesearch) | [GoogleSearch](./ai.googlesearch.md#googlesearch_interface) | Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options.<!-- -->When using this feature, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
|
||||
## GoogleSearchTool.googleSearch
|
||||
|
||||
Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options.
|
||||
|
||||
When using this feature, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
When using this feature, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ Metadata returned when grounding is enabled.
|
||||
|
||||
Currently, only Grounding with Google Search and Grounding with Google Maps are supported (see [GoogleSearchTool](./ai.googlesearchtool.md#googlesearchtool_interface) and [GoogleMapsTool](./ai.googlemapstool.md#googlemapstool_interface)<!-- -->, respectively).
|
||||
|
||||
Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
|
||||
Important: If using Grounding with Google Maps, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
Important: If using Grounding with Google Maps, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ https://github.com/firebase/firebase-js-sdk
|
||||
|
||||
Configuration options for generating images with Imagen.
|
||||
|
||||
See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details.
|
||||
See the [documentation](http://firebase.google.com/docs/ai-logic/generate-images-imagen) for more details.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -29,11 +29,11 @@ export interface ImagenGenerationConfig
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [addWatermark](./ai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | Whether to add an invisible watermark to generated images.<!-- -->If set to <code>true</code>, an invisible SynthID watermark is embedded in generated images to indicate that they are AI generated. If set to <code>false</code>, watermarking will be disabled.<!-- -->For Imagen 3 models, the default value is <code>true</code>; see the <a href="http://firebase.google.com/docs/vertex-ai/model-parameters#imagen">addWatermark</a> 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. |
|
||||
| [addWatermark](./ai.imagengenerationconfig.md#imagengenerationconfigaddwatermark) | boolean | Whether to add an invisible watermark to generated images.<!-- -->If set to <code>true</code>, an invisible SynthID watermark is embedded in generated images to indicate that they are AI generated. If set to <code>false</code>, watermarking will be disabled.<!-- -->For Imagen 3 models, the default value is <code>true</code>; see the <a href="http://firebase.google.com/docs/ai-logic/model-parameters#imagen">addWatermark</a> 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) | 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) | 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 | 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 <code>imagen-3.0-generate-002</code>. |
|
||||
| [numberOfImages](./ai.imagengenerationconfig.md#imagengenerationconfignumberofimages) | number | 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 <a href="http://firebase.google.com/docs/vertex-ai/model-parameters#imagen">sampleCount</a> documentation for more details. |
|
||||
| [negativePrompt](./ai.imagengenerationconfig.md#imagengenerationconfignegativeprompt) | string | 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/ai-logic/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 <code>imagen-3.0-generate-002</code>. |
|
||||
| [numberOfImages](./ai.imagengenerationconfig.md#imagengenerationconfignumberofimages) | number | 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 <a href="http://firebase.google.com/docs/ai-logic/model-parameters#imagen">sampleCount</a> documentation for more details. |
|
||||
|
||||
## ImagenGenerationConfig.addWatermark
|
||||
|
||||
@@ -41,7 +41,7 @@ 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 <a href="http://firebase.google.com/docs/vertex-ai/model-parameters#imagen">addWatermark</a> documentation for more details.
|
||||
For Imagen 3 models, the default value is `true`<!-- -->; see the <a href="http://firebase.google.com/docs/ai-logic/model-parameters#imagen">addWatermark</a> 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.
|
||||
|
||||
@@ -79,7 +79,7 @@ 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.
|
||||
See the [documentation](http://firebase.google.com/docs/ai-logic/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`<!-- -->.
|
||||
|
||||
@@ -93,7 +93,7 @@ negativePrompt?: string;
|
||||
|
||||
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 <a href="http://firebase.google.com/docs/vertex-ai/model-parameters#imagen">sampleCount</a> documentation for more details.
|
||||
The number of sample images that may be generated in each request depends on the model (typically up to 4); see the <a href="http://firebase.google.com/docs/ai-logic/model-parameters#imagen">sampleCount</a> documentation for more details.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export interface ImagenModelParams
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [generationConfig](./ai.imagenmodelparams.md#imagenmodelparamsgenerationconfig) | [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface) | Configuration options for generating images with Imagen. |
|
||||
| [model](./ai.imagenmodelparams.md#imagenmodelparamsmodel) | string | The Imagen model to use for generating images. For example: <code>imagen-3.0-generate-002</code>.<!-- -->Only Imagen 3 models (named <code>imagen-3.0-*</code>) are supported.<!-- -->See [model versions](https://firebase.google.com/docs/vertex-ai/models) for a full list of supported Imagen 3 models. |
|
||||
| [model](./ai.imagenmodelparams.md#imagenmodelparamsmodel) | string | The Imagen model to use for generating images. For example: <code>imagen-3.0-generate-002</code>.<!-- -->Only Imagen 3 models (named <code>imagen-3.0-*</code>) are supported.<!-- -->See [model versions](https://firebase.google.com/docs/ai-logic/models) for a full list of supported Imagen 3 models. |
|
||||
| [safetySettings](./ai.imagenmodelparams.md#imagenmodelparamssafetysettings) | [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface) | Safety settings for filtering potentially inappropriate content. |
|
||||
|
||||
## ImagenModelParams.generationConfig
|
||||
@@ -47,7 +47,7 @@ The Imagen model to use for generating images. For example: `imagen-3.0-generate
|
||||
|
||||
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.
|
||||
See [model versions](https://firebase.google.com/docs/ai-logic/models) for a full list of supported Imagen 3 models.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ https://github.com/firebase/firebase-js-sdk
|
||||
|
||||
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.
|
||||
See the [documentation](http://firebase.google.com/docs/ai-logic/generate-images) for more details.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
+30
-28
@@ -31,11 +31,12 @@ The Firebase AI Web SDK.
|
||||
|
||||
| Class | Description |
|
||||
| --- | --- |
|
||||
| [AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class) | Configuration class for the Agent Platform 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 Agent Platform Gemini API as the backend. |
|
||||
| [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](./ai.backend.md#backend_class) and provide methods for interacting with the configured generative model. |
|
||||
| [AnyOfSchema](./ai.anyofschema.md#anyofschema_class) | Schema class representing a value that can conform to any of the provided sub-schemas. This is useful when a field can accept multiple distinct types or structures. |
|
||||
| [ArraySchema](./ai.arrayschema.md#arrayschema_class) | Schema class for "array" types. The <code>items</code> 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. This class should not be instantiated directly. Use its subclasses; [GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) for the Gemini Developer API (via [Google AI](https://ai.google/)<!-- -->), and [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class) for the Vertex AI Gemini API. |
|
||||
| [Backend](./ai.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](./ai.googleaibackend.md#googleaibackend_class) for the Gemini Developer API (via [Google AI](https://ai.google/)<!-- -->) and [AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class) for the Agent Platform 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. |
|
||||
| [ChatSessionBase](./ai.chatsessionbase.md#chatsessionbase_class) | Base class for various <code>ChatSession</code> classes that enables sending chat messages and stores history of sent and received messages so far. |
|
||||
@@ -48,18 +49,18 @@ The Firebase AI Web SDK.
|
||||
| [LiveSession](./ai.livesession.md#livesession_class) | <b><i>(Public Preview)</i></b> Represents an active, real-time, bidirectional conversation with the model.<!-- -->This class should only be instantiated by calling [LiveGenerativeModel.connect()](./ai.livegenerativemodel.md#livegenerativemodelconnect)<!-- -->. |
|
||||
| [NumberSchema](./ai.numberschema.md#numberschema_class) | Schema class for "number" types. |
|
||||
| [ObjectSchema](./ai.objectschema.md#objectschema_class) | Schema class for "object" types. The <code>properties</code> param must be a map of <code>Schema</code> 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 <code>JSON.stringify()</code> into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) |
|
||||
| [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 <code>JSON.stringify()</code> into a JSON string accepted by Agent Platform Gemini API and Gemini Developer API 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. |
|
||||
| [TemplateGenerativeModel](./ai.templategenerativemodel.md#templategenerativemodel_class) | <b><i>(Public Preview)</i></b> [GenerativeModel](./ai.generativemodel.md#generativemodel_class) APIs that execute on a server-side template.<!-- -->This class should only be instantiated with [getTemplateGenerativeModel()](./ai.md#gettemplategenerativemodel_9476bbc)<!-- -->. |
|
||||
| [TemplateImagenModel](./ai.templateimagenmodel.md#templateimagenmodel_class) | Class for Imagen model APIs that execute on a server-side template.<!-- -->This class should only be instantiated with [getTemplateImagenModel()](./ai.md#gettemplateimagenmodel_9476bbc)<!-- -->. |
|
||||
| [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. |
|
||||
| [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Agent Platform Gemini API (formerly known as 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 Agent Platform Gemini API as the backend. |
|
||||
|
||||
## 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). |
|
||||
| [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 (Gemini Developer API or Agent Platform Gemini API) and configuring its specific options (like location for Agent Platform). |
|
||||
| [AudioConversationController](./ai.audioconversationcontroller.md#audioconversationcontroller_interface) | <b><i>(Public Preview)</i></b> A controller for managing an active audio conversation. |
|
||||
| [AudioTranscriptionConfig](./ai.audiotranscriptionconfig.md#audiotranscriptionconfig_interface) | The audio transcription configuration. |
|
||||
| [BaseParams](./ai.baseparams.md#baseparams_interface) | Base parameters for a number of methods. |
|
||||
@@ -97,20 +98,20 @@ The Firebase AI Web SDK.
|
||||
| [GenerativeContentBlob](./ai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. |
|
||||
| [GoogleMaps](./ai.googlemaps.md#googlemaps_interface) | Specifies the Google Maps configuration. |
|
||||
| [GoogleMapsGroundingChunk](./ai.googlemapsgroundingchunk.md#googlemapsgroundingchunk_interface) | A grounding chunk from Google Maps.<!-- -->Important: If using Grounding with Google Maps, you are required to comply with the [Service Specific Terms](https://cloud.google.com/terms/service-terms) for "Grounding with Google Maps". |
|
||||
| [GoogleMapsTool](./ai.googlemapstool.md#googlemapstool_interface) | A tool that allows a Gemini model to connect to Google Maps to access and incorporate location-based information into its responses.<!-- -->Important: If using Grounding with Google Maps, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
| [GoogleMapsTool](./ai.googlemapstool.md#googlemapstool_interface) | A tool that allows a Gemini model to connect to Google Maps to access and incorporate location-based information into its responses.<!-- -->Important: If using Grounding with Google Maps, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
| [GoogleSearch](./ai.googlesearch.md#googlesearch_interface) | Specifies the Google Search configuration. |
|
||||
| [GoogleSearchTool](./ai.googlesearchtool.md#googlesearchtool_interface) | A tool that allows a Gemini model to connect to Google Search to access and incorporate up-to-date information from the web into its responses.<!-- -->Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
| [GoogleSearchTool](./ai.googlesearchtool.md#googlesearchtool_interface) | A tool that allows a Gemini model to connect to Google Search to access and incorporate up-to-date information from the web into its responses.<!-- -->Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
| [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface) | Represents a chunk of retrieved data that supports a claim in the model's response. This is part of the grounding information provided when grounding is enabled. |
|
||||
| [GroundingMetadata](./ai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned when grounding is enabled.<!-- -->Currently, only Grounding with Google Search and Grounding with Google Maps are supported (see [GoogleSearchTool](./ai.googlesearchtool.md#googlesearchtool_interface) and [GoogleMapsTool](./ai.googlemapstool.md#googlemapstool_interface)<!-- -->, respectively).<!-- -->Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).<!-- -->Important: If using Grounding with Google Maps, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
| [GroundingMetadata](./ai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned when grounding is enabled.<!-- -->Currently, only Grounding with Google Search and Grounding with Google Maps are supported (see [GoogleSearchTool](./ai.googlesearchtool.md#googlesearchtool_interface) and [GoogleMapsTool](./ai.googlemapstool.md#googlemapstool_interface)<!-- -->, respectively).<!-- -->Important: If using Grounding with Google Search, you are required to comply with the "Grounding with Google Search" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms).<!-- -->Important: If using Grounding with Google Maps, you are required to comply with the "Grounding with Google Maps" usage requirements for your chosen API provider: [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-maps) or Agent Platform Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms) section within the Service Specific Terms). |
|
||||
| [GroundingSupport](./ai.groundingsupport.md#groundingsupport_interface) | Provides information about how a specific segment of the model's response is supported by the retrieved grounding chunks. |
|
||||
| [HybridParams](./ai.hybridparams.md#hybridparams_interface) | Configures hybrid inference. |
|
||||
| [ImageConfig](./ai.imageconfig.md#imageconfig_interface) | Configuration options for generating images with Gemini models. |
|
||||
| [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) | Configuration options for generating images with Imagen.<!-- -->See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details. |
|
||||
| [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface) | Configuration options for generating images with Imagen.<!-- -->See the [documentation](http://firebase.google.com/docs/ai-logic/generate-images-imagen) for more details. |
|
||||
| [ImagenGenerationResponse](./ai.imagengenerationresponse.md#imagengenerationresponse_interface) | The response from a request to generate images with Imagen. |
|
||||
| [ImagenInlineImage](./ai.imageninlineimage.md#imageninlineimage_interface) | An image generated by Imagen, represented as inline data. |
|
||||
| [ImagenModelParams](./ai.imagenmodelparams.md#imagenmodelparams_interface) | Parameters for configuring an [ImagenModel](./ai.imagenmodel.md#imagenmodel_class)<!-- -->. |
|
||||
| [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface) | 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. |
|
||||
| [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface) | Settings for controlling the aggressiveness of filtering out sensitive content.<!-- -->See the [documentation](http://firebase.google.com/docs/ai-logic/generate-images) for more details. |
|
||||
| [InlineDataPart](./ai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. |
|
||||
| [LanguageModelCreateCoreOptions](./ai.languagemodelcreatecoreoptions.md#languagemodelcreatecoreoptions_interface) | Configures the creation of an on-device language model session. |
|
||||
| [LanguageModelCreateOptions](./ai.languagemodelcreateoptions.md#languagemodelcreateoptions_interface) | Configures the creation of an on-device language model session. |
|
||||
@@ -174,7 +175,7 @@ The Firebase AI Web SDK.
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
| [AIErrorCode](./ai.md#aierrorcode) | Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. |
|
||||
| [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 <code>backendType</code> 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. |
|
||||
| [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 (Gemini Developer API or Agent Platform Gemini API) the SDK will communicate with.<!-- -->These values are assigned to the <code>backendType</code> property within the specific backend configuration objects ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) or [AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->) to identify which service to target. |
|
||||
| [BlockReason](./ai.md#blockreason) | Reason that a prompt was blocked. |
|
||||
| [FinishReason](./ai.md#finishreason) | Reason that a candidate finished. |
|
||||
| [FunctionCallingMode](./ai.md#functioncallingmode) | |
|
||||
@@ -185,9 +186,9 @@ The Firebase AI Web SDK.
|
||||
| [HarmSeverity](./ai.md#harmseverity) | Harm severity levels. |
|
||||
| [ImageConfigAspectRatio](./ai.md#imageconfigaspectratio) | Aspect ratios for generated images. |
|
||||
| [ImageConfigImageSize](./ai.md#imageconfigimagesize) | Sizes for generated images. For example, '1K' is 1024px, '2K' is 2048px, and '4K' is 4096px. |
|
||||
| [ImagenAspectRatio](./ai.md#imagenaspectratio) | Aspect ratios for Imagen images.<!-- -->To specify an aspect ratio for generated images, set the <code>aspectRatio</code> property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface)<!-- -->.<!-- -->See 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) | A filter level controlling whether generation of images containing people or faces is allowed.<!-- -->See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a> documentation for more details. |
|
||||
| [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | 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, <code>violence</code>, <code>sexual</code>, <code>derogatory</code>, and <code>toxic</code>). 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. |
|
||||
| [ImagenAspectRatio](./ai.md#imagenaspectratio) | Aspect ratios for Imagen images.<!-- -->To specify an aspect ratio for generated images, set the <code>aspectRatio</code> property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface)<!-- -->.<!-- -->See the [documentation](http://firebase.google.com/docs/ai-logic/generate-images) for more details and examples of the supported aspect ratios. |
|
||||
| [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel) | A filter level controlling whether generation of images containing people or faces is allowed.<!-- -->See the <a href="http://firebase.google.com/docs/ai-logic/generate-images">personGeneration</a> documentation for more details. |
|
||||
| [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | 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, <code>violence</code>, <code>sexual</code>, <code>derogatory</code>, and <code>toxic</code>). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/ai-logic/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. |
|
||||
| [InferenceMode](./ai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. |
|
||||
| [InferenceSource](./ai.md#inferencesource) | Indicates whether inference happened on-device or in-cloud. |
|
||||
| [Language](./ai.md#language) | The programming language of the code. |
|
||||
@@ -205,7 +206,7 @@ The Firebase AI Web SDK.
|
||||
| Type Alias | Description |
|
||||
| --- | --- |
|
||||
| [AIErrorCode](./ai.md#aierrorcode) | Standardized error codes that [AIError](./ai.aierror.md#aierror_class) can have. |
|
||||
| [BackendType](./ai.md#backendtype) | Type alias representing valid backend types. It can be either <code>'VERTEX_AI'</code> or <code>'GOOGLE_AI'</code>. |
|
||||
| [BackendType](./ai.md#backendtype) | Type alias representing valid backend types. It should be either <code>'AGENT_PLATFORM'</code> or <code>'GOOGLE_AI'</code> (<code>'VERTEX_AI'</code> is deprecated). |
|
||||
| [BlockReason](./ai.md#blockreason) | Reason that a prompt was blocked. |
|
||||
| [FinishReason](./ai.md#finishreason) | Reason that a candidate finished. |
|
||||
| [FunctionCallingMode](./ai.md#functioncallingmode) | |
|
||||
@@ -216,9 +217,9 @@ The Firebase AI Web SDK.
|
||||
| [HarmSeverity](./ai.md#harmseverity) | Harm severity levels. |
|
||||
| [ImageConfigAspectRatio](./ai.md#imageconfigaspectratio) | Aspect ratios for generated images. |
|
||||
| [ImageConfigImageSize](./ai.md#imageconfigimagesize) | Sizes for generated images. |
|
||||
| [ImagenAspectRatio](./ai.md#imagenaspectratio) | Aspect ratios for Imagen images.<!-- -->To specify an aspect ratio for generated images, set the <code>aspectRatio</code> property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface)<!-- -->.<!-- -->See 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) | A filter level controlling whether generation of images containing people or faces is allowed.<!-- -->See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a> documentation for more details. |
|
||||
| [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | 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, <code>violence</code>, <code>sexual</code>, <code>derogatory</code>, and <code>toxic</code>). 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. |
|
||||
| [ImagenAspectRatio](./ai.md#imagenaspectratio) | Aspect ratios for Imagen images.<!-- -->To specify an aspect ratio for generated images, set the <code>aspectRatio</code> property in your [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface)<!-- -->.<!-- -->See the [documentation](http://firebase.google.com/docs/ai-logic/generate-images) for more details and examples of the supported aspect ratios. |
|
||||
| [ImagenPersonFilterLevel](./ai.md#imagenpersonfilterlevel) | A filter level controlling whether generation of images containing people or faces is allowed.<!-- -->See the <a href="http://firebase.google.com/docs/ai-logic/generate-images">personGeneration</a> documentation for more details. |
|
||||
| [ImagenSafetyFilterLevel](./ai.md#imagensafetyfilterlevel) | 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, <code>violence</code>, <code>sexual</code>, <code>derogatory</code>, and <code>toxic</code>). This filter level controls how aggressively to filter out potentially harmful content from responses. See the [documentation](http://firebase.google.com/docs/ai-logic/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. |
|
||||
| [InferenceMode](./ai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. |
|
||||
| [InferenceSource](./ai.md#inferencesource) | Indicates whether inference happened on-device or in-cloud. |
|
||||
| [Language](./ai.md#language) | The programming language of the code. |
|
||||
@@ -284,8 +285,8 @@ const ai = getAI(app, { backend: new GoogleAIBackend() });
|
||||
|
||||
|
||||
```javascript
|
||||
// Get an AI instance configured to use the Vertex AI Gemini API.
|
||||
const ai = getAI(app, { backend: new VertexAIBackend() });
|
||||
// Get an AI instance configured to use the Agent Platform Gemini API.
|
||||
const ai = getAI(app, { backend: new AgentPlatformBackend() });
|
||||
|
||||
```
|
||||
|
||||
@@ -523,14 +524,15 @@ AIErrorCode: {
|
||||
|
||||
## 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.
|
||||
An enum-like object containing constants that represent the supported backends for the Firebase AI SDK. This determines which backend service (Gemini Developer API or Agent Platform Gemini 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.
|
||||
These values are assigned to the `backendType` property within the specific backend configuration objects ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class) or [AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->) to identify which service to target.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
BackendType: {
|
||||
readonly AGENT_PLATFORM: "AGENT_PLATFORM";
|
||||
readonly VERTEX_AI: "VERTEX_AI";
|
||||
readonly GOOGLE_AI: "GOOGLE_AI";
|
||||
}
|
||||
@@ -720,7 +722,7 @@ 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 [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios.
|
||||
See the [documentation](http://firebase.google.com/docs/ai-logic/generate-images) for more details and examples of the supported aspect ratios.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -743,7 +745,7 @@ ImagenAspectRatio: {
|
||||
|
||||
A filter level controlling whether generation of images containing people or faces is allowed.
|
||||
|
||||
See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a> documentation for more details.
|
||||
See the <a href="http://firebase.google.com/docs/ai-logic/generate-images">personGeneration</a> documentation for more details.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -764,7 +766,7 @@ ImagenPersonFilterLevel: {
|
||||
|
||||
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.
|
||||
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/ai-logic/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.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -960,7 +962,7 @@ export type AIErrorCode = (typeof AIErrorCode)[keyof typeof AIErrorCode];
|
||||
|
||||
## BackendType
|
||||
|
||||
Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`<!-- -->.
|
||||
Type alias representing valid backend types. It should be either `'AGENT_PLATFORM'` or `'GOOGLE_AI'` (`'VERTEX_AI'` is deprecated).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -1078,7 +1080,7 @@ 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 [documentation](http://firebase.google.com/docs/vertex-ai/generate-images) for more details and examples of the supported aspect ratios.
|
||||
See the [documentation](http://firebase.google.com/docs/ai-logic/generate-images) for more details and examples of the supported aspect ratios.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -1095,7 +1097,7 @@ export type ImagenAspectRatio = (typeof ImagenAspectRatio)[keyof typeof ImagenAs
|
||||
|
||||
A filter level controlling whether generation of images containing people or faces is allowed.
|
||||
|
||||
See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a> documentation for more details.
|
||||
See the <a href="http://firebase.google.com/docs/ai-logic/generate-images">personGeneration</a> documentation for more details.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -1112,7 +1114,7 @@ export type ImagenPersonFilterLevel = (typeof ImagenPersonFilterLevel)[keyof typ
|
||||
|
||||
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.
|
||||
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/ai-logic/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.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export interface PromptFeedback
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [blockReason](./ai.promptfeedback.md#promptfeedbackblockreason) | [BlockReason](./ai.md#blockreason) | |
|
||||
| [blockReasonMessage](./ai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | A human-readable description of the <code>blockReason</code>.<!-- -->This property is only supported in the Vertex AI Gemini API ([VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class)<!-- -->). |
|
||||
| [blockReasonMessage](./ai.promptfeedback.md#promptfeedbackblockreasonmessage) | string | A human-readable description of the <code>blockReason</code>.<!-- -->This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_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](./ai.vertexaibackend.md#vertexaibackend_class)<!-- -->).
|
||||
This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ export interface SafetyRating
|
||||
| [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 <code>HarmSeverity.UNSUPPORTED</code>. |
|
||||
| [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. |
|
||||
| [probabilityScore](./ai.safetyrating.md#safetyratingprobabilityscore) | number | The probability score of the harm category.<!-- -->This property is only supported when using the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_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 Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->), this property is not supported and will default to <code>HarmSeverity.UNSUPPORTED</code>. |
|
||||
| [severityScore](./ai.safetyrating.md#safetyratingseverityscore) | number | The severity score of the harm category.<!-- -->This property is only supported when using the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_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
|
||||
|
||||
@@ -57,7 +57,7 @@ probability: HarmProbability;
|
||||
|
||||
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.
|
||||
This property is only supported when using the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->), this property is not supported and will default to 0.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -69,7 +69,7 @@ probabilityScore: number;
|
||||
|
||||
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`<!-- -->.
|
||||
This property is only supported when using the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -81,7 +81,7 @@ severity: HarmSeverity;
|
||||
|
||||
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.
|
||||
This property is only supported when using the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->), this property is not supported and will default to 0.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export interface SafetySetting
|
||||
| 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. |
|
||||
| [method](./ai.safetysetting.md#safetysettingmethod) | [HarmBlockMethod](./ai.md#harmblockmethod) | The harm block method.<!-- -->This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_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
|
||||
@@ -38,7 +38,7 @@ category: HarmCategory;
|
||||
|
||||
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.
|
||||
This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_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.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
|
||||
{% endcomment %}
|
||||
|
||||
# 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.)
|
||||
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 Agent Platform Gemini API and Gemini Developer API REST endpoints. (This string conversion is automatically done when calling SDK methods.)
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -10,9 +10,14 @@ https://github.com/firebase/firebase-js-sdk
|
||||
{% endcomment %}
|
||||
|
||||
# VertexAIBackend class
|
||||
Configuration class for the Vertex AI Gemini API.
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> - Use [AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class) instead.
|
||||
>
|
||||
|
||||
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.
|
||||
Configuration class for the Agent Platform Gemini API (formerly known as 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 Agent Platform Gemini API as the backend.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -25,17 +30,17 @@ export declare class VertexAIBackend extends Backend
|
||||
|
||||
| Constructor | Modifiers | Description |
|
||||
| --- | --- | --- |
|
||||
| [(constructor)(location)](./ai.vertexaibackend.md#vertexaibackendconstructor) | | Creates a configuration object for the Vertex AI backend. |
|
||||
| [(constructor)(location)](./ai.vertexaibackend.md#vertexaibackendconstructor) | | Creates a configuration object for the Agent Platform Gemini API (formerly known as the Vertex AI Gemini API) backend. |
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Modifiers | Type | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [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. |
|
||||
| [location](./ai.vertexaibackend.md#vertexaibackendlocation) | | string | The region identifier. See [Agent Platform Gemini API locations](https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations) for a list of supported locations. |
|
||||
|
||||
## VertexAIBackend.(constructor)
|
||||
|
||||
Creates a configuration object for the Vertex AI backend.
|
||||
Creates a configuration object for the Agent Platform Gemini API (formerly known as the Vertex AI Gemini API) backend.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
@@ -47,11 +52,11 @@ constructor(location?: string);
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| location | string | The region identifier, defaulting to <code>us-central1</code>; see [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations#available-locations) for a list of supported locations. |
|
||||
| location | string | The region identifier, defaulting to <code>us-central1</code>; see [Agent Platform Gemini API locations](https://firebase.google.com/docs/ai-logic/locations?api=vertex#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#available-locations) for a list of supported locations.
|
||||
The region identifier. See [Agent Platform Gemini API locations](https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations) for a list of supported locations.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export interface WebGroundingChunk
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [domain](./ai.webgroundingchunk.md#webgroundingchunkdomain) | string | The domain of the original URI from which the content was retrieved.<!-- -->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)<!-- -->), this property will be <code>undefined</code>. |
|
||||
| [domain](./ai.webgroundingchunk.md#webgroundingchunkdomain) | string | The domain of the original URI from which the content was retrieved.<!-- -->This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->), this property will be <code>undefined</code>. |
|
||||
| [title](./ai.webgroundingchunk.md#webgroundingchunktitle) | string | The title of the retrieved web page. |
|
||||
| [uri](./ai.webgroundingchunk.md#webgroundingchunkuri) | string | The URI of the retrieved web page. |
|
||||
|
||||
@@ -32,7 +32,7 @@ export interface WebGroundingChunk
|
||||
|
||||
The domain of the original URI from which the content was retrieved.
|
||||
|
||||
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)<!-- -->), this property will be `undefined`<!-- -->.
|
||||
This property is only supported in the Agent Platform Gemini API ([AgentPlatformBackend](./ai.agentplatformbackend.md#agentplatformbackend_class)<!-- -->). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->), this property will be `undefined`<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ import {
|
||||
onValue,
|
||||
off
|
||||
} from 'firebase/database';
|
||||
import { getGenerativeModel, getAI, VertexAIBackend } from 'firebase/ai';
|
||||
import { getGenerativeModel, getAI, AgentPlatformBackend } from 'firebase/ai';
|
||||
import { getDataConnect, DataConnect } from 'firebase/data-connect';
|
||||
|
||||
/**
|
||||
@@ -312,7 +312,7 @@ function callPerformance(app) {
|
||||
*/
|
||||
async function callAI(app) {
|
||||
console.log('[AI] start');
|
||||
const ai = getAI(app, { backend: new VertexAIBackend() });
|
||||
const ai = getAI(app, { backend: new AgentPlatformBackend() });
|
||||
const model = getGenerativeModel(ai, { model: 'gemini-3.5-flash' });
|
||||
const result = await model.countTokens('abcdefg');
|
||||
console.log(`[AI] counted tokens: ${result.totalTokens}`);
|
||||
|
||||
@@ -86,7 +86,13 @@ import {
|
||||
StorageReference,
|
||||
deleteObject
|
||||
} from 'firebase/storage';
|
||||
import { getGenerativeModel, getAI, AI, VertexAIBackend } from 'firebase/ai';
|
||||
import {
|
||||
getGenerativeModel,
|
||||
getAI,
|
||||
AI,
|
||||
AgentPlatformBackend,
|
||||
VertexAIBackend
|
||||
} from 'firebase/ai';
|
||||
import { getDataConnect, DataConnect } from 'firebase/data-connect';
|
||||
// @ts-ignore
|
||||
import { config, testAccount } from '../firebase-config';
|
||||
@@ -310,8 +316,11 @@ describe('MODULAR', () => {
|
||||
|
||||
describe('AI', () => {
|
||||
let ai: AI;
|
||||
it('getVertexAI()', () => {
|
||||
ai = getAI(app, { backend: new VertexAIBackend() });
|
||||
it('getAI with AgentPlatformBackend()', () => {
|
||||
ai = getAI(app, { backend: new AgentPlatformBackend() });
|
||||
});
|
||||
it('getAI with VertexAIBackend()', () => {
|
||||
expect(getAI(app, { backend: new VertexAIBackend() })).toBeDefined();
|
||||
});
|
||||
it('getGenerativeModel()', async () => {
|
||||
const model = getGenerativeModel(ai, { model: 'gemini-3.5-flash' });
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
import { initializeApp } from '@firebase/app';
|
||||
import {
|
||||
AgentPlatformBackend,
|
||||
AI,
|
||||
Backend,
|
||||
BackendType,
|
||||
GoogleAIBackend,
|
||||
VertexAIBackend,
|
||||
getAI,
|
||||
getGenerativeModel
|
||||
} from '../src';
|
||||
@@ -45,20 +45,21 @@ function formatConfigAsString(config: { ai: AI; model: string }): string {
|
||||
|
||||
const backends: readonly Backend[] = [
|
||||
new GoogleAIBackend(),
|
||||
new VertexAIBackend('global')
|
||||
new AgentPlatformBackend()
|
||||
];
|
||||
|
||||
/**
|
||||
* Vertex Live API only works on us-central1 at the moment.
|
||||
* Live API only works on us-central1 at the moment.
|
||||
*/
|
||||
const liveBackends: readonly Backend[] = [
|
||||
new GoogleAIBackend(),
|
||||
new VertexAIBackend('us-central1')
|
||||
new AgentPlatformBackend('us-central1')
|
||||
];
|
||||
|
||||
const backendNames: Map<BackendType, string> = new Map([
|
||||
[BackendType.GOOGLE_AI, 'Google AI'],
|
||||
[BackendType.VERTEX_AI, 'Vertex AI']
|
||||
[BackendType.VERTEX_AI, 'Vertex AI'],
|
||||
[BackendType.AGENT_PLATFORM, 'Agent Platform']
|
||||
]);
|
||||
|
||||
const modelNames: readonly string[] = [
|
||||
@@ -69,7 +70,9 @@ const modelNames: readonly string[] = [
|
||||
|
||||
// Used for testing non-AI behavior (e.g. Network requests). Configured to minimize cost.
|
||||
export const cheapestModel = 'gemini-3.1-flash-lite';
|
||||
export const defaultAIInstance = getAI(app, { backend: new VertexAIBackend() });
|
||||
export const defaultAIInstance = getAI(app, {
|
||||
backend: new AgentPlatformBackend()
|
||||
});
|
||||
export const defaultGenerativeModel = getGenerativeModel(defaultAIInstance, {
|
||||
model: cheapestModel,
|
||||
generationConfig: {
|
||||
@@ -80,7 +83,8 @@ export const defaultGenerativeModel = getGenerativeModel(defaultAIInstance, {
|
||||
// The Live API requires a different set of models, and they're different for each backend.
|
||||
const liveModelNames: Map<BackendType, string[]> = new Map([
|
||||
[BackendType.GOOGLE_AI, ['gemini-3.1-flash-live-preview']],
|
||||
[BackendType.VERTEX_AI, ['gemini-3.1-flash-live-preview']]
|
||||
[BackendType.VERTEX_AI, ['gemini-3.1-flash-live-preview']],
|
||||
[BackendType.AGENT_PLATFORM, ['gemini-3.1-flash-live-preview']]
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
@@ -98,7 +98,8 @@ describe('Count Tokens', () => {
|
||||
expect(response.totalBillableCharacters).to.be.undefined;
|
||||
expect(response.promptTokensDetails![0].tokenCount).to.equal(7);
|
||||
} else if (
|
||||
testConfig.ai.backend.backendType === BackendType.VERTEX_AI
|
||||
testConfig.ai.backend.backendType === BackendType.VERTEX_AI ||
|
||||
testConfig.ai.backend.backendType === BackendType.AGENT_PLATFORM
|
||||
) {
|
||||
expect(response.totalTokens).to.equal(6);
|
||||
expect(response.totalBillableCharacters).to.equal(16);
|
||||
@@ -141,7 +142,8 @@ describe('Count Tokens', () => {
|
||||
tokenCount: expectedImageTokens
|
||||
});
|
||||
} else if (
|
||||
testConfig.ai.backend.backendType === BackendType.VERTEX_AI
|
||||
testConfig.ai.backend.backendType === BackendType.VERTEX_AI ||
|
||||
testConfig.ai.backend.backendType === BackendType.AGENT_PLATFORM
|
||||
) {
|
||||
expect(response.totalTokens).to.equal(expectedImageTokens);
|
||||
expect(response.totalBillableCharacters).to.be.undefined; // Incorrect behavior
|
||||
@@ -190,7 +192,8 @@ describe('Count Tokens', () => {
|
||||
tokenCount: 5
|
||||
});
|
||||
} else if (
|
||||
testConfig.ai.backend.backendType === BackendType.VERTEX_AI
|
||||
testConfig.ai.backend.backendType === BackendType.VERTEX_AI ||
|
||||
testConfig.ai.backend.backendType === BackendType.AGENT_PLATFORM
|
||||
) {
|
||||
expect(response.totalTokens).to.be.undefined;
|
||||
expect(response.promptTokensDetails!.length).to.equal(1); // Note: Text modality details absent for Vertex AI with audio-only input.
|
||||
@@ -255,7 +258,8 @@ describe('Count Tokens', () => {
|
||||
tokenCount: 5
|
||||
});
|
||||
} else if (
|
||||
testConfig.ai.backend.backendType === BackendType.VERTEX_AI
|
||||
testConfig.ai.backend.backendType === BackendType.VERTEX_AI ||
|
||||
testConfig.ai.backend.backendType === BackendType.AGENT_PLATFORM
|
||||
) {
|
||||
expect(response.totalTokens).to.equal(expectedImageTokenCount + 3);
|
||||
expect(textDetails).to.deep.equal({
|
||||
|
||||
@@ -37,28 +37,14 @@ import { expect, use } from 'chai';
|
||||
import { stub } from 'sinon';
|
||||
import { AI } from './public-types';
|
||||
import { GenerativeModel } from './models/generative-model';
|
||||
import { GoogleAIBackend, VertexAIBackend } from './backend';
|
||||
import { getFullApp } from '../test-utils/get-fake-firebase-services';
|
||||
import { GoogleAIBackend, AgentPlatformBackend } from './backend';
|
||||
import { fakeAI, getFullApp } from '../test-utils/get-fake-firebase-services';
|
||||
import { AI_TYPE } from './constants';
|
||||
import { logger } from './logger';
|
||||
import sinonChai from 'sinon-chai';
|
||||
|
||||
use(sinonChai);
|
||||
|
||||
const fakeAI: AI = {
|
||||
app: {
|
||||
name: 'DEFAULT',
|
||||
automaticDataCollectionEnabled: true,
|
||||
options: {
|
||||
apiKey: 'key',
|
||||
projectId: 'my-project',
|
||||
appId: 'my-appid'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
};
|
||||
|
||||
describe('Top level API', () => {
|
||||
describe('getAI()', () => {
|
||||
it('works without options', () => {
|
||||
@@ -72,25 +58,25 @@ describe('Top level API', () => {
|
||||
});
|
||||
it('works with options: backend specified, limited use token', () => {
|
||||
const ai = getAI(getFullApp(), {
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
backend: new AgentPlatformBackend('global'),
|
||||
useLimitedUseAppCheckTokens: true
|
||||
});
|
||||
expect(ai.backend).to.be.instanceOf(VertexAIBackend);
|
||||
expect(ai.backend).to.be.instanceOf(AgentPlatformBackend);
|
||||
expect(ai.options?.useLimitedUseAppCheckTokens).to.be.true;
|
||||
});
|
||||
it('works with options: appCheck option is falsy', () => {
|
||||
const ai = getAI(getFullApp(), {
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
backend: new AgentPlatformBackend('global'),
|
||||
useLimitedUseAppCheckTokens: undefined
|
||||
});
|
||||
expect(ai.backend).to.be.instanceOf(VertexAIBackend);
|
||||
expect(ai.backend).to.be.instanceOf(AgentPlatformBackend);
|
||||
expect(ai.options?.useLimitedUseAppCheckTokens).to.be.false;
|
||||
});
|
||||
it('works with options: backend specified only', () => {
|
||||
const ai = getAI(getFullApp(), {
|
||||
backend: new VertexAIBackend('us-central1')
|
||||
backend: new AgentPlatformBackend('global')
|
||||
});
|
||||
expect(ai.backend).to.be.instanceOf(VertexAIBackend);
|
||||
expect(ai.backend).to.be.instanceOf(AgentPlatformBackend);
|
||||
expect(ai.options?.useLimitedUseAppCheckTokens).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,7 +57,12 @@ export {
|
||||
TemplateImagenModel,
|
||||
AIError
|
||||
};
|
||||
export { Backend, VertexAIBackend, GoogleAIBackend } from './backend';
|
||||
export {
|
||||
Backend,
|
||||
VertexAIBackend,
|
||||
GoogleAIBackend,
|
||||
AgentPlatformBackend
|
||||
} from './backend';
|
||||
export {
|
||||
startAudioConversation,
|
||||
AudioConversationController,
|
||||
@@ -88,8 +93,8 @@ declare module '@firebase/component' {
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get an AI instance configured to use the Vertex AI Gemini API.
|
||||
* const ai = getAI(app, { backend: new VertexAIBackend() });
|
||||
* // Get an AI instance configured to use the Agent Platform Gemini API.
|
||||
* const ai = getAI(app, { backend: new AgentPlatformBackend() });
|
||||
* ```
|
||||
*
|
||||
* @param app - The {@link @firebase/app#FirebaseApp} to use.
|
||||
|
||||
@@ -16,9 +16,17 @@
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
import { GoogleAIBackend, VertexAIBackend } from './backend';
|
||||
import {
|
||||
AgentPlatformBackend,
|
||||
GoogleAIBackend,
|
||||
VertexAIBackend
|
||||
} from './backend';
|
||||
import { BackendType } from './public-types';
|
||||
import { DEFAULT_API_VERSION, DEFAULT_LOCATION } from './constants';
|
||||
import {
|
||||
DEFAULT_API_VERSION,
|
||||
DEFAULT_LOCATION,
|
||||
LEGACY_DEFAULT_LOCATION
|
||||
} from './constants';
|
||||
|
||||
describe('Backend', () => {
|
||||
describe('GoogleAIBackend', () => {
|
||||
@@ -43,7 +51,7 @@ describe('Backend', () => {
|
||||
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);
|
||||
expect(backend.location).to.equal(LEGACY_DEFAULT_LOCATION);
|
||||
});
|
||||
it('sets custom location', () => {
|
||||
const backend = new VertexAIBackend('test-location');
|
||||
@@ -53,12 +61,12 @@ describe('Backend', () => {
|
||||
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(DEFAULT_LOCATION);
|
||||
expect(backend.location).to.equal(LEGACY_DEFAULT_LOCATION);
|
||||
});
|
||||
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);
|
||||
expect(backend.location).to.equal(LEGACY_DEFAULT_LOCATION);
|
||||
});
|
||||
it('getModelPath', () => {
|
||||
const backend = new VertexAIBackend();
|
||||
@@ -73,4 +81,38 @@ describe('Backend', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('AgentPlatformBackend', () => {
|
||||
it('set backendType to AGENT_PLATFORM', () => {
|
||||
const backend = new AgentPlatformBackend();
|
||||
expect(backend.backendType).to.equal(BackendType.AGENT_PLATFORM);
|
||||
expect(backend.location).to.equal(DEFAULT_LOCATION);
|
||||
});
|
||||
it('sets custom location', () => {
|
||||
const backend = new AgentPlatformBackend('test-location');
|
||||
expect(backend.backendType).to.equal(BackendType.AGENT_PLATFORM);
|
||||
expect(backend.location).to.equal('test-location');
|
||||
});
|
||||
it('uses default location if location is empty string', () => {
|
||||
const backend = new AgentPlatformBackend('');
|
||||
expect(backend.backendType).to.equal(BackendType.AGENT_PLATFORM);
|
||||
expect(backend.location).to.equal(DEFAULT_LOCATION);
|
||||
});
|
||||
it('uses default location if location is null', () => {
|
||||
const backend = new AgentPlatformBackend(null as any);
|
||||
expect(backend.backendType).to.equal(BackendType.AGENT_PLATFORM);
|
||||
expect(backend.location).to.equal(DEFAULT_LOCATION);
|
||||
});
|
||||
it('getModelPath', () => {
|
||||
const backend = new AgentPlatformBackend();
|
||||
expect(backend._getModelPath('my-project', 'model-name')).to.equal(
|
||||
`/${DEFAULT_API_VERSION}/projects/my-project/locations/${backend.location}/model-name`
|
||||
);
|
||||
});
|
||||
it('getTemplatePath', () => {
|
||||
const backend = new AgentPlatformBackend();
|
||||
expect(backend._getTemplatePath('my-project', 'template-id')).to.equal(
|
||||
`/${DEFAULT_API_VERSION}/projects/my-project/locations/${backend.location}/templates/template-id`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+64
-13
@@ -15,14 +15,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DEFAULT_API_VERSION, DEFAULT_LOCATION } from './constants';
|
||||
import {
|
||||
DEFAULT_API_VERSION,
|
||||
DEFAULT_LOCATION,
|
||||
LEGACY_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} for
|
||||
* the Gemini Developer API (via {@link https://ai.google/ | Google AI}), and
|
||||
* {@link VertexAIBackend} for the Vertex AI Gemini API.
|
||||
* the Gemini Developer API (via {@link https://ai.google/ | Google AI}) and {@link AgentPlatformBackend}
|
||||
* for the Agent Platform Gemini API.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
@@ -83,33 +87,80 @@ export class GoogleAIBackend extends Backend {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration class for the Vertex AI Gemini API.
|
||||
* Configuration class for the Agent Platform Gemini API (formerly known as the
|
||||
* Vertex AI Gemini API).
|
||||
*
|
||||
* Use this with {@link AIOptions} when initializing the AI service via
|
||||
* {@link getAI | getAI()} to specify the Vertex AI Gemini API as the backend.
|
||||
* {@link getAI | getAI()} to specify the Agent Platform Gemini API as the backend.
|
||||
*
|
||||
* @deprecated - Use {@link AgentPlatformBackend} instead.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class VertexAIBackend extends Backend {
|
||||
/**
|
||||
* The region identifier.
|
||||
* See {@link https://firebase.google.com/docs/vertex-ai/locations#available-locations | Vertex AI locations}
|
||||
* See {@link https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations | Agent Platform Gemini API locations}
|
||||
* for a list of supported locations.
|
||||
*/
|
||||
readonly location: string;
|
||||
readonly location: string = LEGACY_DEFAULT_LOCATION;
|
||||
|
||||
/**
|
||||
* Creates a configuration object for the Vertex AI backend.
|
||||
* Creates a configuration object for the Agent Platform Gemini API (formerly
|
||||
* known as the Vertex AI Gemini API) backend.
|
||||
*
|
||||
* @param location - The region identifier, defaulting to `us-central1`;
|
||||
* see {@link https://firebase.google.com/docs/vertex-ai/locations#available-locations | Vertex AI locations}
|
||||
* see {@link https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations | Agent Platform Gemini API locations}
|
||||
* for a list of supported locations.
|
||||
*/
|
||||
constructor(location: string = DEFAULT_LOCATION) {
|
||||
constructor(location?: string) {
|
||||
super(BackendType.VERTEX_AI);
|
||||
if (!location) {
|
||||
this.location = DEFAULT_LOCATION;
|
||||
} else {
|
||||
if (location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_getModelPath(project: string, model: string): string {
|
||||
return `/${DEFAULT_API_VERSION}/projects/${project}/locations/${this.location}/${model}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_getTemplatePath(project: string, templateId: string): string {
|
||||
return `/${DEFAULT_API_VERSION}/projects/${project}/locations/${this.location}/templates/${templateId}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration class for the Agent Platform Gemini API.
|
||||
*
|
||||
* Use this with {@link AIOptions} when initializing the AI service via
|
||||
* {@link getAI | getAI()} to specify the Agent Platform Gemini API as the backend.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class AgentPlatformBackend extends Backend {
|
||||
/**
|
||||
* The region identifier.
|
||||
* See {@link https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations | Agent Platform locations}
|
||||
* for a list of supported locations.
|
||||
*/
|
||||
readonly location: string = DEFAULT_LOCATION;
|
||||
|
||||
/**
|
||||
* Creates a configuration object for the Agent Platform backend.
|
||||
*
|
||||
* @param location - The region identifier, defaulting to `global`;
|
||||
* see {@link https://firebase.google.com/docs/ai-logic/locations?api=vertex#available-locations | Agent Platform locations}
|
||||
* for a list of supported locations.
|
||||
*/
|
||||
constructor(location?: string) {
|
||||
super(BackendType.AGENT_PLATFORM);
|
||||
if (location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ import { version } from '../package.json';
|
||||
|
||||
export const AI_TYPE = 'AI';
|
||||
|
||||
export const DEFAULT_LOCATION = 'us-central1';
|
||||
export const LEGACY_DEFAULT_LOCATION = 'us-central1';
|
||||
|
||||
export const DEFAULT_LOCATION = 'global';
|
||||
|
||||
export const DEFAULT_DOMAIN = 'firebasevertexai.googleapis.com';
|
||||
|
||||
|
||||
@@ -36,19 +36,19 @@ import {
|
||||
} from './types/googleai';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This SDK supports both the Agent Platform Gemini API and the Gemini Developer API (using Google AI).
|
||||
* The public API prioritizes the format used by the Agent Platform 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 Vertex AI Gemini API and the Gemini Developer API
|
||||
* This translation allows developers to switch between the Agent Platform 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.
|
||||
* 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.
|
||||
* Requests in the AgentPlatform format are mapped to the Google AI format before being sent.
|
||||
* Responses from the Google AI backend are mapped back to the AgentPlatform format before being returned to the user.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Maps a Vertex AI {@link GenerateContentRequest} to a format that can be sent to Google AI.
|
||||
* Maps a AgentPlatform {@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.
|
||||
@@ -87,7 +87,7 @@ export function mapGenerateContentRequest(
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* {@link GenerateContentResponse} that we get from AgentPlatform 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.
|
||||
@@ -111,7 +111,7 @@ export function mapGenerateContentResponse(
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a Vertex AI {@link CountTokensRequest} to a format that can be sent to Google AI.
|
||||
* Maps a AgentPlatform {@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.
|
||||
@@ -135,10 +135,10 @@ export function mapCountTokensRequest(
|
||||
|
||||
/**
|
||||
* Maps a Google AI {@link GoogleAIGenerateContentCandidate} to a format that conforms
|
||||
* to the Vertex AI API format.
|
||||
* to the AgentPlatform API format.
|
||||
*
|
||||
* @param candidates The {@link GoogleAIGenerateContentCandidate} to map.
|
||||
* @returns A {@link GenerateContentCandidate} that conforms to the Vertex AI format.
|
||||
* @returns A {@link GenerateContentCandidate} that conforms to the AgentPlatform format.
|
||||
*
|
||||
* @throws If any {@link Part} in the candidates has a `videoMetadata` property.
|
||||
*
|
||||
|
||||
@@ -15,14 +15,34 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { expect } from 'chai';
|
||||
import { AI_TYPE, DEFAULT_LOCATION } from './constants';
|
||||
import {
|
||||
AI_TYPE,
|
||||
DEFAULT_LOCATION,
|
||||
LEGACY_DEFAULT_LOCATION
|
||||
} from './constants';
|
||||
import { encodeInstanceIdentifier, decodeInstanceIdentifier } from './helpers';
|
||||
import { AIError } from './errors';
|
||||
import { AIErrorCode } from './types';
|
||||
import { GoogleAIBackend, VertexAIBackend } from './backend';
|
||||
import {
|
||||
GoogleAIBackend,
|
||||
AgentPlatformBackend,
|
||||
VertexAIBackend
|
||||
} from './backend';
|
||||
|
||||
describe('Identifier Encoding/Decoding', () => {
|
||||
describe('encodeInstanceIdentifier', () => {
|
||||
it('should encode Agent Platform identifier with a specific location', () => {
|
||||
const backend = new AgentPlatformBackend('us-east1');
|
||||
const expected = `${AI_TYPE}/agentplatform/us-east1`;
|
||||
expect(encodeInstanceIdentifier(backend)).to.equal(expected);
|
||||
});
|
||||
|
||||
it('should encode Agent Platform identifier using default location if location is empty string', () => {
|
||||
const backend = new AgentPlatformBackend('');
|
||||
const expected = `${AI_TYPE}/agentplatform/${DEFAULT_LOCATION}`;
|
||||
expect(encodeInstanceIdentifier(backend)).to.equal(expected);
|
||||
});
|
||||
|
||||
it('should encode Vertex AI identifier with a specific location', () => {
|
||||
const backend = new VertexAIBackend('us-east1');
|
||||
const expected = `${AI_TYPE}/vertexai/us-east1`;
|
||||
@@ -31,7 +51,7 @@ describe('Identifier Encoding/Decoding', () => {
|
||||
|
||||
it('should encode Vertex AI identifier using default location if location is empty string', () => {
|
||||
const backend = new VertexAIBackend('');
|
||||
const expected = `${AI_TYPE}/vertexai/${DEFAULT_LOCATION}`;
|
||||
const expected = `${AI_TYPE}/vertexai/${LEGACY_DEFAULT_LOCATION}`;
|
||||
expect(encodeInstanceIdentifier(backend)).to.equal(expected);
|
||||
});
|
||||
|
||||
@@ -57,6 +77,29 @@ describe('Identifier Encoding/Decoding', () => {
|
||||
});
|
||||
|
||||
describe('decodeInstanceIdentifier', () => {
|
||||
it('should decode Agent Platform identifier with location', () => {
|
||||
const encoded = `${AI_TYPE}/agentplatform/europe-west1`;
|
||||
const backend = new AgentPlatformBackend('europe-west1');
|
||||
expect(decodeInstanceIdentifier(encoded)).to.deep.equal(backend);
|
||||
});
|
||||
|
||||
it('should throw an error if Agent Platform identifier string without explicit location part', () => {
|
||||
const encoded = `${AI_TYPE}/agentplatform`;
|
||||
expect(() => decodeInstanceIdentifier(encoded)).to.throw(AIError);
|
||||
|
||||
try {
|
||||
decodeInstanceIdentifier(encoded);
|
||||
expect.fail('Expected decodeInstanceIdentifier to throw');
|
||||
} catch (e) {
|
||||
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(AIErrorCode.ERROR);
|
||||
}
|
||||
});
|
||||
|
||||
it('should decode Vertex AI identifier with location', () => {
|
||||
const encoded = `${AI_TYPE}/vertexai/europe-west1`;
|
||||
const backend = new VertexAIBackend('europe-west1');
|
||||
|
||||
@@ -18,7 +18,12 @@
|
||||
import { AI_TYPE } from './constants';
|
||||
import { AIError } from './errors';
|
||||
import { AIErrorCode } from './types';
|
||||
import { Backend, GoogleAIBackend, VertexAIBackend } from './backend';
|
||||
import {
|
||||
AgentPlatformBackend,
|
||||
Backend,
|
||||
GoogleAIBackend,
|
||||
VertexAIBackend
|
||||
} from './backend';
|
||||
|
||||
/**
|
||||
* Encodes a {@link Backend} into a string that will be used to uniquely identify {@link AI}
|
||||
@@ -31,6 +36,8 @@ export function encodeInstanceIdentifier(backend: Backend): string {
|
||||
return `${AI_TYPE}/googleai`;
|
||||
} else if (backend instanceof VertexAIBackend) {
|
||||
return `${AI_TYPE}/vertexai/${backend.location}`;
|
||||
} else if (backend instanceof AgentPlatformBackend) {
|
||||
return `${AI_TYPE}/agentplatform/${backend.location}`;
|
||||
} else {
|
||||
throw new AIError(
|
||||
AIErrorCode.ERROR,
|
||||
@@ -55,6 +62,15 @@ export function decodeInstanceIdentifier(instanceIdentifier: string): Backend {
|
||||
const backendType = identifierParts[1];
|
||||
switch (backendType) {
|
||||
case 'vertexai':
|
||||
const vertexLocation: string | undefined = identifierParts[2];
|
||||
if (!vertexLocation) {
|
||||
throw new AIError(
|
||||
AIErrorCode.ERROR,
|
||||
`Invalid instance identifier, unknown location '${instanceIdentifier}'`
|
||||
);
|
||||
}
|
||||
return new VertexAIBackend(vertexLocation);
|
||||
case 'agentplatform':
|
||||
const location: string | undefined = identifierParts[2];
|
||||
if (!location) {
|
||||
throw new AIError(
|
||||
@@ -62,7 +78,7 @@ export function decodeInstanceIdentifier(instanceIdentifier: string): Backend {
|
||||
`Invalid instance identifier, unknown location '${instanceIdentifier}'`
|
||||
);
|
||||
}
|
||||
return new VertexAIBackend(location);
|
||||
return new AgentPlatformBackend(location);
|
||||
case 'googleai':
|
||||
return new GoogleAIBackend();
|
||||
default:
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
} from '../types';
|
||||
import { ChatSession } from './chat-session';
|
||||
import { ApiSettings } from '../types/internal';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { AgentPlatformBackend } from '../backend';
|
||||
import { fakeChromeAdapter } from '../../test-utils/get-fake-firebase-services';
|
||||
import { logger } from '../logger';
|
||||
import { Schema } from '../api';
|
||||
@@ -39,8 +39,8 @@ const fakeApiSettings: ApiSettings = {
|
||||
apiKey: 'key',
|
||||
project: 'my-project',
|
||||
appId: 'my-appid',
|
||||
location: 'us-central1',
|
||||
backend: new VertexAIBackend()
|
||||
location: 'global',
|
||||
backend: new AgentPlatformBackend()
|
||||
};
|
||||
|
||||
function getGreeting({
|
||||
|
||||
@@ -26,7 +26,7 @@ import { CountTokensRequest, InferenceMode } from '../types';
|
||||
import { ApiSettings } from '../types/internal';
|
||||
import { Task } from '../requests/request';
|
||||
import { mapCountTokensRequest } from '../googleai-mappers';
|
||||
import { GoogleAIBackend, VertexAIBackend } from '../backend';
|
||||
import { GoogleAIBackend, AgentPlatformBackend } from '../backend';
|
||||
import { fakeChromeAdapter } from '../../test-utils/get-fake-firebase-services';
|
||||
|
||||
use(sinonChai);
|
||||
@@ -36,8 +36,8 @@ const fakeApiSettings: ApiSettings = {
|
||||
apiKey: 'key',
|
||||
project: 'my-project',
|
||||
appId: 'my-appid',
|
||||
location: 'us-central1',
|
||||
backend: new VertexAIBackend()
|
||||
location: 'global',
|
||||
backend: new AgentPlatformBackend()
|
||||
};
|
||||
|
||||
const fakeGoogleAIApiSettings: ApiSettings = {
|
||||
|
||||
@@ -44,7 +44,7 @@ import { ApiSettings } from '../types/internal';
|
||||
import { Task } from '../requests/request';
|
||||
import { AIError } from '../api';
|
||||
import { mapGenerateContentRequest } from '../googleai-mappers';
|
||||
import { GoogleAIBackend, VertexAIBackend } from '../backend';
|
||||
import { GoogleAIBackend, AgentPlatformBackend } from '../backend';
|
||||
import { fakeChromeAdapter } from '../../test-utils/get-fake-firebase-services';
|
||||
|
||||
use(sinonChai);
|
||||
@@ -54,15 +54,15 @@ const fakeApiSettings: ApiSettings = {
|
||||
apiKey: 'key',
|
||||
project: 'my-project',
|
||||
appId: 'my-appid',
|
||||
location: 'us-central1',
|
||||
backend: new VertexAIBackend()
|
||||
location: 'global',
|
||||
backend: new AgentPlatformBackend()
|
||||
};
|
||||
|
||||
const fakeGoogleAIApiSettings: ApiSettings = {
|
||||
apiKey: 'key',
|
||||
project: 'my-project',
|
||||
appId: 'my-appid',
|
||||
location: 'us-central1',
|
||||
location: 'global',
|
||||
backend: new GoogleAIBackend()
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import * as generateContentMethods from './generate-content';
|
||||
import { Content, TemplateFunctionDeclaration } from '../types';
|
||||
import { TemplateChatSessionImpl } from './template-chat-session';
|
||||
import { ApiSettings } from '../types/internal';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { AgentPlatformBackend } from '../backend';
|
||||
import { logger } from '../logger';
|
||||
import { Schema } from '../api';
|
||||
|
||||
@@ -34,8 +34,8 @@ const fakeApiSettings: ApiSettings = {
|
||||
apiKey: 'key',
|
||||
project: 'my-project',
|
||||
appId: 'my-appid',
|
||||
location: 'us-central1',
|
||||
backend: new VertexAIBackend('us-central1')
|
||||
location: 'global',
|
||||
backend: new AgentPlatformBackend('global')
|
||||
};
|
||||
|
||||
const TEMPLATE_ID = 'my-template';
|
||||
|
||||
@@ -18,7 +18,7 @@ import { use, expect } from 'chai';
|
||||
import { AI } from '../public-types';
|
||||
import sinonChai from 'sinon-chai';
|
||||
import { AIModel } from './ai-model';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { fakeAI } from '../../test-utils/get-fake-firebase-services';
|
||||
|
||||
use(sinonChai);
|
||||
|
||||
@@ -32,20 +32,6 @@ class TestModel extends AIModel {
|
||||
}
|
||||
}
|
||||
|
||||
const fakeAI: AI = {
|
||||
app: {
|
||||
name: 'DEFAULT',
|
||||
automaticDataCollectionEnabled: true,
|
||||
options: {
|
||||
apiKey: 'key',
|
||||
projectId: 'my-project',
|
||||
appId: 'my-appid'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
};
|
||||
|
||||
describe('AIModel', () => {
|
||||
it('handles plain model name', () => {
|
||||
const testModel = new TestModel(fakeAI, 'my-model');
|
||||
|
||||
@@ -18,7 +18,6 @@ import { use, expect } from 'chai';
|
||||
import { GenerativeModel, validateGenerationConfig } from './generative-model';
|
||||
import {
|
||||
FunctionCallingMode,
|
||||
AI,
|
||||
InferenceMode,
|
||||
AIErrorCode,
|
||||
ChromeAdapter,
|
||||
@@ -35,29 +34,17 @@ import {
|
||||
import sinonChai from 'sinon-chai';
|
||||
import * as generateContentMethods from '../methods/generate-content';
|
||||
import * as countTokens from '../methods/count-tokens';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { AIError } from '../errors';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import { fakeChromeAdapter } from '../../test-utils/get-fake-firebase-services';
|
||||
import {
|
||||
fakeAI,
|
||||
fakeChromeAdapter
|
||||
} from '../../test-utils/get-fake-firebase-services';
|
||||
import { Availability } from '../types/language-model';
|
||||
|
||||
use(sinonChai);
|
||||
use(chaiAsPromised);
|
||||
|
||||
const fakeAI: AI = {
|
||||
app: {
|
||||
name: 'DEFAULT',
|
||||
automaticDataCollectionEnabled: true,
|
||||
options: {
|
||||
apiKey: 'key',
|
||||
projectId: 'my-project',
|
||||
appId: 'my-appid'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
};
|
||||
|
||||
describe('GenerativeModel', () => {
|
||||
afterEach(() => {
|
||||
restore();
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
ImagenAspectRatio,
|
||||
ImagenPersonFilterLevel,
|
||||
ImagenSafetyFilterLevel,
|
||||
AI,
|
||||
AIErrorCode
|
||||
} from '../public-types';
|
||||
import * as request from '../requests/request';
|
||||
@@ -28,24 +27,10 @@ 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 '../backend';
|
||||
import { fakeAI } from '../../test-utils/get-fake-firebase-services';
|
||||
|
||||
use(sinonChai);
|
||||
|
||||
const fakeAI: AI = {
|
||||
app: {
|
||||
name: 'DEFAULT',
|
||||
automaticDataCollectionEnabled: true,
|
||||
options: {
|
||||
apiKey: 'key',
|
||||
projectId: 'my-project',
|
||||
appId: 'my-appid'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
};
|
||||
|
||||
describe('ImagenModel', () => {
|
||||
afterEach(() => {
|
||||
restore();
|
||||
|
||||
@@ -18,32 +18,13 @@
|
||||
import { use, expect } from 'chai';
|
||||
import sinonChai from 'sinon-chai';
|
||||
import { restore, stub } from 'sinon';
|
||||
import {
|
||||
AI,
|
||||
TemplateToolConfig,
|
||||
RetrievalConfig,
|
||||
LatLng
|
||||
} from '../public-types';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { TemplateToolConfig, RetrievalConfig, LatLng } from '../public-types';
|
||||
import { TemplateGenerativeModel } from './template-generative-model';
|
||||
import * as generateContentMethods from '../methods/generate-content';
|
||||
import { fakeAI } from '../../test-utils/get-fake-firebase-services';
|
||||
|
||||
use(sinonChai);
|
||||
|
||||
const fakeAI: AI = {
|
||||
app: {
|
||||
name: 'DEFAULT',
|
||||
automaticDataCollectionEnabled: true,
|
||||
options: {
|
||||
apiKey: 'key',
|
||||
projectId: 'my-project',
|
||||
appId: 'my-appid'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
};
|
||||
|
||||
const TEMPLATE_ID = 'my-template';
|
||||
const TEMPLATE_VARS = { a: 1, b: '2' };
|
||||
|
||||
|
||||
@@ -19,29 +19,14 @@ import { use, expect } from 'chai';
|
||||
import sinonChai from 'sinon-chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import { restore, stub, match } from 'sinon';
|
||||
import { AI } from '../public-types';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { TemplateImagenModel } from './template-imagen-model';
|
||||
import { AIError } from '../errors';
|
||||
import * as request from '../requests/request';
|
||||
import { fakeAI } from '../../test-utils/get-fake-firebase-services';
|
||||
|
||||
use(sinonChai);
|
||||
use(chaiAsPromised);
|
||||
|
||||
const fakeAI: AI = {
|
||||
app: {
|
||||
name: 'DEFAULT',
|
||||
automaticDataCollectionEnabled: true,
|
||||
options: {
|
||||
apiKey: 'key',
|
||||
projectId: 'my-project',
|
||||
appId: 'my-appid'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
};
|
||||
|
||||
const TEMPLATE_ID = 'my-imagen-template';
|
||||
const TEMPLATE_VARS = { a: 1, b: '2' };
|
||||
|
||||
|
||||
@@ -19,26 +19,13 @@ import { AI, AIErrorCode } from '../public-types';
|
||||
import sinonChai from 'sinon-chai';
|
||||
import { stub } from 'sinon';
|
||||
import { AIError } from '../errors';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { AgentPlatformBackend } from '../backend';
|
||||
import { AIService } from '../service';
|
||||
import { initApiSettings } from './utils';
|
||||
import { fakeAI } from '../../test-utils/get-fake-firebase-services';
|
||||
|
||||
use(sinonChai);
|
||||
|
||||
const fakeAI: AI = {
|
||||
app: {
|
||||
name: 'DEFAULT',
|
||||
automaticDataCollectionEnabled: true,
|
||||
options: {
|
||||
apiKey: 'key',
|
||||
projectId: 'my-project',
|
||||
appId: 'my-appid'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
};
|
||||
|
||||
describe('initApiSettings', () => {
|
||||
it('calls regular app check token when option is set', async () => {
|
||||
const getTokenStub = stub().resolves();
|
||||
@@ -93,8 +80,8 @@ describe('initApiSettings', () => {
|
||||
projectId: 'my-project'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
backend: new AgentPlatformBackend('global'),
|
||||
location: 'global'
|
||||
};
|
||||
try {
|
||||
initApiSettings(fakeAI);
|
||||
@@ -111,8 +98,8 @@ describe('initApiSettings', () => {
|
||||
apiKey: 'key'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
backend: new AgentPlatformBackend('global'),
|
||||
location: 'global'
|
||||
};
|
||||
try {
|
||||
initApiSettings(fakeAI);
|
||||
@@ -130,8 +117,8 @@ describe('initApiSettings', () => {
|
||||
projectId: 'my-project'
|
||||
}
|
||||
},
|
||||
backend: new VertexAIBackend('us-central1'),
|
||||
location: 'us-central1'
|
||||
backend: new AgentPlatformBackend('global'),
|
||||
location: 'global'
|
||||
};
|
||||
try {
|
||||
initApiSettings(fakeAI);
|
||||
|
||||
@@ -44,7 +44,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
|
||||
* Vertex AI Gemini API (using {@link VertexAIBackend}).
|
||||
* Agent Platform Gemini API (using {@link AgentPlatformBackend}).
|
||||
*/
|
||||
backend: Backend;
|
||||
/**
|
||||
@@ -54,7 +54,8 @@ export interface AI {
|
||||
/**
|
||||
* @deprecated 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
|
||||
* Agent Platform Gemini API backends.
|
||||
*/
|
||||
location: string;
|
||||
}
|
||||
@@ -62,19 +63,27 @@ export interface AI {
|
||||
/**
|
||||
* 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)
|
||||
* This determines which backend service (Gemini Developer API or Agent Platform Gemini 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
|
||||
* configuration objects ({@link GoogleAIBackend} or {@link AgentPlatformBackend}) to identify
|
||||
* which service to target.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const BackendType = {
|
||||
/**
|
||||
* Identifies the backend service for the Vertex AI Gemini API provided through Google Cloud.
|
||||
* Identifies the backend service for the Agent Platform Gemini API provided through Google Cloud.
|
||||
* Use this constant when creating a {@link AgentPlatformBackend} configuration.
|
||||
*/
|
||||
AGENT_PLATFORM: 'AGENT_PLATFORM',
|
||||
|
||||
/**
|
||||
* Identifies the backend service for the Agent Platform Gemini API
|
||||
* (formerly known as Vertex AI Gemini API) provided through Google Cloud.
|
||||
* Use this constant when creating a {@link VertexAIBackend} configuration.
|
||||
* @deprecated - Use {@link AgentPlatformBackend} instead.
|
||||
*/
|
||||
VERTEX_AI: 'VERTEX_AI',
|
||||
|
||||
@@ -87,7 +96,7 @@ export const BackendType = {
|
||||
|
||||
/**
|
||||
* Type alias representing valid backend types.
|
||||
* It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`.
|
||||
* It should be either `'AGENT_PLATFORM'` or `'GOOGLE_AI'` (`'VERTEX_AI'` is deprecated).
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
@@ -95,8 +104,8 @@ 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 (Vertex AI Gemini API or Gemini Developer API)
|
||||
* and configuring its specific options (like location for Vertex AI).
|
||||
* This allows specifying which backend to use (Gemini Developer API or Agent Platform Gemini API)
|
||||
* and configuring its specific options (like location for Agent Platform).
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,7 @@ import { DEFAULT_API_VERSION } from '../constants';
|
||||
import { AIErrorCode, InferenceMode } from '../types';
|
||||
import { AIError } from '../errors';
|
||||
import { getMockResponse } from '../../test-utils/mock-response';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { AgentPlatformBackend } from '../backend';
|
||||
|
||||
use(sinonChai);
|
||||
use(chaiAsPromised);
|
||||
@@ -42,8 +42,8 @@ const fakeApiSettings: ApiSettings = {
|
||||
apiKey: 'key',
|
||||
project: 'my-project',
|
||||
appId: 'my-appid',
|
||||
location: 'us-central1',
|
||||
backend: new VertexAIBackend()
|
||||
location: 'global',
|
||||
backend: new AgentPlatformBackend()
|
||||
};
|
||||
|
||||
describe('request methods', () => {
|
||||
@@ -128,7 +128,7 @@ describe('request methods', () => {
|
||||
project: 'myproject',
|
||||
appId: 'my-appid',
|
||||
location: 'moon',
|
||||
backend: new VertexAIBackend(),
|
||||
backend: new AgentPlatformBackend(),
|
||||
getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }),
|
||||
getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' })
|
||||
};
|
||||
@@ -171,7 +171,7 @@ describe('request methods', () => {
|
||||
project: 'myproject',
|
||||
appId: 'my-appid',
|
||||
location: 'moon',
|
||||
backend: new VertexAIBackend(),
|
||||
backend: new AgentPlatformBackend(),
|
||||
automaticDataCollectionEnabled: true,
|
||||
getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }),
|
||||
getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' })
|
||||
@@ -196,7 +196,7 @@ describe('request methods', () => {
|
||||
project: 'myproject',
|
||||
appId: 'my-appid',
|
||||
location: 'moon',
|
||||
backend: new VertexAIBackend(),
|
||||
backend: new AgentPlatformBackend(),
|
||||
automaticDataCollectionEnabled: false,
|
||||
getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }),
|
||||
getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' })
|
||||
@@ -224,7 +224,7 @@ describe('request methods', () => {
|
||||
project: 'myproject',
|
||||
appId: 'my-appid',
|
||||
location: 'moon',
|
||||
backend: new VertexAIBackend()
|
||||
backend: new AgentPlatformBackend()
|
||||
},
|
||||
stream: true,
|
||||
singleRequestOptions: undefined
|
||||
@@ -258,7 +258,7 @@ describe('request methods', () => {
|
||||
project: 'myproject',
|
||||
appId: 'my-appid',
|
||||
location: 'moon',
|
||||
backend: new VertexAIBackend(),
|
||||
backend: new AgentPlatformBackend(),
|
||||
getAppCheckToken: () =>
|
||||
Promise.resolve({ token: 'dummytoken', error: Error('oops') })
|
||||
},
|
||||
@@ -286,7 +286,7 @@ describe('request methods', () => {
|
||||
project: 'myproject',
|
||||
appId: 'my-appid',
|
||||
location: 'moon',
|
||||
backend: new VertexAIBackend()
|
||||
backend: new AgentPlatformBackend()
|
||||
},
|
||||
stream: true,
|
||||
singleRequestOptions: undefined
|
||||
|
||||
@@ -71,7 +71,7 @@ export function createEnhancedContentResponse(
|
||||
inferenceSource: InferenceSource = InferenceSource.IN_CLOUD
|
||||
): EnhancedGenerateContentResponse {
|
||||
/**
|
||||
* The Vertex AI backend omits default values.
|
||||
* The AgentPlatform backend omits default values.
|
||||
* This causes the `index` property to be omitted from the first candidate in the
|
||||
* response, since it has index 0, and 0 is a default value.
|
||||
* See: https://github.com/firebase/firebase-js-sdk/issues/8566
|
||||
@@ -122,8 +122,7 @@ export function addHelpers(
|
||||
return undefined;
|
||||
};
|
||||
(response as EnhancedGenerateContentResponse).inlineDataParts = ():
|
||||
| InlineDataPart[]
|
||||
| undefined => {
|
||||
InlineDataPart[] | undefined => {
|
||||
if (hasValidCandidates(response)) {
|
||||
return getInlineDataParts(response);
|
||||
} else if (response.promptFeedback) {
|
||||
|
||||
@@ -27,7 +27,8 @@ import {
|
||||
/**
|
||||
* 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.
|
||||
* `JSON.stringify()` into a JSON string accepted by Agent Platform Gemini
|
||||
* API and Gemini Developer API REST endpoints.
|
||||
* (This string conversion is automatically done when calling SDK methods.)
|
||||
* @public
|
||||
*/
|
||||
@@ -243,7 +244,10 @@ export class StringSchema extends Schema {
|
||||
* @public
|
||||
*/
|
||||
export class ArraySchema extends Schema {
|
||||
constructor(schemaParams: SchemaParams, public items: TypedSchema) {
|
||||
constructor(
|
||||
schemaParams: SchemaParams,
|
||||
public items: TypedSchema
|
||||
) {
|
||||
super({
|
||||
type: SchemaType.ARRAY,
|
||||
...schemaParams
|
||||
|
||||
@@ -39,14 +39,14 @@ import {
|
||||
} from '../types';
|
||||
import { AIError } from '../errors';
|
||||
import { ApiSettings } from '../types/internal';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { AgentPlatformBackend } from '../backend';
|
||||
|
||||
const fakeApiSettings: ApiSettings = {
|
||||
apiKey: 'key',
|
||||
project: 'my-project',
|
||||
appId: 'my-appid',
|
||||
location: 'us-central1',
|
||||
backend: new VertexAIBackend()
|
||||
location: 'global',
|
||||
backend: new AgentPlatformBackend()
|
||||
};
|
||||
|
||||
use(sinonChai);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { VertexAIBackend } from './backend';
|
||||
import { AgentPlatformBackend } 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, new VertexAIBackend());
|
||||
const ai = new AIService(fakeApp, new AgentPlatformBackend());
|
||||
expect(ai.location).to.equal(DEFAULT_LOCATION);
|
||||
});
|
||||
it('uses custom location if specified', () => {
|
||||
const ai = new AIService(
|
||||
fakeApp,
|
||||
new VertexAIBackend('somewhere'),
|
||||
new AgentPlatformBackend('somewhere'),
|
||||
/* authProvider */ undefined,
|
||||
/* appCheckProvider */ undefined
|
||||
);
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
FirebaseAuthInternal,
|
||||
FirebaseAuthInternalName
|
||||
} from '@firebase/auth-interop-types';
|
||||
import { Backend, VertexAIBackend } from './backend';
|
||||
import { AgentPlatformBackend, Backend, VertexAIBackend } from './backend';
|
||||
|
||||
export class AIService implements AI, _FirebaseService {
|
||||
auth: FirebaseAuthInternal | null;
|
||||
@@ -56,7 +56,10 @@ export class AIService implements AI, _FirebaseService {
|
||||
this.auth = auth || null;
|
||||
this.appCheck = appCheck || null;
|
||||
|
||||
if (backend instanceof VertexAIBackend) {
|
||||
if (
|
||||
backend instanceof VertexAIBackend ||
|
||||
backend instanceof AgentPlatformBackend
|
||||
) {
|
||||
this.location = backend.location;
|
||||
} else {
|
||||
this.location = '';
|
||||
|
||||
@@ -74,7 +74,7 @@ export interface ImagenResponseInternal {
|
||||
|
||||
/**
|
||||
* The parameters to be sent in the request body of the HTTP call
|
||||
* to the Vertex AI backend.
|
||||
* to the backend.
|
||||
*
|
||||
* We need a separate internal-only interface for this because the REST
|
||||
* API expects different parameter names than what we show to our users.
|
||||
|
||||
@@ -34,7 +34,7 @@ export interface ImagenModelParams {
|
||||
*
|
||||
* Only Imagen 3 models (named `imagen-3.0-*`) are supported.
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/vertex-ai/models | model versions}
|
||||
* See {@link https://firebase.google.com/docs/ai-logic/models | model versions}
|
||||
* for a full list of supported Imagen 3 models.
|
||||
*/
|
||||
model: string;
|
||||
@@ -51,7 +51,7 @@ export interface ImagenModelParams {
|
||||
/**
|
||||
* Configuration options for generating images with Imagen.
|
||||
*
|
||||
* See the {@link http://firebase.google.com/docs/vertex-ai/generate-images-imagen | documentation} for
|
||||
* See the {@link http://firebase.google.com/docs/ai-logic/generate-images-imagen | documentation} for
|
||||
* more details.
|
||||
*
|
||||
* @deprecated All Imagen models are deprecated and will shut down as
|
||||
@@ -67,7 +67,7 @@ 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.
|
||||
* See the {@link http://firebase.google.com/docs/ai-logic/model-parameters#imagen | documentation} for more details.
|
||||
*
|
||||
* This is no longer supported in the Gemini Developer API ({@link GoogleAIBackend}) in versions
|
||||
* greater than `imagen-3.0-generate-002`.
|
||||
@@ -77,7 +77,7 @@ export interface ImagenGenerationConfig {
|
||||
* 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 <a href="http://firebase.google.com/docs/vertex-ai/model-parameters#imagen">sampleCount</a>
|
||||
* (typically up to 4); see the <a href="http://firebase.google.com/docs/ai-logic/model-parameters#imagen">sampleCount</a>
|
||||
* documentation for more details.
|
||||
*/
|
||||
numberOfImages?: number;
|
||||
@@ -99,7 +99,7 @@ export interface ImagenGenerationConfig {
|
||||
* 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 <a href="http://firebase.google.com/docs/vertex-ai/model-parameters#imagen">addWatermark</a>
|
||||
* For Imagen 3 models, the default value is `true`; see the <a href="http://firebase.google.com/docs/ai-logic/model-parameters#imagen">addWatermark</a>
|
||||
* documentation for more details.
|
||||
*
|
||||
* When using the Gemini Developer API ({@link GoogleAIBackend}), this will default to true,
|
||||
@@ -114,7 +114,7 @@ export interface ImagenGenerationConfig {
|
||||
* 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 {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
||||
* filter out potentially harmful content from responses. See the {@link http://firebase.google.com/docs/ai-logic/generate-images | documentation }
|
||||
* and the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters | Responsible AI and usage guidelines}
|
||||
* for more details.
|
||||
*
|
||||
@@ -153,7 +153,7 @@ export const ImagenSafetyFilterLevel = {
|
||||
* 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 {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
||||
* filter out potentially harmful content from responses. See the {@link http://firebase.google.com/docs/ai-logic/generate-images | documentation }
|
||||
* and the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters | Responsible AI and usage guidelines}
|
||||
* for more details.
|
||||
*
|
||||
@@ -170,7 +170,7 @@ export type ImagenSafetyFilterLevel =
|
||||
/**
|
||||
* A filter level controlling whether generation of images containing people or faces is allowed.
|
||||
*
|
||||
* See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a>
|
||||
* See the <a href="http://firebase.google.com/docs/ai-logic/generate-images">personGeneration</a>
|
||||
* documentation for more details.
|
||||
*
|
||||
* @deprecated All Imagen models are deprecated and will shut down as
|
||||
@@ -206,7 +206,7 @@ export const ImagenPersonFilterLevel = {
|
||||
/**
|
||||
* A filter level controlling whether generation of images containing people or faces is allowed.
|
||||
*
|
||||
* See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a>
|
||||
* See the <a href="http://firebase.google.com/docs/ai-logic/generate-images">personGeneration</a>
|
||||
* documentation for more details.
|
||||
*
|
||||
* @deprecated All Imagen models are deprecated and will shut down as
|
||||
@@ -222,7 +222,7 @@ export type ImagenPersonFilterLevel =
|
||||
/**
|
||||
* Settings for controlling the aggressiveness of filtering out sensitive content.
|
||||
*
|
||||
* See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
||||
* See the {@link http://firebase.google.com/docs/ai-logic/generate-images | documentation }
|
||||
* for more details.
|
||||
*
|
||||
* @deprecated All Imagen models are deprecated and will shut down as
|
||||
@@ -250,7 +250,7 @@ export interface ImagenSafetySettings {
|
||||
* To specify an aspect ratio for generated images, set the `aspectRatio` property in your
|
||||
* {@link ImagenGenerationConfig}.
|
||||
*
|
||||
* See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
||||
* See the {@link http://firebase.google.com/docs/ai-logic/generate-images | documentation }
|
||||
* for more details and examples of the supported aspect ratios.
|
||||
*
|
||||
* @deprecated All Imagen models are deprecated and will shut down as
|
||||
@@ -289,7 +289,7 @@ export const ImagenAspectRatio = {
|
||||
* To specify an aspect ratio for generated images, set the `aspectRatio` property in your
|
||||
* {@link ImagenGenerationConfig}.
|
||||
*
|
||||
* See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
||||
* See the {@link http://firebase.google.com/docs/ai-logic/generate-images | documentation }
|
||||
* for more details and examples of the supported aspect ratios.
|
||||
*
|
||||
* @deprecated All Imagen models are deprecated and will shut down as
|
||||
|
||||
@@ -92,8 +92,10 @@ export interface TemplateGenerateContentRequest {
|
||||
* Internal version of the template generate content request.
|
||||
* @internal
|
||||
*/
|
||||
export interface TemplateRequestInternal
|
||||
extends Omit<TemplateGenerateContentRequest, 'tools'> {
|
||||
export interface TemplateRequestInternal extends Omit<
|
||||
TemplateGenerateContentRequest,
|
||||
'tools'
|
||||
> {
|
||||
tools?: TemplateFunctionDeclarationsToolInternal[];
|
||||
}
|
||||
|
||||
@@ -107,7 +109,7 @@ export interface SafetySetting {
|
||||
/**
|
||||
* The harm block method.
|
||||
*
|
||||
* This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
|
||||
* This property is only supported in the Agent Platform Gemini API ({@link AgentPlatformBackend}).
|
||||
* When using the Gemini Developer API ({@link GoogleAIBackend}), an {@link AIError} will be
|
||||
* thrown if this property is defined.
|
||||
*/
|
||||
@@ -170,7 +172,7 @@ export interface GenerationConfig {
|
||||
* Generation modalities to be returned in generation responses.
|
||||
*
|
||||
* @remarks
|
||||
* - Multimodal response generation is only supported by some Gemini models and versions; see {@link https://firebase.google.com/docs/vertex-ai/models | model versions}.
|
||||
* - Multimodal response generation is only supported by some Gemini models and versions; see {@link https://firebase.google.com/docs/ai-logic/models | model versions}.
|
||||
* - Only image generation (`ResponseModality.IMAGE`) is supported.
|
||||
*
|
||||
* @beta
|
||||
@@ -335,8 +337,10 @@ export interface StartChatParams extends BaseParams {
|
||||
* Params for {@link TemplateGenerativeModel.startChat}.
|
||||
* @beta
|
||||
*/
|
||||
export interface StartTemplateChatParams
|
||||
extends Omit<StartChatParams, 'tools'> {
|
||||
export interface StartTemplateChatParams extends Omit<
|
||||
StartChatParams,
|
||||
'tools'
|
||||
> {
|
||||
/**
|
||||
* The ID of the server-side template to execute.
|
||||
*/
|
||||
@@ -488,7 +492,7 @@ export interface FunctionDeclaration {
|
||||
*
|
||||
* Important: If using Grounding with Google Search, you are required to comply with the
|
||||
* "Grounding with Google Search" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
|
||||
* or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* or Agent Platform Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* section within the Service Specific Terms).
|
||||
*
|
||||
* @public
|
||||
@@ -500,7 +504,7 @@ export interface GoogleSearchTool {
|
||||
*
|
||||
* When using this feature, you are required to comply with the "Grounding with Google Search"
|
||||
* usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
|
||||
* or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* or Agent Platform Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* section within the Service Specific Terms).
|
||||
*/
|
||||
googleSearch: GoogleSearch;
|
||||
@@ -512,7 +516,7 @@ export interface GoogleSearchTool {
|
||||
*
|
||||
* Important: If using Grounding with Google Maps, you are required to comply with the
|
||||
* "Grounding with Google Maps" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API}
|
||||
* or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* or Agent Platform Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* section within the Service Specific Terms).
|
||||
*
|
||||
* @public
|
||||
@@ -523,7 +527,7 @@ export interface GoogleMapsTool {
|
||||
*
|
||||
* When using this feature, you are required to comply with the "Grounding with Google Maps"
|
||||
* usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API}
|
||||
* or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* or Agent Platform Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* section within the Service Specific Terms).
|
||||
*/
|
||||
googleMaps: GoogleMaps;
|
||||
@@ -658,8 +662,10 @@ export interface TemplateFunctionDeclaration {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface TemplateFunctionDeclarationInternal
|
||||
extends Omit<TemplateFunctionDeclaration, 'parameters'> {
|
||||
export interface TemplateFunctionDeclarationInternal extends Omit<
|
||||
TemplateFunctionDeclaration,
|
||||
'parameters'
|
||||
> {
|
||||
inputSchema?: ObjectSchema | ObjectSchemaRequest;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,7 @@ export interface GenerateContentStreamResult {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface EnhancedGenerateContentResponse
|
||||
extends GenerateContentResponse {
|
||||
export interface EnhancedGenerateContentResponse extends GenerateContentResponse {
|
||||
/**
|
||||
* Returns the text string from the response, if available.
|
||||
* Throws if the prompt or candidate was blocked.
|
||||
@@ -170,7 +169,7 @@ export interface PromptFeedback {
|
||||
/**
|
||||
* A human-readable description of the `blockReason`.
|
||||
*
|
||||
* This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
|
||||
* This property is only supported in the Agent Platform Gemini API ({@link AgentPlatformBackend}).
|
||||
*/
|
||||
blockReasonMessage?: string;
|
||||
}
|
||||
@@ -210,13 +209,13 @@ export interface Citation {
|
||||
/**
|
||||
* The title of the cited source, if available.
|
||||
*
|
||||
* This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
|
||||
* This property is only supported in the Agent Platform Gemini API ({@link AgentPlatformBackend}).
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* The publication date of the cited source, if available.
|
||||
*
|
||||
* This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
|
||||
* This property is only supported in the Agent Platform Gemini API ({@link AgentPlatformBackend}).
|
||||
*/
|
||||
publicationDate?: Date;
|
||||
}
|
||||
@@ -229,12 +228,12 @@ export interface Citation {
|
||||
*
|
||||
* Important: If using Grounding with Google Search, you are required to comply with the
|
||||
* "Grounding with Google Search" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-search | Gemini Developer API}
|
||||
* or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* or Agent Platform Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* section within the Service Specific Terms).
|
||||
*
|
||||
* Important: If using Grounding with Google Maps, you are required to comply with the
|
||||
* "Grounding with Google Maps" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API}
|
||||
* or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* or Agent Platform Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms}
|
||||
* section within the Service Specific Terms).
|
||||
*
|
||||
* @public
|
||||
@@ -335,7 +334,7 @@ export interface WebGroundingChunk {
|
||||
/**
|
||||
* The domain of the original URI from which the content was retrieved.
|
||||
*
|
||||
* This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
|
||||
* This property is only supported in the Agent Platform Gemini API ({@link AgentPlatformBackend}).
|
||||
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
|
||||
* `undefined`.
|
||||
*/
|
||||
@@ -546,21 +545,21 @@ export interface SafetyRating {
|
||||
/**
|
||||
* The harm severity level.
|
||||
*
|
||||
* This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
|
||||
* This property is only supported when using the Agent Platform Gemini API ({@link AgentPlatformBackend}).
|
||||
* 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 Vertex AI Gemini API ({@link VertexAIBackend}).
|
||||
* This property is only supported when using the Agent Platform Gemini API ({@link AgentPlatformBackend}).
|
||||
* 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 Vertex AI Gemini API ({@link VertexAIBackend}).
|
||||
* This property is only supported when using the Agent Platform Gemini API ({@link AgentPlatformBackend}).
|
||||
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0.
|
||||
*/
|
||||
severityScore: number;
|
||||
|
||||
@@ -26,6 +26,7 @@ import { FirebaseAppCheckInternal } from '@firebase/app-check-interop-types';
|
||||
import { AI_TYPE } from '../src/constants';
|
||||
import { factory as factoryNode } from '../src/factory-node';
|
||||
import { ChromeAdapter, InferenceMode } from '../src/types';
|
||||
import { AgentPlatformBackend, AI } from '../src';
|
||||
|
||||
const fakeConfig = {
|
||||
projectId: 'projectId',
|
||||
@@ -82,3 +83,17 @@ export const fakeChromeAdapter: ChromeAdapter = {
|
||||
generateContentStream: () => Promise.resolve({} as Response),
|
||||
countTokens: () => Promise.resolve({} as Response)
|
||||
};
|
||||
|
||||
export const fakeAI: AI = {
|
||||
app: {
|
||||
name: 'DEFAULT',
|
||||
automaticDataCollectionEnabled: true,
|
||||
options: {
|
||||
apiKey: 'key',
|
||||
projectId: 'my-project',
|
||||
appId: 'my-appid'
|
||||
}
|
||||
},
|
||||
backend: new AgentPlatformBackend('global'),
|
||||
location: 'global'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user