send Message Stream
Sends text as the next turn and returns the model's response in chunks.
The turns so far are sent along with text, so the model has the conversation for context. The message is sent when the returned flow is collected, not when this method is called, and the flow carries one turn and is collected once. The overload taking a list documents the rest.
Parameters
The text of the message to send.
Replaces the session config for this turn rather than merging with it.
Throws
if the returned flow is collected again after a completed turn.
Sends content as the next turn and returns the model's response in chunks.
The turns so far are sent along with content, so the model has the conversation for context. The message is sent when the returned flow is collected, not when this method is called, and the flow carries one turn and is collected once. The overload taking a list documents the rest.
Parameters
The message to send.
Replaces the session config for this turn rather than merging with it.
Throws
if the returned flow is collected again after a completed turn.
Sends contents as the next turn and returns the model's response in chunks.
The turns so far are sent along with contents, so the model has the conversation for context. The turn joins the history once the flow completes, and every chunk is kept, so a ten chunk response adds ten model turns to the history rather than one. A stream that is cut off before the model finishes is kept but is not sent again in later requests.
The message is sent when the returned flow is collected, not when this method is called, so collect one turn before starting the next. Starting a turn while an earlier flow is still uncollected sends the two out of order:
val flow = chat.sendMessageStream("first") // nothing sent yet
chat.sendMessage("second") // sent, and recorded, first
flow.collect {} // "first" is sent now, and the model sees it after "second"Each flow carries one turn and is collected once. Collecting it again after the turn has completed throws, rather than quietly sending the message a second time; collect into a list if you need to read the response more than once. A collection that failed or was abandoned did not complete a turn, so it can be retried.
Parameters
The message to send. Several contents are recorded as one turn.
Replaces the session config for this turn rather than merging with it.
Throws
if the returned flow is collected again after a completed turn.