mirror of
https://github.com/hanzoai/firebase-js-sdk.git
synced 2026-09-24 16:59:10 +00:00
feat(ai) Google Maps Grounding Support (#9458)
### Discussion Implement new tools to use Grounding with Google Maps, similar to how Grounding with Google Search works. ### Testing Integration tests. Unit tests. Node standalone app. Updated Quickstart React-based app (not part of this PR). ### API Changes - Grounding with Google Maps support, see internal doc: go/fal-maps-grounding-api - TemplateToolConfig, see internal doc: go/firebase-ai-server-prompt-template
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@firebase/ai': minor
|
||||
'firebase': minor
|
||||
---
|
||||
|
||||
AI Logic : Feature : Added support for Grounding with Google Maps.
|
||||
@@ -690,6 +690,25 @@ export interface GoogleAIGenerateContentResponse {
|
||||
usageMetadata?: UsageMetadata;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface GoogleMaps {
|
||||
// (undocumented)
|
||||
enableWidget?: boolean;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface GoogleMapsGroundingChunk {
|
||||
placeId?: string;
|
||||
text?: string;
|
||||
title?: string;
|
||||
uri?: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface GoogleMapsTool {
|
||||
googleMaps: GoogleMaps;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface GoogleSearch {
|
||||
}
|
||||
@@ -701,11 +720,13 @@ export interface GoogleSearchTool {
|
||||
|
||||
// @public
|
||||
export interface GroundingChunk {
|
||||
maps?: GoogleMapsGroundingChunk;
|
||||
web?: WebGroundingChunk;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface GroundingMetadata {
|
||||
googleMapsWidgetContextToken?: string;
|
||||
groundingChunks?: GroundingChunk[];
|
||||
groundingSupports?: GroundingSupport[];
|
||||
// @deprecated (undocumented)
|
||||
@@ -987,6 +1008,12 @@ export interface LanguageModelPromptOptions {
|
||||
responseConstraint?: object;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface LatLng {
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
}
|
||||
|
||||
// @beta
|
||||
export interface LiveGenerationConfig {
|
||||
contextWindowCompression?: ContextWindowCompressionConfig;
|
||||
@@ -1224,6 +1251,12 @@ export const ResponseModality: {
|
||||
// @beta
|
||||
export type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality];
|
||||
|
||||
// @public
|
||||
export interface RetrievalConfig {
|
||||
languageCode?: string;
|
||||
latLng?: LatLng;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface RetrievedContextAttribution {
|
||||
// (undocumented)
|
||||
@@ -1480,8 +1513,8 @@ export class TemplateGenerativeModel {
|
||||
constructor(ai: AI, requestOptions?: RequestOptions);
|
||||
// @internal (undocumented)
|
||||
_apiSettings: ApiSettings;
|
||||
generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
|
||||
generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
|
||||
generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentResult>;
|
||||
generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentStreamResult>;
|
||||
requestOptions?: RequestOptions;
|
||||
startChat(params: StartTemplateChatParams): TemplateChatSession;
|
||||
}
|
||||
@@ -1507,6 +1540,12 @@ export interface TemplateRequestInternal extends Omit<TemplateGenerateContentReq
|
||||
// @beta
|
||||
export type TemplateTool = TemplateFunctionDeclarationsTool;
|
||||
|
||||
// @public
|
||||
export interface TemplateToolConfig {
|
||||
// (undocumented)
|
||||
retrievalConfig?: RetrievalConfig;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface TextPart {
|
||||
// (undocumented)
|
||||
@@ -1546,12 +1585,14 @@ export const ThinkingLevel: {
|
||||
export type ThinkingLevel = (typeof ThinkingLevel)[keyof typeof ThinkingLevel];
|
||||
|
||||
// @public
|
||||
export type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool;
|
||||
export type Tool = FunctionDeclarationsTool | GoogleMapsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool;
|
||||
|
||||
// @public
|
||||
export interface ToolConfig {
|
||||
// (undocumented)
|
||||
functionCallingConfig?: FunctionCallingConfig;
|
||||
// (undocumented)
|
||||
retrievalConfig?: RetrievalConfig;
|
||||
}
|
||||
|
||||
// @beta
|
||||
|
||||
@@ -98,6 +98,12 @@ toc:
|
||||
path: /docs/reference/js/ai.generativemodel.md
|
||||
- title: GoogleAIBackend
|
||||
path: /docs/reference/js/ai.googleaibackend.md
|
||||
- title: GoogleMaps
|
||||
path: /docs/reference/js/ai.googlemaps.md
|
||||
- title: GoogleMapsGroundingChunk
|
||||
path: /docs/reference/js/ai.googlemapsgroundingchunk.md
|
||||
- title: GoogleMapsTool
|
||||
path: /docs/reference/js/ai.googlemapstool.md
|
||||
- title: GoogleSearch
|
||||
path: /docs/reference/js/ai.googlesearch.md
|
||||
- title: GoogleSearchTool
|
||||
@@ -142,6 +148,8 @@ toc:
|
||||
path: /docs/reference/js/ai.languagemodelmessagecontent.md
|
||||
- title: LanguageModelPromptOptions
|
||||
path: /docs/reference/js/ai.languagemodelpromptoptions.md
|
||||
- title: LatLng
|
||||
path: /docs/reference/js/ai.latlng.md
|
||||
- title: LiveGenerationConfig
|
||||
path: /docs/reference/js/ai.livegenerationconfig.md
|
||||
- title: LiveGenerativeModel
|
||||
@@ -178,6 +186,8 @@ toc:
|
||||
path: /docs/reference/js/ai.promptfeedback.md
|
||||
- title: RequestOptions
|
||||
path: /docs/reference/js/ai.requestoptions.md
|
||||
- title: RetrievalConfig
|
||||
path: /docs/reference/js/ai.retrievalconfig.md
|
||||
- title: RetrievedContextAttribution
|
||||
path: /docs/reference/js/ai.retrievedcontextattribution.md
|
||||
- title: SafetyRating
|
||||
@@ -224,6 +234,8 @@ toc:
|
||||
path: /docs/reference/js/ai.templategenerativemodel.md
|
||||
- title: TemplateImagenModel
|
||||
path: /docs/reference/js/ai.templateimagenmodel.md
|
||||
- title: TemplateToolConfig
|
||||
path: /docs/reference/js/ai.templatetoolconfig.md
|
||||
- title: TextPart
|
||||
path: /docs/reference/js/ai.textpart.md
|
||||
- title: ThinkingConfig
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
Project: /docs/reference/js/_project.yaml
|
||||
Book: /docs/reference/_book.yaml
|
||||
page_type: reference
|
||||
|
||||
{% comment %}
|
||||
DO NOT EDIT THIS FILE!
|
||||
This is generated by the JS SDK team, and any local changes will be
|
||||
overwritten. Changes should be made in the source code at
|
||||
https://github.com/firebase/firebase-js-sdk
|
||||
{% endcomment %}
|
||||
|
||||
# GoogleMaps interface
|
||||
Specifies the Google Maps configuration.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface GoogleMaps
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [enableWidget](./ai.googlemaps.md#googlemapsenablewidget) | boolean | |
|
||||
|
||||
## GoogleMaps.enableWidget
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
enableWidget?: boolean;
|
||||
```
|
||||
@@ -0,0 +1,70 @@
|
||||
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 %}
|
||||
|
||||
# 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".
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface GoogleMapsGroundingChunk
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [placeId](./ai.googlemapsgroundingchunk.md#googlemapsgroundingchunkplaceid) | string | This Place's resource name, in <code>places/{place_id}</code> format. This can be used to look up the place in the Google Maps API. |
|
||||
| [text](./ai.googlemapsgroundingchunk.md#googlemapsgroundingchunktext) | string | The text of the place answer. |
|
||||
| [title](./ai.googlemapsgroundingchunk.md#googlemapsgroundingchunktitle) | string | The title of the place. |
|
||||
| [uri](./ai.googlemapsgroundingchunk.md#googlemapsgroundingchunkuri) | string | The URI of the place. |
|
||||
|
||||
## GoogleMapsGroundingChunk.placeId
|
||||
|
||||
This Place's resource name, in `places/{place_id}` format. This can be used to look up the place in the Google Maps API.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
placeId?: string;
|
||||
```
|
||||
|
||||
## GoogleMapsGroundingChunk.text
|
||||
|
||||
The text of the place answer.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
text?: string;
|
||||
```
|
||||
|
||||
## GoogleMapsGroundingChunk.title
|
||||
|
||||
The title of the place.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
title?: string;
|
||||
```
|
||||
|
||||
## GoogleMapsGroundingChunk.uri
|
||||
|
||||
The URI of the place.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
uri?: string;
|
||||
```
|
||||
@@ -0,0 +1,39 @@
|
||||
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 %}
|
||||
|
||||
# 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).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface GoogleMapsTool
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| 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). |
|
||||
|
||||
## 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).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
googleMaps: GoogleMaps;
|
||||
```
|
||||
@@ -22,8 +22,19 @@ export interface GroundingChunk
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [maps](./ai.groundingchunk.md#groundingchunkmaps) | [GoogleMapsGroundingChunk](./ai.googlemapsgroundingchunk.md#googlemapsgroundingchunk_interface) | Contains details if the grounding chunk is from a Google Maps source. |
|
||||
| [web](./ai.groundingchunk.md#groundingchunkweb) | [WebGroundingChunk](./ai.webgroundingchunk.md#webgroundingchunk_interface) | Contains details if the grounding chunk is from a web source. |
|
||||
|
||||
## GroundingChunk.maps
|
||||
|
||||
Contains details if the grounding chunk is from a Google Maps source.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
maps?: GoogleMapsGroundingChunk;
|
||||
```
|
||||
|
||||
## GroundingChunk.web
|
||||
|
||||
Contains details if the grounding chunk is from a web source.
|
||||
|
||||
@@ -12,10 +12,12 @@ https://github.com/firebase/firebase-js-sdk
|
||||
# GroundingMetadata interface
|
||||
Metadata returned when grounding is enabled.
|
||||
|
||||
Currently, only Grounding with Google Search is supported (see [GoogleSearchTool](./ai.googlesearchtool.md#googlesearchtool_interface)<!-- -->).
|
||||
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).
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
@@ -26,12 +28,23 @@ export interface GroundingMetadata
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [googleMapsWidgetContextToken](./ai.groundingmetadata.md#groundingmetadatagooglemapswidgetcontexttoken) | string | Resource name of the Google Maps widget context token that can be used with the <code>PlacesContextElement</code> widget in order to render contextual data. Only populated in the case that grounding with Google Maps is enabled. |
|
||||
| [groundingChunks](./ai.groundingmetadata.md#groundingmetadatagroundingchunks) | [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface)<!-- -->\[\] | A list of [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface) objects. Each chunk represents a piece of retrieved content (for example, from a web page). that the model used to ground its response. |
|
||||
| [groundingSupports](./ai.groundingmetadata.md#groundingmetadatagroundingsupports) | [GroundingSupport](./ai.groundingsupport.md#groundingsupport_interface)<!-- -->\[\] | A list of [GroundingSupport](./ai.groundingsupport.md#groundingsupport_interface) objects. Each object details how specific segments of the model's response are supported by the <code>groundingChunks</code>. |
|
||||
| [retrievalQueries](./ai.groundingmetadata.md#groundingmetadataretrievalqueries) | string\[\] | |
|
||||
| [searchEntryPoint](./ai.groundingmetadata.md#groundingmetadatasearchentrypoint) | [SearchEntrypoint](./ai.searchentrypoint.md#searchentrypoint_interface) | Google Search entry point for web searches. This contains an HTML/CSS snippet that must be embedded in an app to display a Google Search entry point for follow-up web searches related to a model's "Grounded Response". |
|
||||
| [webSearchQueries](./ai.groundingmetadata.md#groundingmetadatawebsearchqueries) | string\[\] | A list of web search queries that the model performed to gather the grounding information. These can be used to allow users to explore the search results themselves. |
|
||||
|
||||
## GroundingMetadata.googleMapsWidgetContextToken
|
||||
|
||||
Resource name of the Google Maps widget context token that can be used with the `PlacesContextElement` widget in order to render contextual data. Only populated in the case that grounding with Google Maps is enabled.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
googleMapsWidgetContextToken?: string;
|
||||
```
|
||||
|
||||
## GroundingMetadata.groundingChunks
|
||||
|
||||
A list of [GroundingChunk](./ai.groundingchunk.md#groundingchunk_interface) objects. Each chunk represents a piece of retrieved content (for example, from a web page). that the model used to ground its response.
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
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 %}
|
||||
|
||||
# LatLng interface
|
||||
An object that represents a latitude/longitude pair.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface LatLng
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [latitude](./ai.latlng.md#latlnglatitude) | number | The latitude in degrees. It must be in the range <code>[-90.0, +90.0]</code>. |
|
||||
| [longitude](./ai.latlng.md#latlnglongitude) | number | The longitude in degrees. It must be in the range <code>[-180.0, +180.0]</code>. |
|
||||
|
||||
## LatLng.latitude
|
||||
|
||||
The latitude in degrees. It must be in the range `[-90.0, +90.0]`<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
latitude?: number;
|
||||
```
|
||||
|
||||
## LatLng.longitude
|
||||
|
||||
The longitude in degrees. It must be in the range `[-180.0, +180.0]`<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
longitude?: number;
|
||||
```
|
||||
+8
-2
@@ -95,10 +95,13 @@ The Firebase AI Web SDK.
|
||||
| [GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface) | Result object returned from [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream) call. Iterate over <code>stream</code> to get chunks as they come in and/or use the <code>response</code> promise to get the aggregated response when the stream is done. |
|
||||
| [GenerationConfig](./ai.generationconfig.md#generationconfig_interface) | Config options for content-related requests |
|
||||
| [GenerativeContentBlob](./ai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. |
|
||||
| [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). |
|
||||
| [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). |
|
||||
| [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 is supported (see [GoogleSearchTool](./ai.googlesearchtool.md#googlesearchtool_interface)<!-- -->).<!-- -->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). |
|
||||
| [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). |
|
||||
| [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) | <b><i>(Public Preview)</i></b> Configures hybrid inference. |
|
||||
| [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. |
|
||||
@@ -114,6 +117,7 @@ The Firebase AI Web SDK.
|
||||
| [LanguageModelMessage](./ai.languagemodelmessage.md#languagemodelmessage_interface) | <b><i>(Public Preview)</i></b> An on-device language model message. |
|
||||
| [LanguageModelMessageContent](./ai.languagemodelmessagecontent.md#languagemodelmessagecontent_interface) | <b><i>(Public Preview)</i></b> An on-device language model content object. |
|
||||
| [LanguageModelPromptOptions](./ai.languagemodelpromptoptions.md#languagemodelpromptoptions_interface) | <b><i>(Public Preview)</i></b> Options for an on-device language model prompt. |
|
||||
| [LatLng](./ai.latlng.md#latlng_interface) | An object that represents a latitude/longitude pair. |
|
||||
| [LiveGenerationConfig](./ai.livegenerationconfig.md#livegenerationconfig_interface) | <b><i>(Public Preview)</i></b> Configuration parameters used by [LiveGenerativeModel](./ai.livegenerativemodel.md#livegenerativemodel_class) to control live content generation. |
|
||||
| [LiveModelParams](./ai.livemodelparams.md#livemodelparams_interface) | <b><i>(Public Preview)</i></b> Params passed to [getLiveGenerativeModel()](./ai.md#getlivegenerativemodel_f2099ac)<!-- -->. |
|
||||
| [LiveServerContent](./ai.liveservercontent.md#liveservercontent_interface) | <b><i>(Public Preview)</i></b> An incremental content update from the model. |
|
||||
@@ -128,6 +132,7 @@ The Firebase AI Web SDK.
|
||||
| [PrebuiltVoiceConfig](./ai.prebuiltvoiceconfig.md#prebuiltvoiceconfig_interface) | <b><i>(Public Preview)</i></b> Configuration for a pre-built voice. |
|
||||
| [PromptFeedback](./ai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with <code>blockReason</code> and the relevant <code>safetyRatings</code>. |
|
||||
| [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_c63f46a)<!-- -->. |
|
||||
| [RetrievalConfig](./ai.retrievalconfig.md#retrievalconfig_interface) | Configuration options for data retrieval tools. |
|
||||
| [RetrievedContextAttribution](./ai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | |
|
||||
| [SafetyRating](./ai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./ai.generatecontentcandidate.md#generatecontentcandidate_interface) |
|
||||
| [SafetySetting](./ai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. |
|
||||
@@ -147,6 +152,7 @@ The Firebase AI Web SDK.
|
||||
| [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_interface) | <b><i>(Public Preview)</i></b> Interface representing a <code>ChatSession</code> class for use with server prompt templates that enables sending chat messages and stores history of sent and received messages so far. |
|
||||
| [TemplateFunctionDeclaration](./ai.templatefunctiondeclaration.md#templatefunctiondeclaration_interface) | <b><i>(Public Preview)</i></b> Structured representation of a template function declaration. Included in this declaration are the function name and parameters. This <code>TemplateFunctionDeclaration</code> is a representation of a block of code that can be used as a Tool by the model and executed by the client. Note: Template function declarations do not support description fields. |
|
||||
| [TemplateFunctionDeclarationsTool](./ai.templatefunctiondeclarationstool.md#templatefunctiondeclarationstool_interface) | <b><i>(Public Preview)</i></b> A piece of code that enables the system to interact with external systems. |
|
||||
| [TemplateToolConfig](./ai.templatetoolconfig.md#templatetoolconfig_interface) | Tool configuration for <code>TemplateGenerativeModel</code>s. This config is shared for all tools provided in the server prompt template request. |
|
||||
| [TextPart](./ai.textpart.md#textpart_interface) | Content part interface if the part represents a text string. |
|
||||
| [ThinkingConfig](./ai.thinkingconfig.md#thinkingconfig_interface) | Configuration for "thinking" behavior of compatible Gemini models.<!-- -->Certain models utilize a thinking process before generating a response. This allows them to reason through complex problems and plan a more coherent and accurate answer. |
|
||||
| [ToolConfig](./ai.toolconfig.md#toolconfig_interface) | Tool config. This config is shared for all tools provided in the request. |
|
||||
@@ -1225,7 +1231,7 @@ Defines a tool that model can call to access external knowledge.
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool;
|
||||
export type Tool = FunctionDeclarationsTool | GoogleMapsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool;
|
||||
```
|
||||
|
||||
## TypedSchema
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
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 %}
|
||||
|
||||
# RetrievalConfig interface
|
||||
Configuration options for data retrieval tools.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface RetrievalConfig
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [languageCode](./ai.retrievalconfig.md#retrievalconfiglanguagecode) | string | The language code of the user. |
|
||||
| [latLng](./ai.retrievalconfig.md#retrievalconfiglatlng) | [LatLng](./ai.latlng.md#latlng_interface) | The location of the user. |
|
||||
|
||||
## RetrievalConfig.languageCode
|
||||
|
||||
The language code of the user.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
languageCode?: string;
|
||||
```
|
||||
|
||||
## RetrievalConfig.latLng
|
||||
|
||||
The location of the user.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
latLng?: LatLng;
|
||||
```
|
||||
@@ -39,8 +39,8 @@ export declare class TemplateGenerativeModel
|
||||
|
||||
| Method | Modifiers | Description |
|
||||
| --- | --- | --- |
|
||||
| [generateContent(templateId, templateVariables, singleRequestOptions)](./ai.templategenerativemodel.md#templategenerativemodelgeneratecontent) | | <b><i>(Public Preview)</i></b> Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->. |
|
||||
| [generateContentStream(templateId, templateVariables, singleRequestOptions)](./ai.templategenerativemodel.md#templategenerativemodelgeneratecontentstream) | | <b><i>(Public Preview)</i></b> Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. |
|
||||
| [generateContent(templateId, templateVariables, singleRequestOptions, templateToolConfig)](./ai.templategenerativemodel.md#templategenerativemodelgeneratecontent) | | <b><i>(Public Preview)</i></b> Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->. |
|
||||
| [generateContentStream(templateId, templateVariables, singleRequestOptions, templateToolConfig)](./ai.templategenerativemodel.md#templategenerativemodelgeneratecontentstream) | | <b><i>(Public Preview)</i></b> Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. |
|
||||
| [startChat(params)](./ai.templategenerativemodel.md#templategenerativemodelstartchat) | | <b><i>(Public Preview)</i></b> Starts a [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_interface) that will use this template to respond to messages. |
|
||||
|
||||
## TemplateGenerativeModel.(constructor)
|
||||
@@ -86,7 +86,7 @@ Makes a single non-streaming call to the model and returns an object containing
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
|
||||
generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentResult>;
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
@@ -95,7 +95,8 @@ generateContent(templateId: string, templateVariables: Record<string, unknown>,
|
||||
| --- | --- | --- |
|
||||
| templateId | string | The ID of the server-side template to execute. |
|
||||
| templateVariables | Record<string, unknown> | A key-value map of variables to populate the template with. |
|
||||
| singleRequestOptions | [SingleRequestOptions](./ai.singlerequestoptions.md#singlerequestoptions_interface) | |
|
||||
| singleRequestOptions | [SingleRequestOptions](./ai.singlerequestoptions.md#singlerequestoptions_interface) | Optional. Options to use for this request. |
|
||||
| templateToolConfig | [TemplateToolConfig](./ai.templatetoolconfig.md#templatetoolconfig_interface) | Optional. Configuration for tools to use with this request. |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
@@ -111,7 +112,7 @@ Makes a single streaming call to the model and returns an object containing an i
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
|
||||
generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentStreamResult>;
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
@@ -120,7 +121,8 @@ generateContentStream(templateId: string, templateVariables: Record<string, unkn
|
||||
| --- | --- | --- |
|
||||
| templateId | string | The ID of the server-side template to execute. |
|
||||
| templateVariables | Record<string, unknown> | A key-value map of variables to populate the template with. |
|
||||
| singleRequestOptions | [SingleRequestOptions](./ai.singlerequestoptions.md#singlerequestoptions_interface) | |
|
||||
| singleRequestOptions | [SingleRequestOptions](./ai.singlerequestoptions.md#singlerequestoptions_interface) | Optional.Options to use for this request. |
|
||||
| templateToolConfig | [TemplateToolConfig](./ai.templatetoolconfig.md#templatetoolconfig_interface) | Optional. Configuration for tools to use with this request. |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
Project: /docs/reference/js/_project.yaml
|
||||
Book: /docs/reference/_book.yaml
|
||||
page_type: reference
|
||||
|
||||
{% comment %}
|
||||
DO NOT EDIT THIS FILE!
|
||||
This is generated by the JS SDK team, and any local changes will be
|
||||
overwritten. Changes should be made in the source code at
|
||||
https://github.com/firebase/firebase-js-sdk
|
||||
{% endcomment %}
|
||||
|
||||
# TemplateToolConfig interface
|
||||
Tool configuration for `TemplateGenerativeModel`<!-- -->s. This config is shared for all tools provided in the server prompt template request.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface TemplateToolConfig
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [retrievalConfig](./ai.templatetoolconfig.md#templatetoolconfigretrievalconfig) | [RetrievalConfig](./ai.retrievalconfig.md#retrievalconfig_interface) | |
|
||||
|
||||
## TemplateToolConfig.retrievalConfig
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
retrievalConfig?: RetrievalConfig;
|
||||
```
|
||||
@@ -23,6 +23,7 @@ export interface ToolConfig
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [functionCallingConfig](./ai.toolconfig.md#toolconfigfunctioncallingconfig) | [FunctionCallingConfig](./ai.functioncallingconfig.md#functioncallingconfig_interface) | |
|
||||
| [retrievalConfig](./ai.toolconfig.md#toolconfigretrievalconfig) | [RetrievalConfig](./ai.retrievalconfig.md#retrievalconfig_interface) | |
|
||||
|
||||
## ToolConfig.functionCallingConfig
|
||||
|
||||
@@ -31,3 +32,11 @@ export interface ToolConfig
|
||||
```typescript
|
||||
functionCallingConfig?: FunctionCallingConfig;
|
||||
```
|
||||
|
||||
## ToolConfig.retrievalConfig
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
retrievalConfig?: RetrievalConfig;
|
||||
```
|
||||
|
||||
@@ -181,6 +181,217 @@ describe('Generate Content', function () {
|
||||
expect(groundingSupport.segment?.text).to.exist;
|
||||
// Since partIndex and startIndex are commonly 0, they may be omitted from responses.
|
||||
});
|
||||
expect(groundingMetadata!.googleMapsWidgetContextToken).to.not.exist;
|
||||
});
|
||||
|
||||
it('generateContent: google maps grounding prompt location', async () => {
|
||||
const model = getGenerativeModel(testConfig.ai, {
|
||||
model: testConfig.model,
|
||||
generationConfig: commonGenerationConfig,
|
||||
safetySettings: commonSafetySettings,
|
||||
tools: [{ googleMaps: {} }]
|
||||
});
|
||||
|
||||
const result = await model.generateContent(
|
||||
'Where is a good place to grab a coffee near Arlington, MA?'
|
||||
);
|
||||
const response = result.response;
|
||||
const groundingMetadata = response.candidates?.[0].groundingMetadata;
|
||||
expect(groundingMetadata).to.exist;
|
||||
expect(
|
||||
groundingMetadata!.groundingChunks
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingChunks!.forEach(groundingChunk => {
|
||||
expect(groundingChunk.maps).to.exist;
|
||||
expect(groundingChunk.maps!.uri).to.exist;
|
||||
expect(groundingChunk.maps!.title).to.exist;
|
||||
expect(groundingChunk.maps!.placeId).to.exist;
|
||||
});
|
||||
expect(
|
||||
groundingMetadata?.groundingSupports
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingSupports!.forEach(groundingSupport => {
|
||||
expect(
|
||||
groundingSupport.groundingChunkIndices
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
expect(groundingSupport.segment).to.exist;
|
||||
expect(groundingSupport.segment?.endIndex).to.exist;
|
||||
expect(groundingSupport.segment?.text).to.exist;
|
||||
});
|
||||
expect(groundingMetadata!.googleMapsWidgetContextToken).to.not.exist;
|
||||
});
|
||||
|
||||
it('generateContent: google maps grounding prompt location enableWidget true', async () => {
|
||||
const model = getGenerativeModel(testConfig.ai, {
|
||||
model: testConfig.model,
|
||||
generationConfig: commonGenerationConfig,
|
||||
safetySettings: commonSafetySettings,
|
||||
tools: [{ googleMaps: { enableWidget: true } }]
|
||||
});
|
||||
|
||||
const result = await model.generateContent(
|
||||
'Where is a good place to grab a coffee in New York City?'
|
||||
);
|
||||
const response = result.response;
|
||||
const groundingMetadata = response.candidates?.[0].groundingMetadata;
|
||||
expect(groundingMetadata).to.exist;
|
||||
expect(
|
||||
groundingMetadata!.groundingChunks
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingChunks!.forEach(groundingChunk => {
|
||||
expect(groundingChunk.maps).to.exist;
|
||||
expect(groundingChunk.maps!.uri).to.exist;
|
||||
expect(groundingChunk.maps!.title).to.exist;
|
||||
expect(groundingChunk.maps!.placeId).to.exist;
|
||||
});
|
||||
expect(
|
||||
groundingMetadata?.groundingSupports
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingSupports!.forEach(groundingSupport => {
|
||||
expect(
|
||||
groundingSupport.groundingChunkIndices
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
expect(groundingSupport.segment).to.exist;
|
||||
expect(groundingSupport.segment?.endIndex).to.exist;
|
||||
expect(groundingSupport.segment?.text).to.exist;
|
||||
});
|
||||
expect(groundingMetadata!.googleMapsWidgetContextToken).to.exist;
|
||||
});
|
||||
|
||||
it('generateContent: google maps grounding prompt location enableWidget false', async () => {
|
||||
const model = getGenerativeModel(testConfig.ai, {
|
||||
model: testConfig.model,
|
||||
generationConfig: commonGenerationConfig,
|
||||
safetySettings: commonSafetySettings,
|
||||
tools: [{ googleMaps: { enableWidget: false } }]
|
||||
});
|
||||
|
||||
const result = await model.generateContent(
|
||||
'Where is a good place to grab a coffee in New York City?'
|
||||
);
|
||||
const response = result.response;
|
||||
const groundingMetadata = response.candidates?.[0].groundingMetadata;
|
||||
expect(groundingMetadata).to.exist;
|
||||
expect(
|
||||
groundingMetadata!.groundingChunks
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingChunks!.forEach(groundingChunk => {
|
||||
expect(groundingChunk.maps).to.exist;
|
||||
expect(groundingChunk.maps!.uri).to.exist;
|
||||
expect(groundingChunk.maps!.title).to.exist;
|
||||
expect(groundingChunk.maps!.placeId).to.exist;
|
||||
});
|
||||
expect(
|
||||
groundingMetadata?.groundingSupports
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingSupports!.forEach(groundingSupport => {
|
||||
expect(
|
||||
groundingSupport.groundingChunkIndices
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
expect(groundingSupport.segment).to.exist;
|
||||
expect(groundingSupport.segment?.endIndex).to.exist;
|
||||
expect(groundingSupport.segment?.text).to.exist;
|
||||
});
|
||||
expect(groundingMetadata!.googleMapsWidgetContextToken).to.not.exist;
|
||||
});
|
||||
|
||||
it('generateContent: google maps grounding with RetrievalConfig', async () => {
|
||||
if (testConfig.model === 'gemini-3-pro-preview') {
|
||||
// Maps grounding is not supported in gemini-3-pro-preview.
|
||||
return;
|
||||
}
|
||||
const model = getGenerativeModel(testConfig.ai, {
|
||||
model: testConfig.model,
|
||||
generationConfig: commonGenerationConfig,
|
||||
safetySettings: commonSafetySettings,
|
||||
tools: [{ googleMaps: {} }],
|
||||
toolConfig: {
|
||||
retrievalConfig: {
|
||||
latLng: {
|
||||
latitude: 42.4154,
|
||||
longitude: -71.1565
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const result = await model.generateContent(
|
||||
'Where is a good place to grab a coffee near here?'
|
||||
);
|
||||
const response = result.response;
|
||||
const groundingMetadata = response.candidates?.[0].groundingMetadata;
|
||||
expect(groundingMetadata).to.exist;
|
||||
expect(
|
||||
groundingMetadata!.groundingChunks
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingChunks!.forEach(groundingChunk => {
|
||||
expect(groundingChunk.maps).to.exist;
|
||||
expect(groundingChunk.maps!.uri).to.exist;
|
||||
expect(groundingChunk.maps!.title).to.exist;
|
||||
expect(groundingChunk.maps!.placeId).to.exist;
|
||||
});
|
||||
expect(
|
||||
groundingMetadata?.groundingSupports
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingSupports!.forEach(groundingSupport => {
|
||||
expect(
|
||||
groundingSupport.groundingChunkIndices
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
expect(groundingSupport.segment).to.exist;
|
||||
expect(groundingSupport.segment?.endIndex).to.exist;
|
||||
expect(groundingSupport.segment?.text).to.exist;
|
||||
});
|
||||
expect(groundingMetadata!.googleMapsWidgetContextToken).to.not.exist;
|
||||
});
|
||||
|
||||
it('generateContent: google maps grounding RetrievalConfig enableWidget true', async () => {
|
||||
if (testConfig.model === 'gemini-3-pro-preview') {
|
||||
// Maps grounding is not supported in gemini-3-pro-preview.
|
||||
return;
|
||||
}
|
||||
const model = getGenerativeModel(testConfig.ai, {
|
||||
model: testConfig.model,
|
||||
generationConfig: commonGenerationConfig,
|
||||
safetySettings: commonSafetySettings,
|
||||
tools: [{ googleMaps: { enableWidget: true } }],
|
||||
toolConfig: {
|
||||
retrievalConfig: {
|
||||
latLng: {
|
||||
latitude: 42.4154,
|
||||
longitude: -71.1565
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const result = await model.generateContent(
|
||||
'Where is a good place to grab a coffee near here?'
|
||||
//'Where is the closest starbucks?'
|
||||
);
|
||||
const response = result.response;
|
||||
const groundingMetadata = response.candidates?.[0].groundingMetadata;
|
||||
expect(groundingMetadata).to.exist;
|
||||
expect(
|
||||
groundingMetadata!.groundingChunks
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingChunks!.forEach(groundingChunk => {
|
||||
expect(groundingChunk.maps).to.exist;
|
||||
expect(groundingChunk.maps!.uri).to.exist;
|
||||
expect(groundingChunk.maps!.title).to.exist;
|
||||
expect(groundingChunk.maps!.placeId).to.exist;
|
||||
});
|
||||
expect(
|
||||
groundingMetadata?.groundingSupports
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
groundingMetadata!.groundingSupports!.forEach(groundingSupport => {
|
||||
expect(
|
||||
groundingSupport.groundingChunkIndices
|
||||
).to.have.length.greaterThanOrEqual(1);
|
||||
expect(groundingSupport.segment).to.exist;
|
||||
expect(groundingSupport.segment?.endIndex).to.exist;
|
||||
expect(groundingSupport.segment?.text).to.exist;
|
||||
});
|
||||
expect(groundingMetadata!.googleMapsWidgetContextToken).to.exist;
|
||||
});
|
||||
|
||||
describe('URL Context', async () => {
|
||||
|
||||
@@ -319,6 +319,64 @@ describe('generateContent()', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
it('google maps grounding', async () => {
|
||||
const mockResponse = getMockResponse(
|
||||
'vertexAI',
|
||||
'unary-success-google-maps-grounding.json'
|
||||
);
|
||||
const makeRequestStub = stub(request, 'makeRequest').resolves(
|
||||
mockResponse as Response
|
||||
);
|
||||
const result = await generateContent(
|
||||
fakeApiSettings,
|
||||
'model',
|
||||
fakeRequestParams
|
||||
);
|
||||
expect(result.response.text()).to.include(
|
||||
'Here are some pizza restaurants near you:'
|
||||
);
|
||||
const groundingMetadata = result.response.candidates?.[0].groundingMetadata;
|
||||
expect(groundingMetadata).to.not.be.undefined;
|
||||
expect(groundingMetadata!.groundingChunks?.length).to.equal(20);
|
||||
expect(groundingMetadata!.groundingChunks?.[0].maps?.title).to.equal(
|
||||
'Joe’s Pizza'
|
||||
);
|
||||
expect(groundingMetadata!.groundingChunks?.[0].maps?.placeId).to.equal(
|
||||
'places/ChIJqdNaaBVbwokRLTafYrQlZI8'
|
||||
);
|
||||
expect(groundingMetadata!.groundingChunks?.[0].maps?.uri).to.contain(
|
||||
'https://maps.google.com/?cid=10332424901773702701'
|
||||
);
|
||||
expect(groundingMetadata!.groundingSupports?.length).to.equal(39);
|
||||
expect(groundingMetadata!.groundingSupports?.[0].segment?.partIndex).to.be
|
||||
.undefined;
|
||||
expect(groundingMetadata!.groundingSupports?.[0].segment?.startIndex).to.not
|
||||
.be.undefined;
|
||||
expect(groundingMetadata!.groundingSupports?.[0].segment?.endIndex).to.not
|
||||
.be.undefined;
|
||||
expect(groundingMetadata!.groundingSupports?.[0].segment?.text).to.not.be
|
||||
.undefined;
|
||||
expect(
|
||||
groundingMetadata!.groundingSupports?.[0].segment?.startIndex
|
||||
).to.equal(43);
|
||||
expect(
|
||||
groundingMetadata!.groundingSupports?.[0].segment?.endIndex
|
||||
).to.equal(152);
|
||||
expect(groundingMetadata!.groundingSupports?.[0].segment?.text).to.contain(
|
||||
"Joe's Pizza"
|
||||
);
|
||||
|
||||
expect(makeRequestStub).to.be.calledWith(
|
||||
{
|
||||
model: 'model',
|
||||
task: Task.GENERATE_CONTENT,
|
||||
apiSettings: fakeApiSettings,
|
||||
stream: false,
|
||||
singleRequestOptions: undefined
|
||||
},
|
||||
JSON.stringify(fakeRequestParams)
|
||||
);
|
||||
});
|
||||
it('codeExecution', async () => {
|
||||
const mockResponse = getMockResponse(
|
||||
'vertexAI',
|
||||
|
||||
@@ -18,7 +18,12 @@
|
||||
import { use, expect } from 'chai';
|
||||
import sinonChai from 'sinon-chai';
|
||||
import { restore, stub } from 'sinon';
|
||||
import { AI } from '../public-types';
|
||||
import {
|
||||
AI,
|
||||
TemplateToolConfig,
|
||||
RetrievalConfig,
|
||||
LatLng
|
||||
} from '../public-types';
|
||||
import { VertexAIBackend } from '../backend';
|
||||
import { TemplateGenerativeModel } from './template-generative-model';
|
||||
import * as generateContentMethods from '../methods/generate-content';
|
||||
@@ -57,19 +62,89 @@ describe('TemplateGenerativeModel', () => {
|
||||
});
|
||||
|
||||
describe('generateContent', () => {
|
||||
it('should call templateGenerateContent with correct parameters', async () => {
|
||||
it('should call templateGenerateContent with correct parameters no options', async () => {
|
||||
const templateGenerateContentStub = stub(
|
||||
generateContentMethods,
|
||||
'templateGenerateContent'
|
||||
).resolves({} as any);
|
||||
const model = new TemplateGenerativeModel(fakeAI, { timeout: 5000 });
|
||||
const model = new TemplateGenerativeModel(fakeAI);
|
||||
|
||||
await model.generateContent(TEMPLATE_ID, TEMPLATE_VARS);
|
||||
|
||||
expect(templateGenerateContentStub).to.have.been.calledOnceWith(
|
||||
model._apiSettings,
|
||||
TEMPLATE_ID,
|
||||
{ inputs: TEMPLATE_VARS },
|
||||
{ inputs: TEMPLATE_VARS }
|
||||
);
|
||||
});
|
||||
|
||||
it('should call templateGenerateContent with correct parameters w/ request options', async () => {
|
||||
const templateGenerateContentStub = stub(
|
||||
generateContentMethods,
|
||||
'templateGenerateContent'
|
||||
).resolves({} as any);
|
||||
const model = new TemplateGenerativeModel(fakeAI);
|
||||
|
||||
await model.generateContent(TEMPLATE_ID, TEMPLATE_VARS);
|
||||
|
||||
expect(templateGenerateContentStub).to.have.been.calledOnceWith(
|
||||
model._apiSettings,
|
||||
TEMPLATE_ID,
|
||||
{ inputs: TEMPLATE_VARS }
|
||||
);
|
||||
});
|
||||
|
||||
it('should call templateGenerateContent with correct parameters w/ tool config', async () => {
|
||||
const templateGenerateContentStub = stub(
|
||||
generateContentMethods,
|
||||
'templateGenerateContent'
|
||||
).resolves({} as any);
|
||||
const model = new TemplateGenerativeModel(fakeAI);
|
||||
const latLng: LatLng = {
|
||||
latitude: 50.0,
|
||||
longitude: 50.0
|
||||
};
|
||||
const retrievalConfig: RetrievalConfig = { latLng };
|
||||
const templateToolConfig: TemplateToolConfig = { retrievalConfig };
|
||||
|
||||
await model.generateContent(
|
||||
TEMPLATE_ID,
|
||||
TEMPLATE_VARS,
|
||||
undefined,
|
||||
templateToolConfig
|
||||
);
|
||||
|
||||
expect(templateGenerateContentStub).to.have.been.calledOnceWith(
|
||||
model._apiSettings,
|
||||
TEMPLATE_ID,
|
||||
{ inputs: TEMPLATE_VARS, toolConfig: templateToolConfig }
|
||||
);
|
||||
});
|
||||
|
||||
it('should call templateGenerateContent with correct parameters w/ both optional params', async () => {
|
||||
const templateGenerateContentStub = stub(
|
||||
generateContentMethods,
|
||||
'templateGenerateContent'
|
||||
).resolves({} as any);
|
||||
const model = new TemplateGenerativeModel(fakeAI);
|
||||
const latLng: LatLng = {
|
||||
latitude: 50.0,
|
||||
longitude: 50.0
|
||||
};
|
||||
const retrievalConfig: RetrievalConfig = { latLng };
|
||||
const templateToolConfig: TemplateToolConfig = { retrievalConfig };
|
||||
|
||||
await model.generateContent(
|
||||
TEMPLATE_ID,
|
||||
TEMPLATE_VARS,
|
||||
{ timeout: 5000 },
|
||||
templateToolConfig
|
||||
);
|
||||
|
||||
expect(templateGenerateContentStub).to.have.been.calledOnceWith(
|
||||
model._apiSettings,
|
||||
TEMPLATE_ID,
|
||||
{ inputs: TEMPLATE_VARS, toolConfig: templateToolConfig },
|
||||
{ timeout: 5000 }
|
||||
);
|
||||
});
|
||||
@@ -138,6 +213,77 @@ describe('TemplateGenerativeModel', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should call templateGenerateContentStream with correct parameters w/ request options', async () => {
|
||||
const templateGenerateContentStreamStub = stub(
|
||||
generateContentMethods,
|
||||
'templateGenerateContentStream'
|
||||
).resolves({} as any);
|
||||
const model = new TemplateGenerativeModel(fakeAI);
|
||||
await model.generateContentStream(TEMPLATE_ID, TEMPLATE_VARS, {
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
expect(templateGenerateContentStreamStub).to.have.been.calledOnceWith(
|
||||
model._apiSettings,
|
||||
TEMPLATE_ID,
|
||||
{ inputs: TEMPLATE_VARS },
|
||||
{ timeout: 5000 }
|
||||
);
|
||||
});
|
||||
|
||||
it('should call templateGenerateContentStream with correct parameters w/ tool config', async () => {
|
||||
const templateGenerateContentStreamStub = stub(
|
||||
generateContentMethods,
|
||||
'templateGenerateContentStream'
|
||||
).resolves({} as any);
|
||||
const latLng: LatLng = {
|
||||
latitude: 50.0,
|
||||
longitude: 50.0
|
||||
};
|
||||
const retrievalConfig: RetrievalConfig = { latLng };
|
||||
const templateToolConfig: TemplateToolConfig = { retrievalConfig };
|
||||
const model = new TemplateGenerativeModel(fakeAI);
|
||||
await model.generateContentStream(
|
||||
TEMPLATE_ID,
|
||||
TEMPLATE_VARS,
|
||||
undefined,
|
||||
templateToolConfig
|
||||
);
|
||||
|
||||
expect(templateGenerateContentStreamStub).to.have.been.calledOnceWith(
|
||||
model._apiSettings,
|
||||
TEMPLATE_ID,
|
||||
{ inputs: TEMPLATE_VARS, toolConfig: templateToolConfig }
|
||||
);
|
||||
});
|
||||
|
||||
it('should call templateGenerateContent with correct parameters w/ both optional params', async () => {
|
||||
const templateGenerateContentStreamStub = stub(
|
||||
generateContentMethods,
|
||||
'templateGenerateContentStream'
|
||||
).resolves({} as any);
|
||||
const latLng: LatLng = {
|
||||
latitude: 50.0,
|
||||
longitude: 50.0
|
||||
};
|
||||
const retrievalConfig: RetrievalConfig = { latLng };
|
||||
const templateToolConfig: TemplateToolConfig = { retrievalConfig };
|
||||
const model = new TemplateGenerativeModel(fakeAI);
|
||||
await model.generateContentStream(
|
||||
TEMPLATE_ID,
|
||||
TEMPLATE_VARS,
|
||||
{ timeout: 5000 },
|
||||
templateToolConfig
|
||||
);
|
||||
|
||||
expect(templateGenerateContentStreamStub).to.have.been.calledOnceWith(
|
||||
model._apiSettings,
|
||||
TEMPLATE_ID,
|
||||
{ inputs: TEMPLATE_VARS, toolConfig: templateToolConfig },
|
||||
{ timeout: 5000 }
|
||||
);
|
||||
});
|
||||
|
||||
it('singleRequestOptions overrides requestOptions', async () => {
|
||||
const templateGenerateContentStreamStub = stub(
|
||||
generateContentMethods,
|
||||
|
||||
@@ -25,7 +25,8 @@ import {
|
||||
GenerateContentStreamResult,
|
||||
SingleRequestOptions,
|
||||
StartTemplateChatParams,
|
||||
TemplateChatSession
|
||||
TemplateChatSession,
|
||||
TemplateToolConfig
|
||||
} from '../public-types';
|
||||
import { ApiSettings } from '../types/internal';
|
||||
import { initApiSettings } from './utils';
|
||||
@@ -64,18 +65,24 @@ export class TemplateGenerativeModel {
|
||||
* @param templateId - The ID of the server-side template to execute.
|
||||
* @param templateVariables - A key-value map of variables to populate the
|
||||
* template with.
|
||||
* @param singleRequestOptions - Optional. Options to use for this request.
|
||||
* @param templateToolConfig - Optional. Configuration for tools to use with this request.
|
||||
*
|
||||
* @beta
|
||||
*/
|
||||
async generateContent(
|
||||
templateId: string,
|
||||
templateVariables: Record<string, unknown>,
|
||||
singleRequestOptions?: SingleRequestOptions
|
||||
singleRequestOptions?: SingleRequestOptions,
|
||||
templateToolConfig?: TemplateToolConfig
|
||||
): Promise<GenerateContentResult> {
|
||||
return templateGenerateContent(
|
||||
this._apiSettings,
|
||||
templateId,
|
||||
{ inputs: templateVariables },
|
||||
{
|
||||
inputs: templateVariables,
|
||||
...(templateToolConfig && { toolConfig: templateToolConfig })
|
||||
},
|
||||
{
|
||||
...this.requestOptions,
|
||||
...singleRequestOptions
|
||||
@@ -92,18 +99,24 @@ export class TemplateGenerativeModel {
|
||||
* @param templateId - The ID of the server-side template to execute.
|
||||
* @param templateVariables - A key-value map of variables to populate the
|
||||
* template with.
|
||||
* @param singleRequestOptions - Optional.Options to use for this request.
|
||||
* @param templateToolConfig - Optional. Configuration for tools to use with this request.
|
||||
*
|
||||
* @beta
|
||||
*/
|
||||
async generateContentStream(
|
||||
templateId: string,
|
||||
templateVariables: Record<string, unknown>,
|
||||
singleRequestOptions?: SingleRequestOptions
|
||||
singleRequestOptions?: SingleRequestOptions,
|
||||
templateToolConfig?: TemplateToolConfig
|
||||
): Promise<GenerateContentStreamResult> {
|
||||
return templateGenerateContentStream(
|
||||
this._apiSettings,
|
||||
templateId,
|
||||
{ inputs: templateVariables },
|
||||
{
|
||||
inputs: templateVariables,
|
||||
...(templateToolConfig && { toolConfig: templateToolConfig })
|
||||
},
|
||||
{
|
||||
...this.requestOptions,
|
||||
...singleRequestOptions
|
||||
|
||||
@@ -420,6 +420,7 @@ export interface SingleRequestOptions extends RequestOptions {
|
||||
*/
|
||||
export type Tool =
|
||||
| FunctionDeclarationsTool
|
||||
| GoogleMapsTool
|
||||
| GoogleSearchTool
|
||||
| CodeExecutionTool
|
||||
| URLContextTool;
|
||||
@@ -483,6 +484,29 @@ export interface GoogleSearchTool {
|
||||
googleSearch: GoogleSearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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: {@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}
|
||||
* section within the Service Specific Terms).
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface GoogleMapsTool {
|
||||
/**
|
||||
* 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: {@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}
|
||||
* section within the Service Specific Terms).
|
||||
*/
|
||||
googleMaps: GoogleMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool that enables the model to use code execution.
|
||||
*
|
||||
@@ -504,6 +528,18 @@ export interface CodeExecutionTool {
|
||||
*/
|
||||
export interface GoogleSearch {}
|
||||
|
||||
/**
|
||||
* Specifies the Google Maps configuration.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface GoogleMaps {
|
||||
/*
|
||||
* If true, include the widget context token in the response.
|
||||
*/
|
||||
enableWidget?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool that allows you to provide additional context to the models in the form of public web
|
||||
* URLs. By including URLs in your request, the Gemini model will access the content from those
|
||||
@@ -545,6 +581,22 @@ export interface FunctionDeclarationsTool {
|
||||
functionDeclarations?: FunctionDeclaration[];
|
||||
}
|
||||
|
||||
/**
|
||||
* An object that represents a latitude/longitude pair.
|
||||
* @public
|
||||
*/
|
||||
export interface LatLng {
|
||||
/**
|
||||
* The latitude in degrees. It must be in the range `[-90.0, +90.0]`.
|
||||
*/
|
||||
latitude?: number;
|
||||
|
||||
/**
|
||||
* The longitude in degrees. It must be in the range `[-180.0, +180.0]`.
|
||||
*/
|
||||
longitude?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Structured representation of a template function declaration.
|
||||
* Included in this declaration are the function name and parameters. This
|
||||
@@ -624,6 +676,16 @@ export type TemplateTool = TemplateFunctionDeclarationsTool;
|
||||
*/
|
||||
export interface ToolConfig {
|
||||
functionCallingConfig?: FunctionCallingConfig;
|
||||
retrievalConfig?: RetrievalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool configuration for `TemplateGenerativeModel`s.
|
||||
* This config is shared for all tools provided in the server prompt template request.
|
||||
* @public
|
||||
*/
|
||||
export interface TemplateToolConfig {
|
||||
retrievalConfig?: RetrievalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -634,6 +696,22 @@ export interface FunctionCallingConfig {
|
||||
allowedFunctionNames?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration options for data retrieval tools.
|
||||
* @public
|
||||
*/
|
||||
export interface RetrievalConfig {
|
||||
/**
|
||||
* The location of the user.
|
||||
*/
|
||||
latLng?: LatLng;
|
||||
|
||||
/**
|
||||
* The language code of the user.
|
||||
*/
|
||||
languageCode?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encapsulates configuration for on-device inference.
|
||||
*
|
||||
|
||||
@@ -224,13 +224,19 @@ export interface Citation {
|
||||
/**
|
||||
* Metadata returned when grounding is enabled.
|
||||
*
|
||||
* Currently, only Grounding with Google Search is supported (see {@link GoogleSearchTool}).
|
||||
* Currently, only Grounding with Google Search and Grounding with Google Maps are supported
|
||||
* (see {@link GoogleSearchTool} and {@link GoogleMapsTool}, 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: {@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}
|
||||
* 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}
|
||||
* section within the Service Specific Terms).
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface GroundingMetadata {
|
||||
@@ -259,6 +265,12 @@ export interface GroundingMetadata {
|
||||
* @deprecated Use {@link GroundingSupport} instead.
|
||||
*/
|
||||
retrievalQueries?: string[];
|
||||
/**
|
||||
* Resource name of the Google Maps widget context token that can be used with the
|
||||
* `PlacesContextElement` widget in order to render contextual data. Only populated in the case
|
||||
* that grounding with Google Maps is enabled.
|
||||
*/
|
||||
googleMapsWidgetContextToken?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,6 +308,11 @@ export interface GroundingChunk {
|
||||
* Contains details if the grounding chunk is from a web source.
|
||||
*/
|
||||
web?: WebGroundingChunk;
|
||||
|
||||
/**
|
||||
* Contains details if the grounding chunk is from a Google Maps source.
|
||||
*/
|
||||
maps?: GoogleMapsGroundingChunk;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,6 +342,34 @@ export interface WebGroundingChunk {
|
||||
domain?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A grounding chunk from Google Maps.
|
||||
*
|
||||
* Important: If using Grounding with Google Maps, you are required to comply with the
|
||||
* {@link https://cloud.google.com/terms/service-terms | Service Specific Terms} for "Grounding with Google Maps".
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface GoogleMapsGroundingChunk {
|
||||
/**
|
||||
* The URI of the place.
|
||||
*/
|
||||
uri?: string;
|
||||
/**
|
||||
* The title of the place.
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* The text of the place answer.
|
||||
*/
|
||||
text?: string;
|
||||
/**
|
||||
* This Place's resource name, in `places/{place_id}` format. This can be used to look up the
|
||||
* place in the Google Maps API.
|
||||
*/
|
||||
placeId?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides information about how a specific segment of the model's response is supported by the
|
||||
* retrieved grounding chunks.
|
||||
|
||||
Reference in New Issue
Block a user