Skip to content

Commit e6e7739

Browse files
authored
Merge c16cbf1 into 39505cc
2 parents 39505cc + c16cbf1 commit e6e7739

24 files changed

+1598
-120
lines changed

common/api-review/ai.api.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export class BooleanSchema extends Schema {
112112

113113
// @public
114114
export class ChatSession {
115-
constructor(apiSettings: ApiSettings, model: string, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
115+
// Warning: (ae-forgotten-export) The symbol "ChromeAdapter" needs to be exported by the entry point index.d.ts
116+
constructor(apiSettings: ApiSettings, model: string, chromeAdapter: ChromeAdapter, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
116117
getHistory(): Promise<Content[]>;
117118
// (undocumented)
118119
model: string;
@@ -395,8 +396,9 @@ export interface GenerativeContentBlob {
395396

396397
// @public
397398
export class GenerativeModel extends AIModel {
398-
constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions);
399+
constructor(ai: AI, modelParams: ModelParams, chromeAdapter: ChromeAdapter, requestOptions?: RequestOptions);
399400
countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
401+
static DEFAULT_HYBRID_IN_CLOUD_MODEL: string;
400402
generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
401403
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
402404
// (undocumented)
@@ -418,7 +420,7 @@ export class GenerativeModel extends AIModel {
418420
export function getAI(app?: FirebaseApp, options?: AIOptions): AI;
419421

420422
// @public
421-
export function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;
423+
export function getGenerativeModel(ai: AI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
422424

423425
// @beta
424426
export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions): ImagenModel;
@@ -550,6 +552,13 @@ export enum HarmSeverity {
550552
HARM_SEVERITY_UNSUPPORTED = "HARM_SEVERITY_UNSUPPORTED"
551553
}
552554

555+
// @public
556+
export interface HybridParams {
557+
inCloudParams?: ModelParams;
558+
mode: InferenceMode;
559+
onDeviceParams?: OnDeviceParams;
560+
}
561+
553562
// @beta
554563
export enum ImagenAspectRatio {
555564
LANDSCAPE_16x9 = "16:9",
@@ -634,6 +643,9 @@ export interface ImagenSafetySettings {
634643
safetyFilterLevel?: ImagenSafetyFilterLevel;
635644
}
636645

646+
// @public
647+
export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud';
648+
637649
// @public
638650
export interface InlineDataPart {
639651
// (undocumented)
@@ -708,6 +720,18 @@ export interface ObjectSchemaInterface extends SchemaInterface {
708720
type: SchemaType.OBJECT;
709721
}
710722

723+
// @public
724+
export interface OnDeviceParams {
725+
// Warning: (ae-forgotten-export) The symbol "LanguageModelCreateOptions" needs to be exported by the entry point index.d.ts
726+
//
727+
// (undocumented)
728+
createOptions?: LanguageModelCreateOptions;
729+
// Warning: (ae-forgotten-export) The symbol "LanguageModelPromptOptions" needs to be exported by the entry point index.d.ts
730+
//
731+
// (undocumented)
732+
promptOptions?: LanguageModelPromptOptions;
733+
}
734+
711735
// @public
712736
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
713737

docs-devsite/_toc.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ toc:
8080
path: /docs/reference/js/ai.groundingattribution.md
8181
- title: GroundingMetadata
8282
path: /docs/reference/js/ai.groundingmetadata.md
83+
- title: HybridParams
84+
path: /docs/reference/js/ai.hybridparams.md
8385
- title: ImagenGCSImage
8486
path: /docs/reference/js/ai.imagengcsimage.md
8587
- title: ImagenGenerationConfig
@@ -110,6 +112,8 @@ toc:
110112
path: /docs/reference/js/ai.objectschema.md
111113
- title: ObjectSchemaInterface
112114
path: /docs/reference/js/ai.objectschemainterface.md
115+
- title: OnDeviceParams
116+
path: /docs/reference/js/ai.ondeviceparams.md
113117
- title: PromptFeedback
114118
path: /docs/reference/js/ai.promptfeedback.md
115119
- 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, 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 | |
5960
| params | [StartChatParams](./ai.startchatparams.md#startchatparams_interface) \| undefined | |
6061
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \| undefined | |
6162

docs-devsite/ai.generativemodel.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ 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, chromeAdapter, requestOptions)](./ai.generativemodel.md#generativemodelconstructor) | | Constructs a new instance of the <code>GenerativeModel</code> class |
2727
2828
## Properties
2929
3030
| Property | Modifiers | Type | Description |
3131
| --- | --- | --- | --- |
32+
| [DEFAULT\_HYBRID\_IN\_CLOUD\_MODEL](./ai.generativemodel.md#generativemodeldefault_hybrid_in_cloud_model) | <code>static</code> | string | Defines the name of the default in-cloud model to use for hybrid inference. |
3233
| [generationConfig](./ai.generativemodel.md#generativemodelgenerationconfig) | | [GenerationConfig](./ai.generationconfig.md#generationconfig_interface) | |
3334
| [requestOptions](./ai.generativemodel.md#generativemodelrequestoptions) | | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | |
3435
| [safetySettings](./ai.generativemodel.md#generativemodelsafetysettings) | | [SafetySetting](./ai.safetysetting.md#safetysetting_interface)<!-- -->\[\] | |
@@ -52,7 +53,7 @@ Constructs a new instance of the `GenerativeModel` class
5253
<b>Signature:</b>
5354
5455
```typescript
55-
constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions);
56+
constructor(ai: AI, modelParams: ModelParams, chromeAdapter: ChromeAdapter, requestOptions?: RequestOptions);
5657
```
5758
5859
#### Parameters
@@ -61,8 +62,19 @@ constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions);
6162
| --- | --- | --- |
6263
| ai | [AI](./ai.ai.md#ai_interface) | |
6364
| modelParams | [ModelParams](./ai.modelparams.md#modelparams_interface) | |
65+
| chromeAdapter | ChromeAdapter | |
6466
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | |
6567
68+
## GenerativeModel.DEFAULT\_HYBRID\_IN\_CLOUD\_MODEL
69+
70+
Defines the name of the default in-cloud model to use for hybrid inference.
71+
72+
<b>Signature:</b>
73+
74+
```typescript
75+
static DEFAULT_HYBRID_IN_CLOUD_MODEL: string;
76+
```
77+
6678
## GenerativeModel.generationConfig
6779
6880
<b>Signature:</b>

docs-devsite/ai.hybridparams.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
# HybridParams interface
13+
Toggles hybrid inference.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface HybridParams
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [inCloudParams](./ai.hybridparams.md#hybridparamsincloudparams) | [ModelParams](./ai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for in-cloud inference. |
26+
| [mode](./ai.hybridparams.md#hybridparamsmode) | [InferenceMode](./ai.md#inferencemode) | Specifies on-device or in-cloud inference. Defaults to prefer on-device. |
27+
| [onDeviceParams](./ai.hybridparams.md#hybridparamsondeviceparams) | [OnDeviceParams](./ai.ondeviceparams.md#ondeviceparams_interface) | Optional. Specifies advanced params for on-device inference. |
28+
29+
## HybridParams.inCloudParams
30+
31+
Optional. Specifies advanced params for in-cloud inference.
32+
33+
<b>Signature:</b>
34+
35+
```typescript
36+
inCloudParams?: ModelParams;
37+
```
38+
39+
## HybridParams.mode
40+
41+
Specifies on-device or in-cloud inference. Defaults to prefer on-device.
42+
43+
<b>Signature:</b>
44+
45+
```typescript
46+
mode: InferenceMode;
47+
```
48+
49+
## HybridParams.onDeviceParams
50+
51+
Optional. Specifies advanced params for on-device inference.
52+
53+
<b>Signature:</b>
54+
55+
```typescript
56+
onDeviceParams?: OnDeviceParams;
57+
```

docs-devsite/ai.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The Firebase AI Web SDK.
2020
| [getAI(app, options)](./ai.md#getai_a94a413) | Returns the default [AI](./ai.ai.md#ai_interface) instance that is associated with the provided [FirebaseApp](./app.firebaseapp.md#firebaseapp_interface)<!-- -->. If no instance exists, initializes a new instance with the default settings. |
2121
| [getVertexAI(app, options)](./ai.md#getvertexai_04094cf) | |
2222
| <b>function(ai, ...)</b> |
23-
| [getGenerativeModel(ai, modelParams, requestOptions)](./ai.md#getgenerativemodel_80bd839) | Returns a [GenerativeModel](./ai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. |
23+
| [getGenerativeModel(ai, modelParams, requestOptions)](./ai.md#getgenerativemodel_c63f46a) | Returns a [GenerativeModel](./ai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. |
2424
| [getImagenModel(ai, modelParams, requestOptions)](./ai.md#getimagenmodel_e1f6645) | <b><i>(Public Preview)</i></b> Returns an [ImagenModel](./ai.imagenmodel.md#imagenmodel_class) class with methods for using Imagen.<!-- -->Only Imagen 3 models (named <code>imagen-3.0-*</code>) are supported. |
2525

2626
## Classes
@@ -97,6 +97,7 @@ The Firebase AI Web SDK.
9797
| [GenerativeContentBlob](./ai.generativecontentblob.md#generativecontentblob_interface) | Interface for sending an image. |
9898
| [GroundingAttribution](./ai.groundingattribution.md#groundingattribution_interface) | |
9999
| [GroundingMetadata](./ai.groundingmetadata.md#groundingmetadata_interface) | Metadata returned to client when grounding is enabled. |
100+
| [HybridParams](./ai.hybridparams.md#hybridparams_interface) | Toggles hybrid inference. |
100101
| [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. |
101102
| [ImagenGenerationConfig](./ai.imagengenerationconfig.md#imagengenerationconfig_interface) | <b><i>(Public Preview)</i></b> Configuration options for generating images with Imagen.<!-- -->See the [documentation](http://firebase.google.com/docs/vertex-ai/generate-images-imagen) for more details. |
102103
| [ImagenGenerationResponse](./ai.imagengenerationresponse.md#imagengenerationresponse_interface) | <b><i>(Public Preview)</i></b> The response from a request to generate images with Imagen. |
@@ -105,10 +106,11 @@ The Firebase AI Web SDK.
105106
| [ImagenSafetySettings](./ai.imagensafetysettings.md#imagensafetysettings_interface) | <b><i>(Public Preview)</i></b> 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. |
106107
| [InlineDataPart](./ai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. |
107108
| [ModalityTokenCount](./ai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. |
108-
| [ModelParams](./ai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_80bd839)<!-- -->. |
109+
| [ModelParams](./ai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_c63f46a)<!-- -->. |
109110
| [ObjectSchemaInterface](./ai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./ai.objectschema.md#objectschema_class) class. |
111+
| [OnDeviceParams](./ai.ondeviceparams.md#ondeviceparams_interface) | Encapsulates configuration for on-device inference. |
110112
| [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>. |
111-
| [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_80bd839)<!-- -->. |
113+
| [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_c63f46a)<!-- -->. |
112114
| [RetrievedContextAttribution](./ai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | |
113115
| [SafetyRating](./ai.safetyrating.md#safetyrating_interface) | A safety rating associated with a [GenerateContentCandidate](./ai.generatecontentcandidate.md#generatecontentcandidate_interface) |
114116
| [SafetySetting](./ai.safetysetting.md#safetysetting_interface) | Safety setting that can be sent as part of request parameters. |
@@ -140,6 +142,7 @@ The Firebase AI Web SDK.
140142
| Type Alias | Description |
141143
| --- | --- |
142144
| [BackendType](./ai.md#backendtype) | Type alias representing valid backend types. It can be either <code>'VERTEX_AI'</code> or <code>'GOOGLE_AI'</code>. |
145+
| [InferenceMode](./ai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. |
143146
| [Part](./ai.md#part) | Content part - includes text, image/video, or function call/response part types. |
144147
| [ResponseModality](./ai.md#responsemodality) | <b><i>(Public Preview)</i></b> Generation modalities to be returned in generation responses. |
145148
| [Role](./ai.md#role) | Role is the producer of the content. |
@@ -226,22 +229,22 @@ export declare function getVertexAI(app?: FirebaseApp, options?: VertexAIOptions
226229

227230
## function(ai, ...)
228231

229-
### getGenerativeModel(ai, modelParams, requestOptions) {:#getgenerativemodel_80bd839}
232+
### getGenerativeModel(ai, modelParams, requestOptions) {:#getgenerativemodel_c63f46a}
230233

231234
Returns a [GenerativeModel](./ai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality.
232235

233236
<b>Signature:</b>
234237

235238
```typescript
236-
export declare function getGenerativeModel(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;
239+
export declare function getGenerativeModel(ai: AI, modelParams: ModelParams | HybridParams, requestOptions?: RequestOptions): GenerativeModel;
237240
```
238241

239242
#### Parameters
240243

241244
| Parameter | Type | Description |
242245
| --- | --- | --- |
243246
| ai | [AI](./ai.ai.md#ai_interface) | |
244-
| modelParams | [ModelParams](./ai.modelparams.md#modelparams_interface) | |
247+
| modelParams | [ModelParams](./ai.modelparams.md#modelparams_interface) \| [HybridParams](./ai.hybridparams.md#hybridparams_interface) | |
245248
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | |
246249

247250
<b>Returns:</b>
@@ -360,6 +363,16 @@ Type alias representing valid backend types. It can be either `'VERTEX_AI'` or `
360363
export type BackendType = (typeof BackendType)[keyof typeof BackendType];
361364
```
362365

366+
## InferenceMode
367+
368+
Determines whether inference happens on-device or in-cloud.
369+
370+
<b>Signature:</b>
371+
372+
```typescript
373+
export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud';
374+
```
375+
363376
## Part
364377

365378
Content part - includes text, image/video, or function call/response part types.

docs-devsite/ai.modelparams.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

1212
# ModelParams interface
13-
Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_80bd839)<!-- -->.
13+
Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_c63f46a)<!-- -->.
1414

1515
<b>Signature:</b>
1616

docs-devsite/ai.ondeviceparams.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
# OnDeviceParams interface
13+
Encapsulates configuration for on-device inference.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface OnDeviceParams
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [createOptions](./ai.ondeviceparams.md#ondeviceparamscreateoptions) | LanguageModelCreateOptions | |
26+
| [promptOptions](./ai.ondeviceparams.md#ondeviceparamspromptoptions) | LanguageModelPromptOptions | |
27+
28+
## OnDeviceParams.createOptions
29+
30+
<b>Signature:</b>
31+
32+
```typescript
33+
createOptions?: LanguageModelCreateOptions;
34+
```
35+
36+
## OnDeviceParams.promptOptions
37+
38+
<b>Signature:</b>
39+
40+
```typescript
41+
promptOptions?: LanguageModelPromptOptions;
42+
```

docs-devsite/ai.requestoptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

1212
# RequestOptions interface
13-
Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_80bd839)<!-- -->.
13+
Params passed to [getGenerativeModel()](./ai.md#getgenerativemodel_c63f46a)<!-- -->.
1414

1515
<b>Signature:</b>
1616

packages/ai/src/api.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ describe('Top level API', () => {
102102
expect(genModel).to.be.an.instanceOf(GenerativeModel);
103103
expect(genModel.model).to.equal('publishers/google/models/my-model');
104104
});
105+
it('getGenerativeModel with HybridParams sets a default model', () => {
106+
const genModel = getGenerativeModel(fakeAI, {
107+
mode: 'only_on_device'
108+
});
109+
expect(genModel.model).to.equal(
110+
`publishers/google/models/${GenerativeModel.DEFAULT_HYBRID_IN_CLOUD_MODEL}`
111+
);
112+
});
113+
it('getGenerativeModel with HybridParams honors a model override', () => {
114+
const genModel = getGenerativeModel(fakeAI, {
115+
mode: 'prefer_on_device',
116+
inCloudParams: { model: 'my-model' }
117+
});
118+
expect(genModel.model).to.equal('publishers/google/models/my-model');
119+
});
105120
it('getImagenModel throws if no model is provided', () => {
106121
try {
107122
getImagenModel(fakeAI, {} as ImagenModelParams);

0 commit comments

Comments
 (0)