Skip to content

Commit ca4a66c

Browse files
Merge main into release
2 parents 1f44435 + 5c35f51 commit ca4a66c

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

+2044
-661
lines changed

.changeset/metal-ties-cry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'firebase': minor
3+
'@firebase/ai': minor
4+
---
5+
6+
Add support for server prompt templates.

.changeset/spotty-shirts-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/data-connect": patch
3+
---
4+
5+
Fixed issue where onComplete wasn't triggering when the user calls `unsubscribe` on a subscription.

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"src/index.node.ts",
1818
"--timeout",
1919
"5000",
20-
"src/**/*.test.ts"
20+
"'src/**/!(*-browser)*.test.ts"
2121
],
2222
"env": {
2323
"TS_NODE_COMPILER_OPTIONS": "{\"module\":\"commonjs\"}"

common/api-review/ai.api.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export interface AudioTranscriptionConfig {
100100
export abstract class Backend {
101101
protected constructor(type: BackendType);
102102
readonly backendType: BackendType;
103+
// @internal (undocumented)
104+
abstract _getModelPath(project: string, model: string): string;
105+
// @internal (undocumented)
106+
abstract _getTemplatePath(project: string, templateId: string): string;
103107
}
104108

105109
// @public
@@ -157,6 +161,8 @@ export interface ChromeAdapter {
157161
generateContent(request: GenerateContentRequest): Promise<Response>;
158162
generateContentStream(request: GenerateContentRequest): Promise<Response>;
159163
isAvailable(request: GenerateContentRequest): Promise<boolean>;
164+
// @internal (undocumented)
165+
mode: InferenceMode;
160166
}
161167

162168
// @public
@@ -565,9 +571,19 @@ export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOp
565571
// @beta
566572
export function getLiveGenerativeModel(ai: AI, modelParams: LiveModelParams): LiveGenerativeModel;
567573

574+
// @beta
575+
export function getTemplateGenerativeModel(ai: AI, requestOptions?: RequestOptions): TemplateGenerativeModel;
576+
577+
// @beta
578+
export function getTemplateImagenModel(ai: AI, requestOptions?: RequestOptions): TemplateImagenModel;
579+
568580
// @public
569581
export class GoogleAIBackend extends Backend {
570582
constructor();
583+
// @internal (undocumented)
584+
_getModelPath(project: string, model: string): string;
585+
// @internal (undocumented)
586+
_getTemplatePath(project: string, templateId: string): string;
571587
}
572588

573589
// Warning: (ae-internal-missing-underscore) The name "GoogleAICitationMetadata" should be prefixed with an underscore because the declaration is marked as @internal
@@ -1312,6 +1328,25 @@ export class StringSchema extends Schema {
13121328
toJSON(): SchemaRequest;
13131329
}
13141330

1331+
// @beta
1332+
export class TemplateGenerativeModel {
1333+
constructor(ai: AI, requestOptions?: RequestOptions);
1334+
// @internal (undocumented)
1335+
_apiSettings: ApiSettings;
1336+
generateContent(templateId: string, templateVariables: object): Promise<GenerateContentResult>;
1337+
generateContentStream(templateId: string, templateVariables: object): Promise<GenerateContentStreamResult>;
1338+
requestOptions?: RequestOptions;
1339+
}
1340+
1341+
// @beta
1342+
export class TemplateImagenModel {
1343+
constructor(ai: AI, requestOptions?: RequestOptions);
1344+
// @internal (undocumented)
1345+
_apiSettings: ApiSettings;
1346+
generateImages(templateId: string, templateVariables: object): Promise<ImagenGenerationResponse<ImagenInlineImage>>;
1347+
requestOptions?: RequestOptions;
1348+
}
1349+
13151350
// @public
13161351
export interface TextPart {
13171352
// (undocumented)
@@ -1410,6 +1445,10 @@ export interface UsageMetadata {
14101445
// @public
14111446
export class VertexAIBackend extends Backend {
14121447
constructor(location?: string);
1448+
// @internal (undocumented)
1449+
_getModelPath(project: string, model: string): string;
1450+
// @internal (undocumented)
1451+
_getTemplatePath(project: string, templateId: string): string;
14131452
readonly location: string;
14141453
}
14151454

common/api-review/data-connect.api.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,6 @@ export interface DataConnectResult<Data, Variables> extends OpResult<Data> {
109109
ref: OperationRef<Data, Variables>;
110110
}
111111

112-
// @public
113-
export interface DataConnectSubscription<Data, Variables> {
114-
// (undocumented)
115-
errCallback?: (e?: DataConnectError) => void;
116-
// (undocumented)
117-
unsubscribe: () => void;
118-
// (undocumented)
119-
userCallback: OnResultSubscription<Data, Variables>;
120-
}
121-
122112
// @public (undocumented)
123113
export type DataSource = typeof SOURCE_CACHE | typeof SOURCE_SERVER;
124114

docs-devsite/_toc.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ toc:
198198
path: /docs/reference/js/ai.startchatparams.md
199199
- title: StringSchema
200200
path: /docs/reference/js/ai.stringschema.md
201+
- title: TemplateGenerativeModel
202+
path: /docs/reference/js/ai.templategenerativemodel.md
203+
- title: TemplateImagenModel
204+
path: /docs/reference/js/ai.templateimagenmodel.md
201205
- title: TextPart
202206
path: /docs/reference/js/ai.textpart.md
203207
- title: ThinkingConfig

docs-devsite/ai.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The Firebase AI Web SDK.
2222
| [getGenerativeModel(ai, modelParams, requestOptions)](./ai.md#getgenerativemodel_c63f46a) | Returns a [GenerativeModel](./ai.generativemodel.md#generativemodel_class) class with methods for inference and other functionality. |
2323
| [getImagenModel(ai, modelParams, requestOptions)](./ai.md#getimagenmodel_e1f6645) | 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. |
2424
| [getLiveGenerativeModel(ai, modelParams)](./ai.md#getlivegenerativemodel_f2099ac) | <b><i>(Public Preview)</i></b> Returns a [LiveGenerativeModel](./ai.livegenerativemodel.md#livegenerativemodel_class) class for real-time, bidirectional communication.<!-- -->The Live API is only supported in modern browser windows and Node &gt;<!-- -->= 22. |
25+
| [getTemplateGenerativeModel(ai, requestOptions)](./ai.md#gettemplategenerativemodel_9476bbc) | <b><i>(Public Preview)</i></b> Returns a [TemplateGenerativeModel](./ai.templategenerativemodel.md#templategenerativemodel_class) class for executing server-side templates. |
26+
| [getTemplateImagenModel(ai, requestOptions)](./ai.md#gettemplateimagenmodel_9476bbc) | <b><i>(Public Preview)</i></b> Returns a [TemplateImagenModel](./ai.templateimagenmodel.md#templateimagenmodel_class) class for executing server-side Imagen templates. |
2527
| <b>function(liveSession, ...)</b> |
2628
| [startAudioConversation(liveSession, options)](./ai.md#startaudioconversation_01c8e7f) | <b><i>(Public Preview)</i></b> Starts a real-time, bidirectional audio conversation with the model. This helper function manages the complexities of microphone access, audio recording, playback, and interruptions. |
2729

@@ -47,6 +49,8 @@ The Firebase AI Web SDK.
4749
| [ObjectSchema](./ai.objectschema.md#objectschema_class) | Schema class for "object" types. The <code>properties</code> param must be a map of <code>Schema</code> objects. |
4850
| [Schema](./ai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with <code>JSON.stringify()</code> into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) |
4951
| [StringSchema](./ai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. |
52+
| [TemplateGenerativeModel](./ai.templategenerativemodel.md#templategenerativemodel_class) | <b><i>(Public Preview)</i></b> [GenerativeModel](./ai.generativemodel.md#generativemodel_class) APIs that execute on a server-side template.<!-- -->This class should only be instantiated with [getTemplateGenerativeModel()](./ai.md#gettemplategenerativemodel_9476bbc)<!-- -->. |
53+
| [TemplateImagenModel](./ai.templateimagenmodel.md#templateimagenmodel_class) | <b><i>(Public Preview)</i></b> Class for Imagen model APIs that execute on a server-side template.<!-- -->This class should only be instantiated with [getTemplateImagenModel()](./ai.md#gettemplateimagenmodel_9476bbc)<!-- -->. |
5054
| [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Vertex AI Gemini API.<!-- -->Use this with [AIOptions](./ai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./ai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. |
5155

5256
## Interfaces
@@ -341,6 +345,54 @@ export declare function getLiveGenerativeModel(ai: AI, modelParams: LiveModelPar
341345

342346
If the `apiKey` or `projectId` fields are missing in your Firebase config.
343347

348+
### getTemplateGenerativeModel(ai, requestOptions) {:#gettemplategenerativemodel_9476bbc}
349+
350+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
351+
>
352+
353+
Returns a [TemplateGenerativeModel](./ai.templategenerativemodel.md#templategenerativemodel_class) class for executing server-side templates.
354+
355+
<b>Signature:</b>
356+
357+
```typescript
358+
export declare function getTemplateGenerativeModel(ai: AI, requestOptions?: RequestOptions): TemplateGenerativeModel;
359+
```
360+
361+
#### Parameters
362+
363+
| Parameter | Type | Description |
364+
| --- | --- | --- |
365+
| ai | [AI](./ai.ai.md#ai_interface) | An [AI](./ai.ai.md#ai_interface) instance. |
366+
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. |
367+
368+
<b>Returns:</b>
369+
370+
[TemplateGenerativeModel](./ai.templategenerativemodel.md#templategenerativemodel_class)
371+
372+
### getTemplateImagenModel(ai, requestOptions) {:#gettemplateimagenmodel_9476bbc}
373+
374+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
375+
>
376+
377+
Returns a [TemplateImagenModel](./ai.templateimagenmodel.md#templateimagenmodel_class) class for executing server-side Imagen templates.
378+
379+
<b>Signature:</b>
380+
381+
```typescript
382+
export declare function getTemplateImagenModel(ai: AI, requestOptions?: RequestOptions): TemplateImagenModel;
383+
```
384+
385+
#### Parameters
386+
387+
| Parameter | Type | Description |
388+
| --- | --- | --- |
389+
| ai | [AI](./ai.ai.md#ai_interface) | An [AI](./ai.ai.md#ai_interface) instance. |
390+
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. |
391+
392+
<b>Returns:</b>
393+
394+
[TemplateImagenModel](./ai.templateimagenmodel.md#templateimagenmodel_class)
395+
344396
## function(liveSession, ...)
345397

346398
### startAudioConversation(liveSession, options) {:#startaudioconversation_01c8e7f}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
# TemplateGenerativeModel class
13+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
14+
>
15+
16+
[GenerativeModel](./ai.generativemodel.md#generativemodel_class) APIs that execute on a server-side template.
17+
18+
This class should only be instantiated with [getTemplateGenerativeModel()](./ai.md#gettemplategenerativemodel_9476bbc)<!-- -->.
19+
20+
<b>Signature:</b>
21+
22+
```typescript
23+
export declare class TemplateGenerativeModel
24+
```
25+
26+
## Constructors
27+
28+
| Constructor | Modifiers | Description |
29+
| --- | --- | --- |
30+
| [(constructor)(ai, requestOptions)](./ai.templategenerativemodel.md#templategenerativemodelconstructor) | | <b><i>(Public Preview)</i></b> Constructs a new instance of the <code>TemplateGenerativeModel</code> class |
31+
32+
## Properties
33+
34+
| Property | Modifiers | Type | Description |
35+
| --- | --- | --- | --- |
36+
| [requestOptions](./ai.templategenerativemodel.md#templategenerativemodelrequestoptions) | | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | <b><i>(Public Preview)</i></b> Additional options to use when making requests. |
37+
38+
## Methods
39+
40+
| Method | Modifiers | Description |
41+
| --- | --- | --- |
42+
| [generateContent(templateId, templateVariables)](./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)<!-- -->. |
43+
| [generateContentStream(templateId, templateVariables)](./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. |
44+
45+
## TemplateGenerativeModel.(constructor)
46+
47+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
48+
>
49+
50+
Constructs a new instance of the `TemplateGenerativeModel` class
51+
52+
<b>Signature:</b>
53+
54+
```typescript
55+
constructor(ai: AI, requestOptions?: RequestOptions);
56+
```
57+
58+
#### Parameters
59+
60+
| Parameter | Type | Description |
61+
| --- | --- | --- |
62+
| ai | [AI](./ai.ai.md#ai_interface) | |
63+
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | |
64+
65+
## TemplateGenerativeModel.requestOptions
66+
67+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
68+
>
69+
70+
Additional options to use when making requests.
71+
72+
<b>Signature:</b>
73+
74+
```typescript
75+
requestOptions?: RequestOptions;
76+
```
77+
78+
## TemplateGenerativeModel.generateContent()
79+
80+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
81+
>
82+
83+
Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->.
84+
85+
<b>Signature:</b>
86+
87+
```typescript
88+
generateContent(templateId: string, templateVariables: object): Promise<GenerateContentResult>;
89+
```
90+
91+
#### Parameters
92+
93+
| Parameter | Type | Description |
94+
| --- | --- | --- |
95+
| templateId | string | The ID of the server-side template to execute. |
96+
| templateVariables | object | A key-value map of variables to populate the template with. |
97+
98+
<b>Returns:</b>
99+
100+
Promise&lt;[GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface)<!-- -->&gt;
101+
102+
## TemplateGenerativeModel.generateContentStream()
103+
104+
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
105+
>
106+
107+
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.
108+
109+
<b>Signature:</b>
110+
111+
```typescript
112+
generateContentStream(templateId: string, templateVariables: object): Promise<GenerateContentStreamResult>;
113+
```
114+
115+
#### Parameters
116+
117+
| Parameter | Type | Description |
118+
| --- | --- | --- |
119+
| templateId | string | The ID of the server-side template to execute. |
120+
| templateVariables | object | A key-value map of variables to populate the template with. |
121+
122+
<b>Returns:</b>
123+
124+
Promise&lt;[GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface)<!-- -->&gt;
125+

0 commit comments

Comments
 (0)