ChatSession interface

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

Signature:

export interface ChatSession 

Properties

Property Type Description
model string
params StartChatParams
requestOptions RequestOptions

Methods

Method Description
getHistory() Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history.
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.model

Signature:

model: string;

ChatSession.params

Signature:

params?: StartChatParams;

ChatSession.requestOptions

Signature:

requestOptions?: RequestOptions;

ChatSession.getHistory()

Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history.

Signature:

getHistory(): Promise<Content[]>;

Returns:

Promise<Content[]>

ChatSession.sendMessage()

Sends a chat message and receives a non-streaming GenerateContentResult

Signature:

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

Parameters

Parameter Type Description
request string | Array<string | Part>
singleRequestOptions SingleRequestOptions

Returns:

Promise<GenerateContentResult>

ChatSession.sendMessageStream()

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

Signature:

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

Parameters

Parameter Type Description
request string | Array<string | Part>
singleRequestOptions SingleRequestOptions

Returns:

Promise<GenerateContentStreamResult>