From 56472172687d80b43919d6e6ed4269207b1bf773 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Wed, 7 May 2025 09:02:55 -0700 Subject: [PATCH 1/3] Document exported LanguageModel types --- common/api-review/vertexai.api.md | 94 +++++++++++- docs-devsite/_toc.yaml | 14 ++ docs-devsite/vertexai.hybridparams.md | 2 +- docs-devsite/vertexai.languagemodel.md | 142 ++++++++++++++++++ ...vertexai.languagemodelcreatecoreoptions.md | 53 +++++++ .../vertexai.languagemodelcreateoptions.md | 54 +++++++ .../vertexai.languagemodelexpectedinput.md | 42 ++++++ docs-devsite/vertexai.languagemodelmessage.md | 42 ++++++ .../vertexai.languagemodelmessagecontent.md | 40 +++++ .../vertexai.languagemodelmessageshorthand.md | 40 +++++ docs-devsite/vertexai.md | 45 ++++++ .../vertexai/src/methods/chrome-adapter.ts | 4 +- packages/vertexai/src/types/index.ts | 1 + packages/vertexai/src/types/language-model.ts | 29 +++- 14 files changed, 594 insertions(+), 8 deletions(-) create mode 100644 docs-devsite/vertexai.languagemodel.md create mode 100644 docs-devsite/vertexai.languagemodelcreatecoreoptions.md create mode 100644 docs-devsite/vertexai.languagemodelcreateoptions.md create mode 100644 docs-devsite/vertexai.languagemodelexpectedinput.md create mode 100644 docs-devsite/vertexai.languagemodelmessage.md create mode 100644 docs-devsite/vertexai.languagemodelmessagecontent.md create mode 100644 docs-devsite/vertexai.languagemodelmessageshorthand.md diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 8758d25bdce..743590ba1b4 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -74,6 +74,18 @@ export class ArraySchema extends Schema { toJSON(): SchemaRequest; } +// @public (undocumented) +export enum Availability { + // (undocumented) + 'available' = "available", + // (undocumented) + 'downloadable' = "downloadable", + // (undocumented) + 'downloading' = "downloading", + // (undocumented) + 'unavailable' = "unavailable" +} + // @public export abstract class Backend { protected constructor(type: BackendType); @@ -553,7 +565,6 @@ export enum HarmSeverity { export interface HybridParams { inCloudParams?: ModelParams; mode: InferenceMode; - // Warning: (ae-forgotten-export) The symbol "LanguageModelCreateOptions" needs to be exported by the entry point index.d.ts onDeviceParams?: LanguageModelCreateOptions; } @@ -662,6 +673,87 @@ export class IntegerSchema extends Schema { constructor(schemaParams?: SchemaParams); } +// @public +export interface LanguageModel extends EventTarget { + // (undocumented) + availability(options?: LanguageModelCreateCoreOptions): Promise; + // (undocumented) + create(options?: LanguageModelCreateOptions): Promise; + // (undocumented) + destroy(): undefined; + // (undocumented) + measureInputUsage(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise; + // Warning: (ae-forgotten-export) The symbol "LanguageModelPromptOptions" needs to be exported by the entry point index.d.ts + // + // (undocumented) + prompt(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise; + // (undocumented) + promptStreaming(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): ReadableStream; +} + +// @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[]; + // Warning: (ae-forgotten-export) The symbol "LanguageModelMessageType" needs to be exported by the entry point index.d.ts + // + // (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 (undocumented) +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 (undocumented) +export interface LanguageModelMessageShorthand { + // (undocumented) + content: string; + // (undocumented) + role: LanguageModelMessageRole; +} + +// @public (undocumented) +export type LanguageModelPrompt = LanguageModelMessageContent[]; + // @public export enum Modality { AUDIO = "AUDIO", diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index c1a10429ad7..b1857bdca06 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -552,6 +552,20 @@ toc: path: /docs/reference/js/vertexai.inlinedatapart.md - title: IntegerSchema path: /docs/reference/js/vertexai.integerschema.md + - title: LanguageModel + path: /docs/reference/js/vertexai.languagemodel.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.hybridparams.md b/docs-devsite/vertexai.hybridparams.md index cf847b40fa7..d0064981a62 100644 --- a/docs-devsite/vertexai.hybridparams.md +++ b/docs-devsite/vertexai.hybridparams.md @@ -24,7 +24,7 @@ export interface HybridParams | --- | --- | --- | | [inCloudParams](./vertexai.hybridparams.md#hybridparamsincloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for in-cloud inference. | | [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | Specifies on-device or in-cloud inference. Defaults to prefer on-device. | -| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | LanguageModelCreateOptions | Optional. Specifies advanced params for on-device inference. | +| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | [LanguageModelCreateOptions](./vertexai.languagemodelcreateoptions.md#languagemodelcreateoptions_interface) | Optional. Specifies advanced params for on-device inference. | ## HybridParams.inCloudParams diff --git a/docs-devsite/vertexai.languagemodel.md b/docs-devsite/vertexai.languagemodel.md new file mode 100644 index 00000000000..73838606e4d --- /dev/null +++ b/docs-devsite/vertexai.languagemodel.md @@ -0,0 +1,142 @@ +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 %} + +# LanguageModel interface + Copyright 2025 Google LLC + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + +Signature: + +```typescript +export interface LanguageModel extends EventTarget +``` +Extends: EventTarget + +## Methods + +| Method | Description | +| --- | --- | +| [availability(options)](./vertexai.languagemodel.md#languagemodelavailability) | | +| [create(options)](./vertexai.languagemodel.md#languagemodelcreate) | | +| [destroy()](./vertexai.languagemodel.md#languagemodeldestroy) | | +| [measureInputUsage(input, options)](./vertexai.languagemodel.md#languagemodelmeasureinputusage) | | +| [prompt(input, options)](./vertexai.languagemodel.md#languagemodelprompt) | | +| [promptStreaming(input, options)](./vertexai.languagemodel.md#languagemodelpromptstreaming) | | + +## LanguageModel.availability() + +Signature: + +```typescript +availability(options?: LanguageModelCreateCoreOptions): Promise; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| options | [LanguageModelCreateCoreOptions](./vertexai.languagemodelcreatecoreoptions.md#languagemodelcreatecoreoptions_interface) | | + +Returns: + +Promise<[Availability](./vertexai.md#availability)> + +## LanguageModel.create() + +Signature: + +```typescript +create(options?: LanguageModelCreateOptions): Promise; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| options | [LanguageModelCreateOptions](./vertexai.languagemodelcreateoptions.md#languagemodelcreateoptions_interface) | | + +Returns: + +Promise<[LanguageModel](./vertexai.languagemodel.md#languagemodel_interface)> + +## LanguageModel.destroy() + +Signature: + +```typescript +destroy(): undefined; +``` +Returns: + +undefined + +## LanguageModel.measureInputUsage() + +Signature: + +```typescript +measureInputUsage(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| input | [LanguageModelPrompt](./vertexai.md#languagemodelprompt) | | +| options | LanguageModelPromptOptions | | + +Returns: + +Promise<number> + +## LanguageModel.prompt() + +Signature: + +```typescript +prompt(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| input | [LanguageModelPrompt](./vertexai.md#languagemodelprompt) | | +| options | LanguageModelPromptOptions | | + +Returns: + +Promise<string> + +## LanguageModel.promptStreaming() + +Signature: + +```typescript +promptStreaming(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): ReadableStream; +``` + +#### Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| input | [LanguageModelPrompt](./vertexai.md#languagemodelprompt) | | +| options | LanguageModelPromptOptions | | + +Returns: + +ReadableStream + 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..d270cd6b664 --- /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 | | + +## 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..4620fc6c1ed --- /dev/null +++ b/docs-devsite/vertexai.languagemodelmessagecontent.md @@ -0,0 +1,40 @@ +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 +Signature: + +```typescript +export interface LanguageModelMessageContent +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [content](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontentcontent) | LanguageModelMessageContentValue | | +| [type](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontenttype) | 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..95b129d23ff --- /dev/null +++ b/docs-devsite/vertexai.languagemodelmessageshorthand.md @@ -0,0 +1,40 @@ +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 +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 46eafd41e80..5b1cfe42b56 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -49,6 +49,7 @@ The Firebase AI Web SDK. | Enumeration | Description | | --- | --- | | [AIErrorCode](./vertexai.md#aierrorcode) | Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. | +| [Availability](./vertexai.md#availability) | | | [BlockReason](./vertexai.md#blockreason) | Reason that a prompt was blocked. | | [FinishReason](./vertexai.md#finishreason) | Reason that a candidate finished. | | [FunctionCallingMode](./vertexai.md#functioncallingmode) | | @@ -105,6 +106,13 @@ 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. | +| [LanguageModel](./vertexai.languagemodel.md#languagemodel_interface) | Copyright 2025 Google LLCLicensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | +| [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) | | +| [LanguageModelMessageShorthand](./vertexai.languagemodelmessageshorthand.md#languagemodelmessageshorthand_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. | @@ -141,6 +149,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. | +| [LanguageModelPrompt](./vertexai.md#languagemodelprompt) | | | [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. | @@ -345,6 +355,24 @@ 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[]; +``` + +## LanguageModelPrompt + +Signature: + +```typescript +export type LanguageModelPrompt = LanguageModelMessageContent[]; +``` + ## Part Content part - includes text, image/video, or function call/response part types. @@ -425,6 +453,23 @@ export declare const enum AIErrorCode | RESPONSE\_ERROR | "response-error" | An error occurred in a response. | | UNSUPPORTED | "unsupported" | An error occured due an attempt to use an unsupported feature. | +## Availability + +Signature: + +```typescript +export declare enum Availability +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| available | "available" | | +| downloadable | "downloadable" | | +| downloading | "downloading" | | +| unavailable | "unavailable" | | + ## BlockReason Reason that a prompt was blocked. diff --git a/packages/vertexai/src/methods/chrome-adapter.ts b/packages/vertexai/src/methods/chrome-adapter.ts index 9ba674937a8..65b707fae78 100644 --- a/packages/vertexai/src/methods/chrome-adapter.ts +++ b/packages/vertexai/src/methods/chrome-adapter.ts @@ -101,7 +101,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): Promise { @@ -120,7 +120,7 @@ export class ChromeAdapter { * *

