LiveSession
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(watchOS, unavailable)
public final class LiveSession : SendableA live WebSocket session, capable of streaming content to and from the model.
Messages are streamed through responses, and can be sent through either the
dedicated realtime API function (such as sendAudioRealtime(_:) and
sendTextRealtime(_:)), or through the incremental API (such as
sendContent(_:turnComplete:)).
To create an instance of this class, see LiveGenerativeModel.
- 
                  
                  An asynchronous stream of messages from the server. These messages from the incremental updates from the model, for the current conversation. DeclarationSwift public var responses: AsyncThrowingStream<LiveServerMessage, Error> { get }
- 
                  
                  Response to a LiveServerToolCallreceived from the server.This method is used both for the realtime API and the incremental API. DeclarationSwift public func sendFunctionResponses(_ responses: [FunctionResponsePart]) asyncParametersresponsesClient generated function results, matched to their respective FunctionCallPartby thefunctionIdfield.
- 
                  
                  Sends an audio input stream to the model, using the realtime API. To learn more about audio formats, and the required state they should be provided in, see the docs on Supported audio formats. DeclarationSwift public func sendAudioRealtime(_ audio: Data) asyncParametersaudioRaw 16-bit PCM audio at 16Hz, used to update the model on the client’s conversation. 
- 
                  
                  Sends a video frame to the model, using the realtime API. Instead of raw video data, the model expects individual frames of the video, sent as images. If your video has audio, send it seperately through sendAudioRealtime(_:).For better performance, frames can also be sent at a lower rate than the video; even as low as 1 frame per second. DeclarationSwift public func sendVideoRealtime(_ video: Data, mimeType: String) asyncParametersvideoEncoded image data extracted from a frame of the video, used to update the model on the client’s conversation. mimeTypeThe IANA standard MIME type of the video frame data (eg; images/png,images/jpegetc.,).
- 
                  
                  Sends a text input stream to the model, using the realtime API. DeclarationSwift public func sendTextRealtime(_ text: String) asyncParameterstextText content to append to the current client’s conversation. 
- 
                  
                  Incremental update of the current conversation. The content is unconditionally appended to the conversation history and used as part of the prompt to the model to generate content. Sending this message will also cause an interruption, if the server is actively generating content. DeclarationSwift public func sendContent(_ content: [ModelContent], turnComplete: Bool = false) asyncParameterscontentContent to append to the current conversation with the model. turnCompleteWhether the server should start generating content with the currently accumulated prompt, or await additional messages before starting generation. By default, the server will await additional messages. 
- 
                  
                  Incremental update of the current conversation. The content is unconditionally appended to the conversation history and used as part of the prompt to the model to generate content. Sending this message will also cause an interruption, if the server is actively generating content. DeclarationSwift public func sendContent(_ parts: any PartsRepresentable..., turnComplete: Bool = false) asyncParameterscontentContent to append to the current conversation with the model (see PartsRepresentablefor conforming types).turnCompleteWhether the server should start generating content with the currently accumulated prompt, or await additional messages before starting generation. By default, the server will await additional messages. 
- 
                  
                  Permanently stop the conversation with the model, and close the connection to the server This method will be called automatically when the LiveSessionis deinitialized, but this method can be called manually to explicitly end the session.Attempting to receive content from a closed session will cause a LiveSessionUnexpectedClosureErrorerror to be thrown.DeclarationSwift public func close() async