diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md
index 05977b66bd9..314e9b7b6fc 100644
--- a/common/api-review/vertexai.api.md
+++ b/common/api-review/vertexai.api.md
@@ -661,6 +661,67 @@ export class IntegerSchema extends Schema {
constructor(schemaParams?: SchemaParams);
}
+// @public
+export interface LanguageModelCreateCoreOptions {
+ expectedInputs?: LanguageModelExpectedInput[];
+ // (undocumented)
+ temperature?: number;
+ // (undocumented)
+ topK?: number;
+}
+
+// @public
+export interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
+ // (undocumented)
+ initialPrompts?: LanguageModelInitialPrompts;
+ // (undocumented)
+ signal?: AbortSignal;
+ // (undocumented)
+ systemPrompt?: string;
+}
+
+// @public
+export interface LanguageModelExpectedInput {
+ // (undocumented)
+ languages?: string[];
+ // (undocumented)
+ type: LanguageModelMessageType;
+}
+
+// @public
+export type LanguageModelInitialPrompts = LanguageModelMessage[] | LanguageModelMessageShorthand[];
+
+// @public
+export interface LanguageModelMessage {
+ // (undocumented)
+ content: LanguageModelMessageContent[];
+ // Warning: (ae-forgotten-export) The symbol "LanguageModelMessageRole" needs to be exported by the entry point index.d.ts
+ //
+ // (undocumented)
+ role: LanguageModelMessageRole;
+}
+
+// @public
+export interface LanguageModelMessageContent {
+ // Warning: (ae-forgotten-export) The symbol "LanguageModelMessageContentValue" needs to be exported by the entry point index.d.ts
+ //
+ // (undocumented)
+ content: LanguageModelMessageContentValue;
+ // (undocumented)
+ type: LanguageModelMessageType;
+}
+
+// @public
+export interface LanguageModelMessageShorthand {
+ // (undocumented)
+ content: string;
+ // (undocumented)
+ role: LanguageModelMessageRole;
+}
+
+// @public
+export type LanguageModelMessageType = 'text' | 'image' | 'audio';
+
// @public
export enum Modality {
AUDIO = "AUDIO",
@@ -719,8 +780,6 @@ export interface ObjectSchemaInterface extends SchemaInterface {
// @public
export interface OnDeviceParams {
- // Warning: (ae-forgotten-export) The symbol "LanguageModelCreateOptions" needs to be exported by the entry point index.d.ts
- //
// (undocumented)
createOptions?: LanguageModelCreateOptions;
// Warning: (ae-forgotten-export) The symbol "LanguageModelPromptOptions" needs to be exported by the entry point index.d.ts
diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml
index 405d11bfc01..8c2c901a45e 100644
--- a/docs-devsite/_toc.yaml
+++ b/docs-devsite/_toc.yaml
@@ -552,6 +552,18 @@ toc:
path: /docs/reference/js/vertexai.inlinedatapart.md
- title: IntegerSchema
path: /docs/reference/js/vertexai.integerschema.md
+ - title: LanguageModelCreateCoreOptions
+ path: /docs/reference/js/vertexai.languagemodelcreatecoreoptions.md
+ - title: LanguageModelCreateOptions
+ path: /docs/reference/js/vertexai.languagemodelcreateoptions.md
+ - title: LanguageModelExpectedInput
+ path: /docs/reference/js/vertexai.languagemodelexpectedinput.md
+ - title: LanguageModelMessage
+ path: /docs/reference/js/vertexai.languagemodelmessage.md
+ - title: LanguageModelMessageContent
+ path: /docs/reference/js/vertexai.languagemodelmessagecontent.md
+ - title: LanguageModelMessageShorthand
+ path: /docs/reference/js/vertexai.languagemodelmessageshorthand.md
- title: ModalityTokenCount
path: /docs/reference/js/vertexai.modalitytokencount.md
- title: ModelParams
diff --git a/docs-devsite/vertexai.languagemodelcreatecoreoptions.md b/docs-devsite/vertexai.languagemodelcreatecoreoptions.md
new file mode 100644
index 00000000000..20e2a7327fc
--- /dev/null
+++ b/docs-devsite/vertexai.languagemodelcreatecoreoptions.md
@@ -0,0 +1,53 @@
+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 %}
+
+# LanguageModelCreateCoreOptions interface
+Defines Prompt API session configuration for availability checking and creation.
+
+Signature:
+
+```typescript
+export interface LanguageModelCreateCoreOptions
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [expectedInputs](./vertexai.languagemodelcreatecoreoptions.md#languagemodelcreatecoreoptionsexpectedinputs) | [LanguageModelExpectedInput](./vertexai.languagemodelexpectedinput.md#languagemodelexpectedinput_interface)\[\] | Configures the Prompt API to prepare for the given input types. |
+| [temperature](./vertexai.languagemodelcreatecoreoptions.md#languagemodelcreatecoreoptionstemperature) | number | |
+| [topK](./vertexai.languagemodelcreatecoreoptions.md#languagemodelcreatecoreoptionstopk) | number | |
+
+## LanguageModelCreateCoreOptions.expectedInputs
+
+Configures the Prompt API to prepare for the given input types.
+
+Signature:
+
+```typescript
+expectedInputs?: LanguageModelExpectedInput[];
+```
+
+## LanguageModelCreateCoreOptions.temperature
+
+Signature:
+
+```typescript
+temperature?: number;
+```
+
+## LanguageModelCreateCoreOptions.topK
+
+Signature:
+
+```typescript
+topK?: number;
+```
diff --git a/docs-devsite/vertexai.languagemodelcreateoptions.md b/docs-devsite/vertexai.languagemodelcreateoptions.md
new file mode 100644
index 00000000000..1f4d2c39e94
--- /dev/null
+++ b/docs-devsite/vertexai.languagemodelcreateoptions.md
@@ -0,0 +1,54 @@
+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 %}
+
+# LanguageModelCreateOptions interface
+Defines Prompt API session configuration used during creation.
+
+See Chrome's Prompt API explainer ([https://github.com/webmachinelearning/prompt-api](https://github.com/webmachinelearning/prompt-api)) for more context.
+
+Signature:
+
+```typescript
+export interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions
+```
+Extends: [LanguageModelCreateCoreOptions](./vertexai.languagemodelcreatecoreoptions.md#languagemodelcreatecoreoptions_interface)
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [initialPrompts](./vertexai.languagemodelcreateoptions.md#languagemodelcreateoptionsinitialprompts) | [LanguageModelInitialPrompts](./vertexai.md#languagemodelinitialprompts) | |
+| [signal](./vertexai.languagemodelcreateoptions.md#languagemodelcreateoptionssignal) | AbortSignal | |
+| [systemPrompt](./vertexai.languagemodelcreateoptions.md#languagemodelcreateoptionssystemprompt) | string | |
+
+## LanguageModelCreateOptions.initialPrompts
+
+Signature:
+
+```typescript
+initialPrompts?: LanguageModelInitialPrompts;
+```
+
+## LanguageModelCreateOptions.signal
+
+Signature:
+
+```typescript
+signal?: AbortSignal;
+```
+
+## LanguageModelCreateOptions.systemPrompt
+
+Signature:
+
+```typescript
+systemPrompt?: string;
+```
diff --git a/docs-devsite/vertexai.languagemodelexpectedinput.md b/docs-devsite/vertexai.languagemodelexpectedinput.md
new file mode 100644
index 00000000000..e6bf3e0f238
--- /dev/null
+++ b/docs-devsite/vertexai.languagemodelexpectedinput.md
@@ -0,0 +1,42 @@
+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 %}
+
+# LanguageModelExpectedInput interface
+Defines input types to prepare for.
+
+Signature:
+
+```typescript
+export interface LanguageModelExpectedInput
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [languages](./vertexai.languagemodelexpectedinput.md#languagemodelexpectedinputlanguages) | string\[\] | |
+| [type](./vertexai.languagemodelexpectedinput.md#languagemodelexpectedinputtype) | [LanguageModelMessageType](./vertexai.md#languagemodelmessagetype) | |
+
+## LanguageModelExpectedInput.languages
+
+Signature:
+
+```typescript
+languages?: string[];
+```
+
+## LanguageModelExpectedInput.type
+
+Signature:
+
+```typescript
+type: LanguageModelMessageType;
+```
diff --git a/docs-devsite/vertexai.languagemodelmessage.md b/docs-devsite/vertexai.languagemodelmessage.md
new file mode 100644
index 00000000000..f7bd3209f1e
--- /dev/null
+++ b/docs-devsite/vertexai.languagemodelmessage.md
@@ -0,0 +1,42 @@
+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 %}
+
+# LanguageModelMessage interface
+Defines a prompt format comparable to Vertex's [Content](./vertexai.content.md#content_interface).
+
+Signature:
+
+```typescript
+export interface LanguageModelMessage
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [content](./vertexai.languagemodelmessage.md#languagemodelmessagecontent) | [LanguageModelMessageContent](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontent_interface)\[\] | |
+| [role](./vertexai.languagemodelmessage.md#languagemodelmessagerole) | LanguageModelMessageRole | |
+
+## LanguageModelMessage.content
+
+Signature:
+
+```typescript
+content: LanguageModelMessageContent[];
+```
+
+## LanguageModelMessage.role
+
+Signature:
+
+```typescript
+role: LanguageModelMessageRole;
+```
diff --git a/docs-devsite/vertexai.languagemodelmessagecontent.md b/docs-devsite/vertexai.languagemodelmessagecontent.md
new file mode 100644
index 00000000000..c9e57900329
--- /dev/null
+++ b/docs-devsite/vertexai.languagemodelmessagecontent.md
@@ -0,0 +1,42 @@
+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 %}
+
+# LanguageModelMessageContent interface
+Defines a prompt format comparable to Vertex's [Part](./vertexai.md#part).
+
+Signature:
+
+```typescript
+export interface LanguageModelMessageContent
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [content](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontentcontent) | LanguageModelMessageContentValue | |
+| [type](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontenttype) | [LanguageModelMessageType](./vertexai.md#languagemodelmessagetype) | |
+
+## LanguageModelMessageContent.content
+
+Signature:
+
+```typescript
+content: LanguageModelMessageContentValue;
+```
+
+## LanguageModelMessageContent.type
+
+Signature:
+
+```typescript
+type: LanguageModelMessageType;
+```
diff --git a/docs-devsite/vertexai.languagemodelmessageshorthand.md b/docs-devsite/vertexai.languagemodelmessageshorthand.md
new file mode 100644
index 00000000000..fb0d9453489
--- /dev/null
+++ b/docs-devsite/vertexai.languagemodelmessageshorthand.md
@@ -0,0 +1,42 @@
+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 %}
+
+# LanguageModelMessageShorthand interface
+Defines a prompt format comparable to a simplified Vertex [Content](./vertexai.content.md#content_interface).
+
+Signature:
+
+```typescript
+export interface LanguageModelMessageShorthand
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [content](./vertexai.languagemodelmessageshorthand.md#languagemodelmessageshorthandcontent) | string | |
+| [role](./vertexai.languagemodelmessageshorthand.md#languagemodelmessageshorthandrole) | LanguageModelMessageRole | |
+
+## LanguageModelMessageShorthand.content
+
+Signature:
+
+```typescript
+content: string;
+```
+
+## LanguageModelMessageShorthand.role
+
+Signature:
+
+```typescript
+role: LanguageModelMessageRole;
+```
diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md
index 034af9bae90..6d22d01faf0 100644
--- a/docs-devsite/vertexai.md
+++ b/docs-devsite/vertexai.md
@@ -105,6 +105,12 @@ The Firebase AI Web SDK.
| [ImagenModelParams](./vertexai.imagenmodelparams.md#imagenmodelparams_interface) | (Public Preview) Parameters for configuring an [ImagenModel](./vertexai.imagenmodel.md#imagenmodel_class). |
| [ImagenSafetySettings](./vertexai.imagensafetysettings.md#imagensafetysettings_interface) | (Public Preview) 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. |
| [InlineDataPart](./vertexai.inlinedatapart.md#inlinedatapart_interface) | Content part interface if the part represents an image. |
+| [LanguageModelCreateCoreOptions](./vertexai.languagemodelcreatecoreoptions.md#languagemodelcreatecoreoptions_interface) | Defines Prompt API session configuration for availability checking and creation. |
+| [LanguageModelCreateOptions](./vertexai.languagemodelcreateoptions.md#languagemodelcreateoptions_interface) | Defines Prompt API session configuration used during creation.See Chrome's Prompt API explainer ([https://github.com/webmachinelearning/prompt-api](https://github.com/webmachinelearning/prompt-api)) for more context. |
+| [LanguageModelExpectedInput](./vertexai.languagemodelexpectedinput.md#languagemodelexpectedinput_interface) | Defines input types to prepare for. |
+| [LanguageModelMessage](./vertexai.languagemodelmessage.md#languagemodelmessage_interface) | Defines a prompt format comparable to Vertex's [Content](./vertexai.content.md#content_interface). |
+| [LanguageModelMessageContent](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontent_interface) | Defines a prompt format comparable to Vertex's [Part](./vertexai.md#part). |
+| [LanguageModelMessageShorthand](./vertexai.languagemodelmessageshorthand.md#languagemodelmessageshorthand_interface) | Defines a prompt format comparable to a simplified Vertex [Content](./vertexai.content.md#content_interface). |
| [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. |
| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_c63f46a). |
| [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. |
@@ -142,6 +148,8 @@ The Firebase AI Web SDK.
| --- | --- |
| [BackendType](./vertexai.md#backendtype) | Type alias representing valid backend types. It can be either 'VERTEX_AI' or 'GOOGLE_AI'. |
| [InferenceMode](./vertexai.md#inferencemode) | Determines whether inference happens on-device or in-cloud. |
+| [LanguageModelInitialPrompts](./vertexai.md#languagemodelinitialprompts) | Enables multiple prompt formats. |
+| [LanguageModelMessageType](./vertexai.md#languagemodelmessagetype) | Indicates the type of prompt content. |
| [Part](./vertexai.md#part) | Content part - includes text, image/video, or function call/response part types. |
| [Role](./vertexai.md#role) | Role is the producer of the content. |
| [Tool](./vertexai.md#tool) | Defines a tool that model can call to access external knowledge. |
@@ -346,6 +354,26 @@ Determines whether inference happens on-device or in-cloud.
export type InferenceMode = 'prefer_on_device' | 'only_on_device' | 'only_in_cloud';
```
+## LanguageModelInitialPrompts
+
+Enables multiple prompt formats.
+
+Signature:
+
+```typescript
+export type LanguageModelInitialPrompts = LanguageModelMessage[] | LanguageModelMessageShorthand[];
+```
+
+## LanguageModelMessageType
+
+Indicates the type of prompt content.
+
+Signature:
+
+```typescript
+export type LanguageModelMessageType = 'text' | 'image' | 'audio';
+```
+
## Part
Content part - includes text, image/video, or function call/response part types.
diff --git a/docs-devsite/vertexai.ondeviceparams.md b/docs-devsite/vertexai.ondeviceparams.md
index 3dae308f5e1..2c0d45cacba 100644
--- a/docs-devsite/vertexai.ondeviceparams.md
+++ b/docs-devsite/vertexai.ondeviceparams.md
@@ -22,7 +22,7 @@ export interface OnDeviceParams
| Property | Type | Description |
| --- | --- | --- |
-| [createOptions](./vertexai.ondeviceparams.md#ondeviceparamscreateoptions) | LanguageModelCreateOptions | |
+| [createOptions](./vertexai.ondeviceparams.md#ondeviceparamscreateoptions) | [LanguageModelCreateOptions](./vertexai.languagemodelcreateoptions.md#languagemodelcreateoptions_interface) | |
| [promptOptions](./vertexai.ondeviceparams.md#ondeviceparamspromptoptions) | LanguageModelPromptOptions | |
## OnDeviceParams.createOptions
diff --git a/packages/vertexai/src/methods/chrome-adapter.ts b/packages/vertexai/src/methods/chrome-adapter.ts
index aa3709048a2..d6de108668d 100644
--- a/packages/vertexai/src/methods/chrome-adapter.ts
+++ b/packages/vertexai/src/methods/chrome-adapter.ts
@@ -104,7 +104,7 @@ export class ChromeAdapter {
*
*
This is comparable to {@link GenerativeModel.generateContent} for generating content in * Cloud.
- * @param request a standard Vertex {@link GenerateContentRequest} + * @param request - a standard Vertex {@link GenerateContentRequest} * @returns {@link Response}, so we can reuse common response formatting. */ async generateContent(request: GenerateContentRequest): PromiseThis is comparable to {@link GenerativeModel.generateContentStream} for generating content in * Cloud.
- * @param request a standard Vertex {@link GenerateContentRequest} + * @param request - a standard Vertex {@link GenerateContentRequest} * @returns {@link Response}, so we can reuse common response formatting. */ async generateContentStream( diff --git a/packages/vertexai/src/types/index.ts b/packages/vertexai/src/types/index.ts index 01f3e7a701a..ce3d0b826c9 100644 --- a/packages/vertexai/src/types/index.ts +++ b/packages/vertexai/src/types/index.ts @@ -23,3 +23,13 @@ export * from './error'; export * from './schema'; export * from './imagen'; export * from './googleai'; +export { + LanguageModelCreateOptions, + LanguageModelCreateCoreOptions, + LanguageModelExpectedInput, + LanguageModelInitialPrompts, + LanguageModelMessage, + LanguageModelMessageContent, + LanguageModelMessageShorthand, + LanguageModelMessageType +} from './language-model'; diff --git a/packages/vertexai/src/types/language-model.ts b/packages/vertexai/src/types/language-model.ts index 22916e7ff96..c4f0f110f4f 100644 --- a/packages/vertexai/src/types/language-model.ts +++ b/packages/vertexai/src/types/language-model.ts @@ -38,11 +38,23 @@ export enum Availability { 'downloading' = 'downloading', 'available' = 'available' } +/** + * Defines Prompt API session configuration for availability checking and creation. + */ export interface LanguageModelCreateCoreOptions { topK?: number; temperature?: number; + /** + * Configures the Prompt API to prepare for the given input types. + */ expectedInputs?: LanguageModelExpectedInput[]; } +/** + * Defines Prompt API session configuration used during creation. + * + * See Chrome's Prompt API explainer ({@link https://github.com/webmachinelearning/prompt-api}) for + * more context. + */ export interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions { signal?: AbortSignal; @@ -53,30 +65,54 @@ export interface LanguageModelPromptOptions { responseConstraint?: object; // TODO: Restore AbortSignal once the API is defined. } -interface LanguageModelExpectedInput { +/** + * Defines input types to prepare for. + */ +export interface LanguageModelExpectedInput { type: LanguageModelMessageType; languages?: string[]; } // TODO: revert to type from Prompt API explainer once it's supported. export type LanguageModelPrompt = LanguageModelMessageContent[]; -type LanguageModelInitialPrompts = +/** + * Enables multiple prompt formats. + */ +export type LanguageModelInitialPrompts = | LanguageModelMessage[] | LanguageModelMessageShorthand[]; -interface LanguageModelMessage { +/** + * Defines a prompt format comparable to Vertex's {@link Content}. + */ +export interface LanguageModelMessage { role: LanguageModelMessageRole; content: LanguageModelMessageContent[]; } -interface LanguageModelMessageShorthand { +/** + * Defines a prompt format comparable to a simplified Vertex {@link Content}. + */ +export interface LanguageModelMessageShorthand { role: LanguageModelMessageRole; content: string; } +/** + * Defines a prompt format comparable to Vertex's {@link Part}. + */ export interface LanguageModelMessageContent { type: LanguageModelMessageType; content: LanguageModelMessageContentValue; } -type LanguageModelMessageRole = 'system' | 'user' | 'assistant'; -type LanguageModelMessageType = 'text' | 'image' | 'audio'; -type LanguageModelMessageContentValue = +/** + * Defines the producer of the prompt. + */ +export type LanguageModelMessageRole = 'system' | 'user' | 'assistant'; +/** + * Indicates the type of prompt content. + */ +export type LanguageModelMessageType = 'text' | 'image' | 'audio'; +/** + * Defines the prompt content itself. + */ +export type LanguageModelMessageContentValue = | ImageBitmapSource | AudioBuffer | BufferSource