Firebase.AI.Chat

An object that represents a back-and-forth chat with a model, capturing the history and saving the context in memory between each message sent.

Summary

Properties

History
IEnumerable< ModelContent >
The previous content from the chat that has been successfully sent and received from the model.

Public functions

SendMessageAsync(ModelContent content, CancellationToken cancellationToken)
Sends a message using the existing history of this chat as context.
SendMessageAsync(string text, CancellationToken cancellationToken)
Sends a message using the existing history of this chat as context.
SendMessageAsync(IEnumerable< ModelContent > content, CancellationToken cancellationToken)
Sends a message using the existing history of this chat as context.
SendMessageStreamAsync(ModelContent content, CancellationToken cancellationToken)
IAsyncEnumerable< GenerateContentResponse >
Sends a message using the existing history of this chat as context.
SendMessageStreamAsync(string text, CancellationToken cancellationToken)
IAsyncEnumerable< GenerateContentResponse >
Sends a message using the existing history of this chat as context.
SendMessageStreamAsync(IEnumerable< ModelContent > content, CancellationToken cancellationToken)
IAsyncEnumerable< GenerateContentResponse >
Sends a message using the existing history of this chat as context.

Properties

History

IEnumerable< ModelContent > History

The previous content from the chat that has been successfully sent and received from the model.

This will be provided to the model for each message sent as context for the discussion.

Public functions

SendMessageAsync

Task< GenerateContentResponse > SendMessageAsync(
  ModelContent content,
  CancellationToken cancellationToken
)

Sends a message using the existing history of this chat as context.

If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.

Details
Parameters
content
The input given to the model as a prompt.
cancellationToken
An optional token to cancel the operation.
Exceptions
HttpRequestException
Thrown when an error occurs during content generation.
Returns
The model's response if no error occurred.

SendMessageAsync

Task< GenerateContentResponse > SendMessageAsync(
  string text,
  CancellationToken cancellationToken
)

Sends a message using the existing history of this chat as context.

If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.

Details
Parameters
text
The text given to the model as a prompt.
cancellationToken
An optional token to cancel the operation.
Exceptions
HttpRequestException
Thrown when an error occurs during content generation.
Returns
The model's response if no error occurred.

SendMessageAsync

Task< GenerateContentResponse > SendMessageAsync(
  IEnumerable< ModelContent > content,
  CancellationToken cancellationToken
)

Sends a message using the existing history of this chat as context.

If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.

Details
Parameters
content
The input given to the model as a prompt.
cancellationToken
An optional token to cancel the operation.
Exceptions
HttpRequestException
Thrown when an error occurs during content generation.
Returns
The model's response if no error occurred.

SendMessageStreamAsync

IAsyncEnumerable< GenerateContentResponse > SendMessageStreamAsync(
  ModelContent content,
  CancellationToken cancellationToken
)

Sends a message using the existing history of this chat as context.

If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.

Details
Parameters
content
The input given to the model as a prompt.
cancellationToken
An optional token to cancel the operation.
Exceptions
HttpRequestException
Thrown when an error occurs during content generation.
Returns
A stream of generated content responses from the model.

SendMessageStreamAsync

IAsyncEnumerable< GenerateContentResponse > SendMessageStreamAsync(
  string text,
  CancellationToken cancellationToken
)

Sends a message using the existing history of this chat as context.

If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.

Details
Parameters
text
The text given to the model as a prompt.
cancellationToken
An optional token to cancel the operation.
Exceptions
HttpRequestException
Thrown when an error occurs during content generation.
Returns
A stream of generated content responses from the model.

SendMessageStreamAsync

IAsyncEnumerable< GenerateContentResponse > SendMessageStreamAsync(
  IEnumerable< ModelContent > content,
  CancellationToken cancellationToken
)

Sends a message using the existing history of this chat as context.

If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.

Details
Parameters
content
The input given to the model as a prompt.
cancellationToken
An optional token to cancel the operation.
Exceptions
HttpRequestException
Thrown when an error occurs during content generation.
Returns
A stream of generated content responses from the model.