Back to Firebase Js Sdk

ChatSession class

docs-devsite/ai.chatsession.md

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

ChatSession class

ChatSession class that enables sending chat messages and stores history of sent and received messages so far.

<b>Signature:</b>

typescript
export declare class ChatSession extends ChatSessionBase<StartChatParams, GenerateContentRequest, FunctionDeclarationsTool> 

<b>Extends:</b> ChatSessionBase<!-- --><StartChatParams<!-- -->, GenerateContentRequest<!-- -->, FunctionDeclarationsTool<!-- -->>

Constructors

ConstructorModifiersDescription
(constructor)(apiSettings, model, chromeAdapter, params, requestOptions)Constructs a new instance of the <code>ChatSession</code> class

Properties

PropertyModifiersTypeDescription
modelstring
paramsStartChatParams | undefined
requestOptionsRequestOptions | undefined

Methods

MethodModifiersDescription
sendMessage(request, singleRequestOptions)Sends a chat message and receives a non-streaming GenerateContentResult
sendMessageStream(request, singleRequestOptions)Sends a chat message and receives the response as a GenerateContentStreamResult containing an iterable stream and a response promise.

ChatSession.(constructor)

Constructs a new instance of the ChatSession class

<b>Signature:</b>

typescript
constructor(apiSettings: ApiSettings, model: string, chromeAdapter?: ChromeAdapter | undefined, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);

Parameters

ParameterTypeDescription
apiSettingsApiSettings
modelstring
chromeAdapterChromeAdapter | undefined
paramsStartChatParams | undefined
requestOptionsRequestOptions | undefined

ChatSession.model

<b>Signature:</b>

typescript
model: string;

ChatSession.params

<b>Signature:</b>

typescript
params?: StartChatParams | undefined;

ChatSession.requestOptions

<b>Signature:</b>

typescript
requestOptions?: RequestOptions | undefined;

ChatSession.sendMessage()

Sends a chat message and receives a non-streaming GenerateContentResult

<b>Signature:</b>

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

Parameters

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

<b>Returns:</b>

Promise<GenerateContentResult<!-- -->>

ChatSession.sendMessageStream()

Sends a chat message and receives the response as a GenerateContentStreamResult containing an iterable stream and a response promise.

<b>Signature:</b>

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

Parameters

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

<b>Returns:</b>

Promise<GenerateContentStreamResult<!-- -->>