FirebaseVertexAI Framework Reference

Chat

@available(iOS 15.0, macOS 11.0, *)
public class 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.

  • 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.

    Declaration

    Swift

    public var history: [ModelContent]
  • 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.

    Throws

    A GenerateContentError if an error occurred.

    Declaration

    Swift

    public func sendMessage(_ parts: any ThrowingPartsRepresentable...) async throws
      -> 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 message and response will be added to the history. If unsuccessful, history will remain unchanged.

    Throws

    A GenerateContentError if an error occurred.

    Declaration

    Swift

    public func sendMessage(_ content: @autoclosure () throws -> [ModelContent]) async throws
      -> 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 message and response will be added to the history. If unsuccessful, history will remain unchanged.

    Declaration

    Swift

    @available(macOS 12.0, *)
    public func sendMessageStream(_ parts: any ThrowingPartsRepresentable...)
      -> 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 message and response will be added to the history. If unsuccessful, history will remain unchanged.

    Declaration

    Swift

    @available(macOS 12.0, *)
    public func sendMessageStream(_ content: @autoclosure () throws -> [ModelContent])
      -> 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.