Back to Firebase Js Sdk

GenerativeModel class

docs-devsite/ai.generativemodel.md

12.12.17.0 KB
Original Source

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 %}

GenerativeModel class

Class for generative model APIs.

<b>Signature:</b>

typescript
export declare class GenerativeModel extends AIModel 

<b>Extends:</b> AIModel

Constructors

ConstructorModifiersDescription
(constructor)(ai, modelParams, requestOptions, chromeAdapter)Constructs a new instance of the <code>GenerativeModel</code> class

Properties

PropertyModifiersTypeDescription
generationConfigGenerationConfig
requestOptionsRequestOptions
safetySettingsSafetySetting<!-- -->[]
systemInstructionContent
toolConfigToolConfig
toolsTool<!-- -->[]

Methods

MethodModifiersDescription
countTokens(request, singleRequestOptions)Counts the tokens in the provided request.
generateContent(request, singleRequestOptions)Makes a single non-streaming call to the model and returns an object containing a single GenerateContentResponse<!-- -->.
generateContentStream(request, singleRequestOptions)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.
startChat(startChatParams)Gets a new ChatSession instance which can be used for multi-turn chats.

GenerativeModel.(constructor)

Constructs a new instance of the GenerativeModel class

<b>Signature:</b>

typescript
constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions, chromeAdapter?: ChromeAdapter | undefined);

Parameters

ParameterTypeDescription
aiAI
modelParamsModelParams
requestOptionsRequestOptions
chromeAdapterChromeAdapter | undefined

GenerativeModel.generationConfig

<b>Signature:</b>

typescript
generationConfig: GenerationConfig;

GenerativeModel.requestOptions

<b>Signature:</b>

typescript
requestOptions?: RequestOptions;

GenerativeModel.safetySettings

<b>Signature:</b>

typescript
safetySettings: SafetySetting[];

GenerativeModel.systemInstruction

<b>Signature:</b>

typescript
systemInstruction?: Content;

GenerativeModel.toolConfig

<b>Signature:</b>

typescript
toolConfig?: ToolConfig;

GenerativeModel.tools

<b>Signature:</b>

typescript
tools?: Tool[];

GenerativeModel.countTokens()

Counts the tokens in the provided request.

<b>Signature:</b>

typescript
countTokens(request: CountTokensRequest | string | Array<string | Part>, singleRequestOptions?: SingleRequestOptions): Promise<CountTokensResponse>;

Parameters

ParameterTypeDescription
requestCountTokensRequest | string | Array<string | Part<!-- -->>
singleRequestOptionsSingleRequestOptions

<b>Returns:</b>

Promise<CountTokensResponse<!-- -->>

GenerativeModel.generateContent()

Makes a single non-streaming call to the model and returns an object containing a single GenerateContentResponse<!-- -->.

<b>Signature:</b>

typescript
generateContent(request: GenerateContentRequest | string | Array<string | Part>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;

Parameters

ParameterTypeDescription
requestGenerateContentRequest | string | Array<string | Part<!-- -->>
singleRequestOptionsSingleRequestOptions

<b>Returns:</b>

Promise<GenerateContentResult<!-- -->>

GenerativeModel.generateContentStream()

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.

<b>Signature:</b>

typescript
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;

Parameters

ParameterTypeDescription
requestGenerateContentRequest | string | Array<string | Part<!-- -->>
singleRequestOptionsSingleRequestOptions

<b>Returns:</b>

Promise<GenerateContentStreamResult<!-- -->>

GenerativeModel.startChat()

Gets a new ChatSession instance which can be used for multi-turn chats.

<b>Signature:</b>

typescript
startChat(startChatParams?: StartChatParams): ChatSession;

Parameters

ParameterTypeDescription
startChatParamsStartChatParams

<b>Returns:</b>

ChatSession