This 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..877fca4b57c 100644 --- a/packages/vertexai/src/types/index.ts +++ b/packages/vertexai/src/types/index.ts @@ -23,3 +23,4 @@ export * from './error'; export * from './schema'; export * from './imagen'; export * from './googleai'; +export * from './language-model'; diff --git a/packages/vertexai/src/types/language-model.ts b/packages/vertexai/src/types/language-model.ts index cd84f22dbdb..07bfad6cfd9 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; @@ -52,20 +64,29 @@ export interface LanguageModelCreateOptions interface LanguageModelPromptOptions { signal?: AbortSignal; } -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 { +export interface LanguageModelMessageShorthand { role: LanguageModelMessageRole; content: string; } From 6020be90f0a9c89aa16f8bcbe6c169f2edc14b77 Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Wed, 7 May 2025 10:13:36 -0700 Subject: [PATCH 2/3] Restore itemized exports --- common/api-review/vertexai.api.md | 37 +---- docs-devsite/_toc.yaml | 2 - docs-devsite/vertexai.languagemodel.md | 142 ------------------ .../vertexai.languagemodelmessagecontent.md | 2 + .../vertexai.languagemodelmessageshorthand.md | 2 + docs-devsite/vertexai.md | 32 +--- packages/vertexai/src/types/index.ts | 10 +- packages/vertexai/src/types/language-model.ts | 6 + 8 files changed, 23 insertions(+), 210 deletions(-) delete mode 100644 docs-devsite/vertexai.languagemodel.md diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 743590ba1b4..c94119f919c 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -74,18 +74,6 @@ export class ArraySchema extends Schema { toJSON(): SchemaRequest; } -// @public (undocumented) -export enum Availability { - // (undocumented) - 'available' = "available", - // (undocumented) - 'downloadable' = "downloadable", - // (undocumented) - 'downloading' = "downloading", - // (undocumented) - 'unavailable' = "unavailable" -} - // @public export abstract class Backend { protected constructor(type: BackendType); @@ -673,24 +661,6 @@ export class IntegerSchema extends Schema { constructor(schemaParams?: SchemaParams); } -// @public -export interface LanguageModel extends EventTarget { - // (undocumented) - availability(options?: LanguageModelCreateCoreOptions): Promise; - // (undocumented) - create(options?: LanguageModelCreateOptions): Promise; - // (undocumented) - destroy(): undefined; - // (undocumented) - measureInputUsage(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise; - // Warning: (ae-forgotten-export) The symbol "LanguageModelPromptOptions" needs to be exported by the entry point index.d.ts - // - // (undocumented) - prompt(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise; - // (undocumented) - promptStreaming(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): ReadableStream; -} - // @public export interface LanguageModelCreateCoreOptions { expectedInputs?: LanguageModelExpectedInput[]; @@ -733,7 +703,7 @@ export interface LanguageModelMessage { role: LanguageModelMessageRole; } -// @public (undocumented) +// @public export interface LanguageModelMessageContent { // Warning: (ae-forgotten-export) The symbol "LanguageModelMessageContentValue" needs to be exported by the entry point index.d.ts // @@ -743,7 +713,7 @@ export interface LanguageModelMessageContent { type: LanguageModelMessageType; } -// @public (undocumented) +// @public export interface LanguageModelMessageShorthand { // (undocumented) content: string; @@ -751,9 +721,6 @@ export interface LanguageModelMessageShorthand { role: LanguageModelMessageRole; } -// @public (undocumented) -export type LanguageModelPrompt = LanguageModelMessageContent[]; - // @public export enum Modality { AUDIO = "AUDIO", diff --git a/docs-devsite/_toc.yaml b/docs-devsite/_toc.yaml index b1857bdca06..816ee941809 100644 --- a/docs-devsite/_toc.yaml +++ b/docs-devsite/_toc.yaml @@ -552,8 +552,6 @@ toc: path: /docs/reference/js/vertexai.inlinedatapart.md - title: IntegerSchema path: /docs/reference/js/vertexai.integerschema.md - - title: LanguageModel - path: /docs/reference/js/vertexai.languagemodel.md - title: LanguageModelCreateCoreOptions path: /docs/reference/js/vertexai.languagemodelcreatecoreoptions.md - title: LanguageModelCreateOptions diff --git a/docs-devsite/vertexai.languagemodel.md b/docs-devsite/vertexai.languagemodel.md deleted file mode 100644 index 73838606e4d..00000000000 --- a/docs-devsite/vertexai.languagemodel.md +++ /dev/null @@ -1,142 +0,0 @@ -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 %} - -# LanguageModel interface - Copyright 2025 Google LLC - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - -Signature: - -```typescript -export interface LanguageModel extends EventTarget -``` -Extends: EventTarget - -## Methods - -| Method | Description | -| --- | --- | -| [availability(options)](./vertexai.languagemodel.md#languagemodelavailability) | | -| [create(options)](./vertexai.languagemodel.md#languagemodelcreate) | | -| [destroy()](./vertexai.languagemodel.md#languagemodeldestroy) | | -| [measureInputUsage(input, options)](./vertexai.languagemodel.md#languagemodelmeasureinputusage) | | -| [prompt(input, options)](./vertexai.languagemodel.md#languagemodelprompt) | | -| [promptStreaming(input, options)](./vertexai.languagemodel.md#languagemodelpromptstreaming) | | - -## LanguageModel.availability() - -Signature: - -```typescript -availability(options?: LanguageModelCreateCoreOptions): Promise; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| options | [LanguageModelCreateCoreOptions](./vertexai.languagemodelcreatecoreoptions.md#languagemodelcreatecoreoptions_interface) | | - -Returns: - -Promise<[Availability](./vertexai.md#availability)> - -## LanguageModel.create() - -Signature: - -```typescript -create(options?: LanguageModelCreateOptions): Promise; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| options | [LanguageModelCreateOptions](./vertexai.languagemodelcreateoptions.md#languagemodelcreateoptions_interface) | | - -Returns: - -Promise<[LanguageModel](./vertexai.languagemodel.md#languagemodel_interface)> - -## LanguageModel.destroy() - -Signature: - -```typescript -destroy(): undefined; -``` -Returns: - -undefined - -## LanguageModel.measureInputUsage() - -Signature: - -```typescript -measureInputUsage(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| input | [LanguageModelPrompt](./vertexai.md#languagemodelprompt) | | -| options | LanguageModelPromptOptions | | - -Returns: - -Promise<number> - -## LanguageModel.prompt() - -Signature: - -```typescript -prompt(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| input | [LanguageModelPrompt](./vertexai.md#languagemodelprompt) | | -| options | LanguageModelPromptOptions | | - -Returns: - -Promise<string> - -## LanguageModel.promptStreaming() - -Signature: - -```typescript -promptStreaming(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): ReadableStream; -``` - -#### Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| input | [LanguageModelPrompt](./vertexai.md#languagemodelprompt) | | -| options | LanguageModelPromptOptions | | - -Returns: - -ReadableStream - diff --git a/docs-devsite/vertexai.languagemodelmessagecontent.md b/docs-devsite/vertexai.languagemodelmessagecontent.md index 4620fc6c1ed..891473fb7d0 100644 --- a/docs-devsite/vertexai.languagemodelmessagecontent.md +++ b/docs-devsite/vertexai.languagemodelmessagecontent.md @@ -10,6 +10,8 @@ https://github.com/firebase/firebase-js-sdk {% endcomment %} # LanguageModelMessageContent interface +Defines a prompt format comparable to Vertex's [Part](./vertexai.md#part). + Signature: ```typescript diff --git a/docs-devsite/vertexai.languagemodelmessageshorthand.md b/docs-devsite/vertexai.languagemodelmessageshorthand.md index 95b129d23ff..fb0d9453489 100644 --- a/docs-devsite/vertexai.languagemodelmessageshorthand.md +++ b/docs-devsite/vertexai.languagemodelmessageshorthand.md @@ -10,6 +10,8 @@ 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 diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index 5b1cfe42b56..176e0265eda 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -49,7 +49,6 @@ The Firebase AI Web SDK. | Enumeration | Description | | --- | --- | | [AIErrorCode](./vertexai.md#aierrorcode) | Standardized error codes that [AIError](./vertexai.aierror.md#aierror_class) can have. | -| [Availability](./vertexai.md#availability) | | | [BlockReason](./vertexai.md#blockreason) | Reason that a prompt was blocked. | | [FinishReason](./vertexai.md#finishreason) | Reason that a candidate finished. | | [FunctionCallingMode](./vertexai.md#functioncallingmode) | | @@ -106,13 +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. | -| [LanguageModel](./vertexai.languagemodel.md#languagemodel_interface) | Copyright 2025 Google LLCLicensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | | [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) | | -| [LanguageModelMessageShorthand](./vertexai.languagemodelmessageshorthand.md#languagemodelmessageshorthand_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. | @@ -150,7 +148,6 @@ 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. | -| [LanguageModelPrompt](./vertexai.md#languagemodelprompt) | | | [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. | @@ -365,14 +362,6 @@ Enables multiple prompt formats. export type LanguageModelInitialPrompts = LanguageModelMessage[] | LanguageModelMessageShorthand[]; ``` -## LanguageModelPrompt - -Signature: - -```typescript -export type LanguageModelPrompt = LanguageModelMessageContent[]; -``` - ## Part Content part - includes text, image/video, or function call/response part types. @@ -453,23 +442,6 @@ export declare const enum AIErrorCode | RESPONSE\_ERROR | "response-error" | An error occurred in a response. | | UNSUPPORTED | "unsupported" | An error occured due an attempt to use an unsupported feature. | -## Availability - -Signature: - -```typescript -export declare enum Availability -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| available | "available" | | -| downloadable | "downloadable" | | -| downloading | "downloading" | | -| unavailable | "unavailable" | | - ## BlockReason Reason that a prompt was blocked. diff --git a/packages/vertexai/src/types/index.ts b/packages/vertexai/src/types/index.ts index 877fca4b57c..3a93e13c930 100644 --- a/packages/vertexai/src/types/index.ts +++ b/packages/vertexai/src/types/index.ts @@ -23,4 +23,12 @@ export * from './error'; export * from './schema'; export * from './imagen'; export * from './googleai'; -export * from './language-model'; +export { + LanguageModelCreateOptions, + LanguageModelCreateCoreOptions, + LanguageModelExpectedInput, + LanguageModelInitialPrompts, + LanguageModelMessage, + LanguageModelMessageContent, + LanguageModelMessageShorthand +} from './language-model'; diff --git a/packages/vertexai/src/types/language-model.ts b/packages/vertexai/src/types/language-model.ts index 07bfad6cfd9..94614ff9750 100644 --- a/packages/vertexai/src/types/language-model.ts +++ b/packages/vertexai/src/types/language-model.ts @@ -86,10 +86,16 @@ export interface LanguageModelMessage { role: LanguageModelMessageRole; content: LanguageModelMessageContent[]; } +/** + * 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; From fb119a7ee6486b69f5bdb21e580b0c1188d6626e Mon Sep 17 00:00:00 2001 From: Erik Eldridge Date: Tue, 13 May 2025 11:36:13 -0700 Subject: [PATCH 3/3] Export missing types --- common/api-review/vertexai.api.md | 5 +++-- .../vertexai.languagemodelexpectedinput.md | 2 +- .../vertexai.languagemodelmessagecontent.md | 2 +- docs-devsite/vertexai.md | 11 +++++++++++ packages/vertexai/src/types/index.ts | 3 ++- packages/vertexai/src/types/language-model.ts | 15 ++++++++++++--- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md index 37ce62b9275..314e9b7b6fc 100644 --- a/common/api-review/vertexai.api.md +++ b/common/api-review/vertexai.api.md @@ -684,8 +684,6 @@ export interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptio export interface LanguageModelExpectedInput { // (undocumented) languages?: string[]; - // Warning: (ae-forgotten-export) The symbol "LanguageModelMessageType" needs to be exported by the entry point index.d.ts - // // (undocumented) type: LanguageModelMessageType; } @@ -721,6 +719,9 @@ export interface LanguageModelMessageShorthand { role: LanguageModelMessageRole; } +// @public +export type LanguageModelMessageType = 'text' | 'image' | 'audio'; + // @public export enum Modality { AUDIO = "AUDIO", diff --git a/docs-devsite/vertexai.languagemodelexpectedinput.md b/docs-devsite/vertexai.languagemodelexpectedinput.md index d270cd6b664..e6bf3e0f238 100644 --- a/docs-devsite/vertexai.languagemodelexpectedinput.md +++ b/docs-devsite/vertexai.languagemodelexpectedinput.md @@ -23,7 +23,7 @@ export interface LanguageModelExpectedInput | Property | Type | Description | | --- | --- | --- | | [languages](./vertexai.languagemodelexpectedinput.md#languagemodelexpectedinputlanguages) | string\[\] | | -| [type](./vertexai.languagemodelexpectedinput.md#languagemodelexpectedinputtype) | LanguageModelMessageType | | +| [type](./vertexai.languagemodelexpectedinput.md#languagemodelexpectedinputtype) | [LanguageModelMessageType](./vertexai.md#languagemodelmessagetype) | | ## LanguageModelExpectedInput.languages diff --git a/docs-devsite/vertexai.languagemodelmessagecontent.md b/docs-devsite/vertexai.languagemodelmessagecontent.md index 891473fb7d0..c9e57900329 100644 --- a/docs-devsite/vertexai.languagemodelmessagecontent.md +++ b/docs-devsite/vertexai.languagemodelmessagecontent.md @@ -23,7 +23,7 @@ export interface LanguageModelMessageContent | Property | Type | Description | | --- | --- | --- | | [content](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontentcontent) | LanguageModelMessageContentValue | | -| [type](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontenttype) | LanguageModelMessageType | | +| [type](./vertexai.languagemodelmessagecontent.md#languagemodelmessagecontenttype) | [LanguageModelMessageType](./vertexai.md#languagemodelmessagetype) | | ## LanguageModelMessageContent.content diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md index c8e0bb1d690..6d22d01faf0 100644 --- a/docs-devsite/vertexai.md +++ b/docs-devsite/vertexai.md @@ -149,6 +149,7 @@ 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. | @@ -363,6 +364,16 @@ Enables multiple prompt formats. 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/packages/vertexai/src/types/index.ts b/packages/vertexai/src/types/index.ts index 3a93e13c930..ce3d0b826c9 100644 --- a/packages/vertexai/src/types/index.ts +++ b/packages/vertexai/src/types/index.ts @@ -30,5 +30,6 @@ export { LanguageModelInitialPrompts, LanguageModelMessage, LanguageModelMessageContent, - LanguageModelMessageShorthand + LanguageModelMessageShorthand, + LanguageModelMessageType } from './language-model'; diff --git a/packages/vertexai/src/types/language-model.ts b/packages/vertexai/src/types/language-model.ts index 4a400687844..c4f0f110f4f 100644 --- a/packages/vertexai/src/types/language-model.ts +++ b/packages/vertexai/src/types/language-model.ts @@ -101,9 +101,18 @@ 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