FirebaseVertexAI Framework Reference

Chat

@available(iOS15.0,macOS12.0,tvOS15.0,watchOS8.0,*)publicfinalclassChat:Sendable

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

  • The previous content from the chat that has been successfully sent and received from themodel. This will be provided to the model for each message sent as context for the discussion.

    Declaration

    Swift

    publicvarhistory:[ModelContent]{getset}
  • Sends a message using the existing history of this chat as context. If successful, the messageand response will be added to the history. If unsuccessful, history will remain unchanged.

    Throws

    AGenerateContentError if an error occurred.

    Declaration

    Swift

    publicfuncsendMessage(_parts:anyPartsRepresentable...)asyncthrows->GenerateContentResponse

    Parameters

    parts

    The new content to send as a single chat message.

    Return Value

    The model’s response if no error occurred.

  • Sends a message using the existing history of this chat as context. If successful, the messageand response will be added to the history. If unsuccessful, history will remain unchanged.

    Throws

    AGenerateContentError if an error occurred.

    Declaration

    Swift

    publicfuncsendMessage(_content:[ModelContent])asyncthrows->GenerateContentResponse

    Parameters

    content

    The new content to send as a single chat message.

    Return Value

    The model’s response if no error occurred.

  • Sends a message using the existing history of this chat as context. If successful, the messageand response will be added to the history. If unsuccessful, history will remain unchanged.

    Declaration

    Swift

    @available(macOS12.0,*)publicfuncsendMessageStream(_parts:anyPartsRepresentable...)throws->AsyncThrowingStream<GenerateContentResponse,Error>

    Parameters

    parts

    The new content to send as a single chat message.

    Return Value

    A stream containing the model’s response or an error if an error occurred.

  • Sends a message using the existing history of this chat as context. If successful, the messageand response will be added to the history. If unsuccessful, history will remain unchanged.

    Declaration

    Swift

    @available(macOS12.0,*)publicfuncsendMessageStream(_content:[ModelContent])throws->AsyncThrowingStream<GenerateContentResponse,Error>

    Parameters

    content

    The new content to send as a single chat message.

    Return Value

    A stream containing the model’s response or an error if an error occurred.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-03-06 UTC.