Skip to content

Commit 056b9c7

Browse files
committed
feat(ai): server prompt templates
1 parent 22e0a1a commit 056b9c7

33 files changed

+2610
-372
lines changed

.changeset/metal-ties-cry.md

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

common/api-review/ai.api.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ export interface AudioConversationController {
9696
export abstract class Backend {
9797
protected constructor(type: BackendType);
9898
readonly backendType: BackendType;
99+
// (undocumented)
100+
abstract _getModelPath(project: string, model: string): string;
101+
// (undocumented)
102+
abstract _getTemplatePath(project: string, templateId: string): string;
99103
}
100104

101105
// @public
@@ -561,9 +565,19 @@ export function getImagenModel(ai: AI, modelParams: ImagenModelParams, requestOp
561565
// @beta
562566
export function getLiveGenerativeModel(ai: AI, modelParams: LiveModelParams): LiveGenerativeModel;
563567

568+
// @beta
569+
export function getTemplateGenerativeModel(ai: AI, requestOptions?: RequestOptions): TemplateGenerativeModel;
570+
571+
// @beta
572+
export function getTemplateImagenModel(ai: AI, requestOptions?: RequestOptions): TemplateImagenModel;
573+
564574
// @public
565575
export class GoogleAIBackend extends Backend {
566576
constructor();
577+
// (undocumented)
578+
_getModelPath(project: string, model: string): string;
579+
// (undocumented)
580+
_getTemplatePath(project: string, templateId: string): string;
567581
}
568582

569583
// Warning: (ae-internal-missing-underscore) The name "GoogleAICitationMetadata" should be prefixed with an underscore because the declaration is marked as @internal
@@ -1304,6 +1318,40 @@ export class StringSchema extends Schema {
13041318
toJSON(): SchemaRequest;
13051319
}
13061320

1321+
// @beta
1322+
export class TemplateChatSession {
1323+
constructor(_apiSettings: ApiSettings, templateId: string, _history?: Content[], requestOptions?: RequestOptions | undefined);
1324+
getHistory(): Promise<Content[]>;
1325+
// (undocumented)
1326+
requestOptions?: RequestOptions | undefined;
1327+
sendMessage(request: string | Array<string | Part>, inputs?: object): Promise<GenerateContentResult>;
1328+
sendMessageStream(request: string | Array<string | Part>, inputs?: object): Promise<GenerateContentStreamResult>;
1329+
// (undocumented)
1330+
templateId: string;
1331+
}
1332+
1333+
// @beta
1334+
export class TemplateGenerativeModel {
1335+
constructor(ai: AI, requestOptions?: RequestOptions);
1336+
// @internal (undocumented)
1337+
_apiSettings: ApiSettings;
1338+
generateContent(templateId: string, templateVariables: object): Promise<GenerateContentResult>;
1339+
generateContentStream(templateId: string, templateVariables: object): Promise<GenerateContentStreamResult>;
1340+
// (undocumented)
1341+
requestOptions?: RequestOptions;
1342+
startChat(templateId: string, history?: Content[]): TemplateChatSession;
1343+
}
1344+
1345+
// @beta
1346+
export class TemplateImagenModel {
1347+
constructor(ai: AI, requestOptions?: RequestOptions);
1348+
// @internal (undocumented)
1349+
_apiSettings: ApiSettings;
1350+
generateImages(templateId: string, templateVariables: object): Promise<ImagenGenerationResponse<ImagenInlineImage>>;
1351+
// (undocumented)
1352+
requestOptions?: RequestOptions;
1353+
}
1354+
13071355
// @public
13081356
export interface TextPart {
13091357
// (undocumented)
@@ -1397,6 +1445,10 @@ export interface UsageMetadata {
13971445
// @public
13981446
export class VertexAIBackend extends Backend {
13991447
constructor(location?: string);
1448+
// (undocumented)
1449+
_getModelPath(project: string, model: string): string;
1450+
// (undocumented)
1451+
_getTemplatePath(project: string, templateId: string): string;
14001452
readonly location: string;
14011453
}
14021454

docs-devsite/_toc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ toc:
196196
path: /docs/reference/js/ai.startchatparams.md
197197
- title: StringSchema
198198
path: /docs/reference/js/ai.stringschema.md
199+
- title: TemplateChatSession
200+
path: /docs/reference/js/ai.templatechatsession.md
201+
- title: TemplateGenerativeModel
202+
path: /docs/reference/js/ai.templategenerativemodel.md
203+
- title: TemplateImagenModel
204+
path: /docs/reference/js/ai.templateimagenmodel.md
199205
- title: TextPart
200206
path: /docs/reference/js/ai.textpart.md
201207
- title: ThinkingConfig

docs-devsite/ai.backend.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export declare abstract class Backend
3030
| --- | --- | --- | --- |
3131
| [backendType](./ai.backend.md#backendbackendtype) | | [BackendType](./ai.md#backendtype) | Specifies the backend type. |
3232

33+
## Methods
34+
35+
| Method | Modifiers | Description |
36+
| --- | --- | --- |
37+
| [\_getModelPath(project, model)](./ai.backend.md#backend_getmodelpath) | | |
38+
| [\_getTemplatePath(project, templateId)](./ai.backend.md#backend_gettemplatepath) | | |
39+
3340
## Backend.(constructor)
3441

3542
Protected constructor for use by subclasses.
@@ -55,3 +62,42 @@ Specifies the backend type.
5562
```typescript
5663
readonly backendType: BackendType;
5764
```
65+
66+
## Backend.\_getModelPath()
67+
68+
<b>Signature:</b>
69+
70+
```typescript
71+
abstract _getModelPath(project: string, model: string): string;
72+
```
73+
74+
#### Parameters
75+
76+
| Parameter | Type | Description |
77+
| --- | --- | --- |
78+
| project | string | |
79+
| model | string | |
80+
81+
<b>Returns:</b>
82+
83+
string
84+
85+
## Backend.\_getTemplatePath()
86+
87+
<b>Signature:</b>
88+
89+
```typescript
90+
abstract _getTemplatePath(project: string, templateId: string): string;
91+
```
92+
93+
#### Parameters
94+
95+
| Parameter | Type | Description |
96+
| --- | --- | --- |
97+
| project | string | |
98+
| templateId | string | |
99+
100+
<b>Returns:</b>
101+
102+
string
103+

docs-devsite/ai.googleaibackend.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ export declare class GoogleAIBackend extends Backend
2727
| --- | --- | --- |
2828
| [(constructor)()](./ai.googleaibackend.md#googleaibackendconstructor) | | Creates a configuration object for the Gemini Developer API backend. |
2929
30+
## Methods
31+
32+
| Method | Modifiers | Description |
33+
| --- | --- | --- |
34+
| [\_getModelPath(project, model)](./ai.googleaibackend.md#googleaibackend_getmodelpath) | | |
35+
| [\_getTemplatePath(project, templateId)](./ai.googleaibackend.md#googleaibackend_gettemplatepath) | | |
36+
3037
## GoogleAIBackend.(constructor)
3138
3239
Creates a configuration object for the Gemini Developer API backend.
@@ -36,3 +43,42 @@ Creates a configuration object for the Gemini Developer API backend.
3643
```typescript
3744
constructor();
3845
```
46+
47+
## GoogleAIBackend.\_getModelPath()
48+
49+
<b>Signature:</b>
50+
51+
```typescript
52+
_getModelPath(project: string, model: string): string;
53+
```
54+
55+
#### Parameters
56+
57+
| Parameter | Type | Description |
58+
| --- | --- | --- |
59+
| project | string | |
60+
| model | string | |
61+
62+
<b>Returns:</b>
63+
64+
string
65+
66+
## GoogleAIBackend.\_getTemplatePath()
67+
68+
<b>Signature:</b>
69+
70+
```typescript
71+
_getTemplatePath(project: string, templateId: string): string;
72+
```
73+
74+
#### Parameters
75+
76+
| Parameter | Type | Description |
77+
| --- | --- | --- |
78+
| project | string | |
79+
| templateId | string | |
80+
81+
<b>Returns:</b>
82+
83+
string
84+

docs-devsite/ai.md

Lines changed: 53 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,9 @@ 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+
| [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_class) | <b><i>(Public Preview)</i></b> A chat session that enables sending chat messages and stores the history of sent and received messages so far.<!-- -->This session is for multi-turn chats using a server-side template. It should be instantiated with [TemplateGenerativeModel.startChat()](./ai.templategenerativemodel.md#templategenerativemodelstartchat)<!-- -->. |
53+
| [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)<!-- -->. |
54+
| [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)<!-- -->. |
5055
| [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. |
5156

5257
## Interfaces
@@ -339,6 +344,54 @@ export declare function getLiveGenerativeModel(ai: AI, modelParams: LiveModelPar
339344

340345
If the `apiKey` or `projectId` fields are missing in your Firebase config.
341346

347+
### getTemplateGenerativeModel(ai, requestOptions) {:#gettemplategenerativemodel_9476bbc}
348+
349+
> 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.
350+
>
351+
352+
Returns a [TemplateGenerativeModel](./ai.templategenerativemodel.md#templategenerativemodel_class) class for executing server-side templates.
353+
354+
<b>Signature:</b>
355+
356+
```typescript
357+
export declare function getTemplateGenerativeModel(ai: AI, requestOptions?: RequestOptions): TemplateGenerativeModel;
358+
```
359+
360+
#### Parameters
361+
362+
| Parameter | Type | Description |
363+
| --- | --- | --- |
364+
| ai | [AI](./ai.ai.md#ai_interface) | An [AI](./ai.ai.md#ai_interface) instance. |
365+
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. |
366+
367+
<b>Returns:</b>
368+
369+
[TemplateGenerativeModel](./ai.templategenerativemodel.md#templategenerativemodel_class)
370+
371+
### getTemplateImagenModel(ai, requestOptions) {:#gettemplateimagenmodel_9476bbc}
372+
373+
> 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.
374+
>
375+
376+
Returns a [TemplateImagenModel](./ai.templateimagenmodel.md#templateimagenmodel_class) class for executing server-side Imagen templates.
377+
378+
<b>Signature:</b>
379+
380+
```typescript
381+
export declare function getTemplateImagenModel(ai: AI, requestOptions?: RequestOptions): TemplateImagenModel;
382+
```
383+
384+
#### Parameters
385+
386+
| Parameter | Type | Description |
387+
| --- | --- | --- |
388+
| ai | [AI](./ai.ai.md#ai_interface) | An [AI](./ai.ai.md#ai_interface) instance. |
389+
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | Additional options to use when making requests. |
390+
391+
<b>Returns:</b>
392+
393+
[TemplateImagenModel](./ai.templateimagenmodel.md#templateimagenmodel_class)
394+
342395
## function(liveSession, ...)
343396

344397
### startAudioConversation(liveSession, options) {:#startaudioconversation_01c8e7f}

0 commit comments

Comments
 (0)