Skip to content

Commit b4d65ab

Browse files
Merge main into release
2 parents 52c8579 + e25317f commit b4d65ab

Some content is hidden

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

53 files changed

+2543
-169
lines changed

.changeset/purple-chairs-wait.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/ai': minor
3+
'firebase': minor
4+
---
5+
6+
Add hybrid inference options to the Firebase AI SDK.

.changeset/strong-avocados-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/performance': patch
3+
---
4+
5+
Fixed errors thrown when capturing long target element names for the out-of-the-box metrics.

common/api-review/ai.api.md

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class BooleanSchema extends Schema {
125125

126126
// @public
127127
export class ChatSession {
128-
constructor(apiSettings: ApiSettings, model: string, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
128+
constructor(apiSettings: ApiSettings, model: string, chromeAdapter?: ChromeAdapter | undefined, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
129129
getHistory(): Promise<Content[]>;
130130
// (undocumented)
131131
model: string;
@@ -137,6 +137,15 @@ export class ChatSession {
137137
sendMessageStream(request: string | Array<string | Part>): Promise<GenerateContentStreamResult>;
138138
}
139139

140+
// @public
141+
export interface ChromeAdapter {
142+
// @internal (undocumented)
143+
countTokens(request: CountTokensRequest): Promise<Response>;
144+
generateContent(request: GenerateContentRequest): Promise<Response>;
145+
generateContentStream(request: GenerateContentRequest): Promise<Response>;
146+
isAvailable(request: GenerateContentRequest): Promise<boolean>;
147+
}
148+
140149
// @public
141150
export interface Citation {
142151
// (undocumented)
@@ -416,7 +425,7 @@ export interface GenerativeContentBlob {
416425

417426
// @public
418427
export class GenerativeModel extends AIModel {
419-
constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions);
428+
constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions, chromeAdapter?: ChromeAdapter | undefined);
420429
countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
421430
generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
422431
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
@@ -439,7 +448,7 @@ export class GenerativeModel extends AIModel {
439448
export function getAI(app?: FirebaseApp, options?: AIOptions): AI;
440449

441450
// @public
442-
export function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;
451+
export function getGenerativeModel(ai: AI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
443452

444453
// @beta
445454
export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
@@ -588,6 +597,13 @@ export const HarmSeverity: {
588597
// @public
589598
export type HarmSeverity = (typeof HarmSeverity)[keyof typeof HarmSeverity];
590599

600+
// @public
601+
export interface HybridParams {
602+
inCloudParams?: ModelParams;
603+
mode: InferenceMode;
604+
onDeviceParams?: OnDeviceParams;
605+
}
606+
591607
// @beta
592608
export const ImagenAspectRatio: {
593609
readonly SQUARE: "1:1";
@@ -600,7 +616,7 @@ export const ImagenAspectRatio: {
600616
// @beta
601617
export type ImagenAspectRatio = (typeof ImagenAspectRatio)[keyof typeof ImagenAspectRatio];
602618

603-
// @public
619+
// @beta
604620
export interface ImagenGCSImage {
605621
gcsURI: string;
606622
mimeType: string;
@@ -681,6 +697,16 @@ export interface ImagenSafetySettings {
681697
safetyFilterLevel?: ImagenSafetyFilterLevel;
682698
}
683699

700+
// @public
701+
export const InferenceMode: {
702+
readonly PREFER_ON_DEVICE: "prefer_on_device";
703+
readonly ONLY_ON_DEVICE: "only_on_device";
704+
readonly ONLY_IN_CLOUD: "only_in_cloud";
705+
};
706+
707+
// @public
708+
export type InferenceMode = (typeof InferenceMode)[keyof typeof InferenceMode];
709+
684710
// @public
685711
export interface InlineDataPart {
686712
// (undocumented)
@@ -699,6 +725,63 @@ export class IntegerSchema extends Schema {
699725
constructor(schemaParams?: SchemaParams);
700726
}
701727

728+
// @public
729+
export interface LanguageModelCreateCoreOptions {
730+
// (undocumented)
731+
expectedInputs?: LanguageModelExpected[];
732+
// (undocumented)
733+
temperature?: number;
734+
// (undocumented)
735+
topK?: number;
736+
}
737+
738+
// @public
739+
export interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
740+
// (undocumented)
741+
initialPrompts?: LanguageModelMessage[];
742+
// (undocumented)
743+
signal?: AbortSignal;
744+
}
745+
746+
// @public
747+
export interface LanguageModelExpected {
748+
// (undocumented)
749+
languages?: string[];
750+
// (undocumented)
751+
type: LanguageModelMessageType;
752+
}
753+
754+
// @public
755+
export interface LanguageModelMessage {
756+
// (undocumented)
757+
content: LanguageModelMessageContent[];
758+
// (undocumented)
759+
role: LanguageModelMessageRole;
760+
}
761+
762+
// @public
763+
export interface LanguageModelMessageContent {
764+
// (undocumented)
765+
type: LanguageModelMessageType;
766+
// (undocumented)
767+
value: LanguageModelMessageContentValue;
768+
}
769+
770+
// @public
771+
export type LanguageModelMessageContentValue = ImageBitmapSource | AudioBuffer | BufferSource | string;
772+
773+
// @public
774+
export type LanguageModelMessageRole = 'system' | 'user' | 'assistant';
775+
776+
// @public
777+
export type LanguageModelMessageType = 'text' | 'image' | 'audio';
778+
779+
// @public
780+
export interface LanguageModelPromptOptions {
781+
// (undocumented)
782+
responseConstraint?: object;
783+
}
784+
702785
// @public
703786
export const Modality: {
704787
readonly MODALITY_UNSPECIFIED: "MODALITY_UNSPECIFIED";
@@ -757,6 +840,14 @@ export interface ObjectSchemaRequest extends SchemaRequest {
757840
type: 'object';
758841
}
759842

843+
// @public
844+
export interface OnDeviceParams {
845+
// (undocumented)
846+
createOptions?: LanguageModelCreateOptions;
847+
// (undocumented)
848+
promptOptions?: LanguageModelPromptOptions;
849+
}
850+
760851
// @public
761852
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
762853

docs-devsite/_toc.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ toc:
2424
path: /docs/reference/js/ai.booleanschema.md
2525
- title: ChatSession
2626
path: /docs/reference/js/ai.chatsession.md
27+
- title: ChromeAdapter
28+
path: /docs/reference/js/ai.chromeadapter.md
2729
- title: Citation
2830
path: /docs/reference/js/ai.citation.md
2931
- title: CitationMetadata
@@ -88,6 +90,8 @@ toc:
8890
path: /docs/reference/js/ai.groundingmetadata.md
8991
- title: GroundingSupport
9092
path: /docs/reference/js/ai.groundingsupport.md
93+
- title: HybridParams
94+
path: /docs/reference/js/ai.hybridparams.md
9195
- title: ImagenGCSImage
9296
path: /docs/reference/js/ai.imagengcsimage.md
9397
- title: ImagenGenerationConfig
@@ -108,6 +112,18 @@ toc:
108112
path: /docs/reference/js/ai.inlinedatapart.md
109113
- title: IntegerSchema
110114
path: /docs/reference/js/ai.integerschema.md
115+
- title: LanguageModelCreateCoreOptions
116+
path: /docs/reference/js/ai.languagemodelcreatecoreoptions.md
117+
- title: LanguageModelCreateOptions
118+
path: /docs/reference/js/ai.languagemodelcreateoptions.md
119+
- title: LanguageModelExpected
120+
path: /docs/reference/js/ai.languagemodelexpected.md
121+
- title: LanguageModelMessage
122+
path: /docs/reference/js/ai.languagemodelmessage.md
123+
- title: LanguageModelMessageContent
124+
path: /docs/reference/js/ai.languagemodelmessagecontent.md
125+
- title: LanguageModelPromptOptions
126+
path: /docs/reference/js/ai.languagemodelpromptoptions.md
111127
- title: ModalityTokenCount
112128
path: /docs/reference/js/ai.modalitytokencount.md
113129
- title: ModelParams
@@ -118,6 +134,8 @@ toc:
118134
path: /docs/reference/js/ai.objectschema.md
119135
- title: ObjectSchemaRequest
120136
path: /docs/reference/js/ai.objectschemarequest.md
137+
- title: OnDeviceParams
138+
path: /docs/reference/js/ai.ondeviceparams.md
121139
- title: PromptFeedback
122140
path: /docs/reference/js/ai.promptfeedback.md
123141
- title: RequestOptions

docs-devsite/ai.chatsession.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export declare class ChatSession
2222

2323
| Constructor | Modifiers | Description |
2424
| --- | --- | --- |
25-
| [(constructor)(apiSettings, model, params, requestOptions)](./ai.chatsession.md#chatsessionconstructor) | | Constructs a new instance of the <code>ChatSession</code> class |
25+
| [(constructor)(apiSettings, model, chromeAdapter, params, requestOptions)](./ai.chatsession.md#chatsessionconstructor) | | Constructs a new instance of the <code>ChatSession</code> class |
2626

2727
## Properties
2828

@@ -47,7 +47,7 @@ Constructs a new instance of the `ChatSession` class
4747
<b>Signature:</b>
4848

4949
```typescript
50-
constructor(apiSettings: ApiSettings, model: string, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
50+
constructor(apiSettings: ApiSettings, model: string, chromeAdapter?: ChromeAdapter | undefined, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
5151
```
5252

5353
#### Parameters
@@ -56,6 +56,7 @@ constructor(apiSettings: ApiSettings, model: string, params?: StartChatParams |
5656
| --- | --- | --- |
5757
| apiSettings | ApiSettings | |
5858
| model | string | |
59+
| chromeAdapter | [ChromeAdapter](./ai.chromeadapter.md#chromeadapter_interface) \| undefined | |
5960
| params | [StartChatParams](./ai.startchatparams.md#startchatparams_interface) \| undefined | |
6061
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \| undefined | |
6162

docs-devsite/ai.chromeadapter.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# ChromeAdapter interface
13+
<b>(EXPERIMENTAL)</b> Defines an inference "backend" that uses Chrome's on-device model, and encapsulates logic for detecting when on-device inference is possible.
14+
15+
These methods should not be called directly by the user.
16+
17+
<b>Signature:</b>
18+
19+
```typescript
20+
export interface ChromeAdapter
21+
```
22+
23+
## Methods
24+
25+
| Method | Description |
26+
| --- | --- |
27+
| [generateContent(request)](./ai.chromeadapter.md#chromeadaptergeneratecontent) | Generates content using on-device inference.<p>This is comparable to [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) for generating content using in-cloud inference.</p> |
28+
| [generateContentStream(request)](./ai.chromeadapter.md#chromeadaptergeneratecontentstream) | Generates a content stream using on-device inference.<p>This is comparable to [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream) for generating a content stream using in-cloud inference.</p> |
29+
| [isAvailable(request)](./ai.chromeadapter.md#chromeadapterisavailable) | Checks if the on-device model is capable of handling a given request. |
30+
31+
## ChromeAdapter.generateContent()
32+
33+
Generates content using on-device inference.
34+
35+
<p>This is comparable to [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) for generating content using in-cloud inference.</p>
36+
37+
<b>Signature:</b>
38+
39+
```typescript
40+
generateContent(request: GenerateContentRequest): Promise<Response>;
41+
```
42+
43+
#### Parameters
44+
45+
| Parameter | Type | Description |
46+
| --- | --- | --- |
47+
| request | [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | a standard Firebase AI [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) |
48+
49+
<b>Returns:</b>
50+
51+
Promise&lt;Response&gt;
52+
53+
## ChromeAdapter.generateContentStream()
54+
55+
Generates a content stream using on-device inference.
56+
57+
<p>This is comparable to [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream) for generating a content stream using in-cloud inference.</p>
58+
59+
<b>Signature:</b>
60+
61+
```typescript
62+
generateContentStream(request: GenerateContentRequest): Promise<Response>;
63+
```
64+
65+
#### Parameters
66+
67+
| Parameter | Type | Description |
68+
| --- | --- | --- |
69+
| request | [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | a standard Firebase AI [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) |
70+
71+
<b>Returns:</b>
72+
73+
Promise&lt;Response&gt;
74+
75+
## ChromeAdapter.isAvailable()
76+
77+
Checks if the on-device model is capable of handling a given request.
78+
79+
<b>Signature:</b>
80+
81+
```typescript
82+
isAvailable(request: GenerateContentRequest): Promise<boolean>;
83+
```
84+
85+
#### Parameters
86+
87+
| Parameter | Type | Description |
88+
| --- | --- | --- |
89+
| request | [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | A potential request to be passed to the model. |
90+
91+
<b>Returns:</b>
92+
93+
Promise&lt;boolean&gt;
94+

docs-devsite/ai.generativemodel.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export declare class GenerativeModel extends AIModel
2323
2424
| Constructor | Modifiers | Description |
2525
| --- | --- | --- |
26-
| [(constructor)(ai, modelParams, requestOptions)](./ai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the <code>GenerativeModel</code> class |
26+
| [(constructor)(ai, modelParams, requestOptions, chromeAdapter)](./ai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the <code>GenerativeModel</code> class |
2727
2828
## Properties
2929
@@ -52,7 +52,7 @@ Constructs a new instance of the `GenerativeModel` class
5252
<b>Signature:</b>
5353
5454
```typescript
55-
constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions);
55+
constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions, chromeAdapter?: ChromeAdapter | undefined);
5656
```
5757
5858
#### Parameters
@@ -62,6 +62,7 @@ constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions);
6262
| ai | [AI](./ai.ai.md#ai_interface) | |
6363
| modelParams | [ModelParams](./ai.modelparams.md#modelparams_interface) | |
6464
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | |
65+
| chromeAdapter | [ChromeAdapter](./ai.chromeadapter.md#chromeadapter_interface) \| undefined | |
6566
6667
## GenerativeModel.generationConfig
6768

docs-devsite/ai.groundingmetadata.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface GroundingMetadata
2929
| [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. |
3030
| [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>. |
3131
| [retrievalQueries](./ai.groundingmetadata.md#groundingmetadataretrievalqueries) | string\[\] | |
32-
| [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. |
32+
| [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". |
3333
| [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. |
3434

3535
## GroundingMetadata.groundingChunks
@@ -67,7 +67,7 @@ retrievalQueries?: string[];
6767

6868
## GroundingMetadata.searchEntryPoint
6969

70-
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.
70+
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".
7171

7272
<b>Signature:</b>
7373

0 commit comments

Comments
 (0)