ChatSession class

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

Signature:

export declare class ChatSession 

Constructors

Constructor Modifiers Description
(constructor)(apiSettings, model, params, requestOptions) Constructs a new instance of the ChatSession class

Properties

Property Modifiers Type Description
model string
params StartChatParams | undefined
requestOptions RequestOptions | undefined

Methods

Method Modifiers Description
getHistory() Gets the chat history so far. Blocked prompts are not added to history. Blocked candidates are not added to history, nor are the prompts that generated them.
sendMessage(request) Sends a chat message and receives a non-streaming GenerateContentResult
sendMessageStream(request) 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

Signature:

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

Parameters

Parameter Type Description
apiSettings ApiSettings
model string
params StartChatParams | undefined
requestOptions RequestOptions | undefined

ChatSession.model

Signature:

model: string;

ChatSession.params

Signature:

params?: StartChatParams | undefined;

ChatSession.requestOptions

Signature:

requestOptions?: RequestOptions | undefined;

ChatSession.getHistory()

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

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>): Promise<GenerateContentResult>;

Parameters

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

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>): Promise<GenerateContentStreamResult>;

Parameters

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

Returns:

Promise<GenerateContentStreamResult>