Class StreamingParts
java.lang.Object
org.springframework.ai.chat.messages.part.StreamingParts
Transport attributes that let a streaming chat model deliver a message part in
increments and let
MessageAggregator rebuild the ordered parts list.
The contract for a streamed ChatResponse chunk:
- A chunk's assistant message carries at most one part per content block index.
- A part stamped with
partial(MessagePart, int)is a delta: text and arguments are appended to what was already received for that index, a non-null payload replaces the accumulated one. - A part stamped with
complete(MessagePart, int)replaces whatever was accumulated for that index. - Parts without an index are aggregated the pre-streaming way: text is concatenated, tool calls are appended, other parts are carried in arrival order.
- The chat model sets
ChatResponseMetadata.idon every chunk of one model response; the aggregator groups indexed parts by that id so that consecutive tool-call rounds flowing through one stream do not merge into each other.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic MessagePartcomplete(MessagePart part, int index) Marks a part as the complete content block at the given index.static booleanisPartial(MessagePart part) Whether a streamed part is a delta.static MessagePartpartial(MessagePart part, int index) Marks a part as a delta of the content block at the given index.static @Nullable IntegerpartIndex(MessagePart part) The content block index of a streamed part.static MessagePartstrip(MessagePart part) Removes the streaming attributes from a part.
-
Field Details
-
PART_INDEX_ATTRIBUTE
Attribute holding the zero-based content block index of a streamed part.- See Also:
-
PARTIAL_ATTRIBUTE
Attribute set totrueon a streamed part that is a delta.- See Also:
-
-
Method Details
-
partial
Marks a part as a delta of the content block at the given index.- Parameters:
part- the partindex- the content block index- Returns:
- a copy of the part with the streaming attributes set
-
complete
Marks a part as the complete content block at the given index.- Parameters:
part- the partindex- the content block index- Returns:
- a copy of the part with the index set and no partial flag
-
partIndex
The content block index of a streamed part.- Parameters:
part- the part- Returns:
- the index, or
nullwhen absent or malformed
-
isPartial
Whether a streamed part is a delta.- Parameters:
part- the part- Returns:
trueonly when the partial attribute is"true"
-
strip
Removes the streaming attributes from a part.- Parameters:
part- the part- Returns:
- the same value when nothing was stamped, else a copy without the streaming attributes
-