StreamingChatMessageContent Class

This is the class for streaming chat message response content.

All Chat Completion Services should return an instance of this class as streaming response, where each part of the response as it is streamed is converted to an instance of this class, the end-user will have to either do something directly or gather them and combine them into a new instance. A service can implement their own subclass of this class and return instances of that.

Create a new instance of StreamingChatMessageContent.

Constructor

StreamingChatMessageContent(role: AuthorRole, choice_index: int, items: list[BinaryContent | ImageContent | StreamingTextContent | FunctionCallContent | FunctionResultContent | StreamingFileReferenceContent | StreamingAnnotationContent] | None = None, content: str | None = None, inner_content: Any | None = None, name: str | None = None, encoding: str | None = None, finish_reason: FinishReason | None = None, ai_model_id: str | None = None, metadata: dict[str, Any] | None = None, function_invoke_attempt: int | None = None)

Parameters

Name Description
choice_index
Required

int - The index of the choice that generated this response.

inner_content

Optional[Any] - The inner content of the response, this should hold all the information from the response so even when not creating a subclass a developer can leverage the full thing.

Default value: None
ai_model_id

Optional[str] - The id of the AI model that generated this response.

Default value: None
metadata

Dict[str, Any] - Any metadata that should be attached to the response.

Default value: None
role
Required

Optional[ChatRole] - The role of the chat message, defaults to ASSISTANT.

content

Optional[str] - The text of the response.

Default value: None
encoding

Optional[str] - The encoding of the text.

Default value: None
role
Required

The role of the chat message.

choice_index
Required

The index of the choice that generated this response.

items

The content.

Default value: None
content
Required

The text of the response.

inner_content
Required

The inner content of the response, this should hold all the information from the response so even when not creating a subclass a developer can leverage the full thing.

name

The name of the response.

Default value: None
encoding
Required

The encoding of the text.

finish_reason

The reason the response was finished.

Default value: None
metadata
Required

Any metadata that should be attached to the response.

ai_model_id
Required

The id of the AI model that generated this response.

function_invoke_attempt

Tracks the current attempt count for automatically invoking functions. This value increments with each subsequent automatic invocation attempt.

Default value: None

Methods

to_element

Convert the StreamingChatMessageContent to an XML Element.

to_element

Convert the StreamingChatMessageContent to an XML Element.

to_element() -> Element

Parameters

Name Description
root_key
Required

str - The key to use for the root of the XML Element.

Returns

Type Description

Element - The XML Element representing the StreamingChatMessageContent.

Attributes

ai_model_id

ai_model_id: str | None

choice_index

choice_index: int

content_type

content_type: Literal[ContentTypes.CHAT_MESSAGE_CONTENT]

encoding

encoding: str | None

finish_reason

finish_reason: FinishReason | None

function_invoke_attempt

function_invoke_attempt: int | None

inner_content

inner_content: Annotated[Any | None, Field(exclude=True)]

items

items: list[Annotated[ITEM_TYPES, Field(discriminator=DISCRIMINATOR_FIELD)]]

metadata

metadata: dict[str, Any]

name

name: str | None

role

role: AuthorRole