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.

Inheritance
StreamingChatMessageContent
StreamingChatMessageContent

Constructor

StreamingChatMessageContent(role: AuthorRole, choice_index: int, items: list[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)

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

ChatRole - The role of the chat message.

choice_index
Required

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

items

list[TextContent, FunctionCallContent, FunctionResultContent, ImageContent] - The content.

Default value: None
content
Required

str - The text of the response.

inner_content
Required

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.

name

Optional[str] - The name of the response.

Default value: None
encoding
Required

Optional[str] - The encoding of the text.

finish_reason

Optional[FinishReason] - The reason the response was finished.

Default value: None
metadata
Required

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

ai_model_id
Required

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

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

model_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'populate_by_name': True, 'validate_assignment': True}

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.fields from Pydantic V1.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ai_model_id': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'choice_index': FieldInfo(annotation=int, required=True), 'content_type': FieldInfo(annotation=Literal[<ContentTypes.CHAT_MESSAGE_CONTENT: 'message'>], required=False, default='message', init=False), 'encoding': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'finish_reason': FieldInfo(annotation=Union[FinishReason, NoneType], required=False, default=None), 'inner_content': FieldInfo(annotation=Union[Any, NoneType], required=False, default=None), 'items': FieldInfo(annotation=list[Annotated[Union[AnnotationContent, ImageContent, TextContent, FunctionResultContent, FunctionCallContent, FileReferenceContent, StreamingAnnotationContent, StreamingFileReferenceContent], FieldInfo(annotation=NoneType, required=True, discriminator='content_type')]], required=False, default_factory=list), 'metadata': FieldInfo(annotation=dict[str, Any], required=False, default_factory=dict), 'name': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'role': FieldInfo(annotation=AuthorRole, required=True)}

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

inner_content

inner_content: Any | None

items

items: list[Annotated[AnnotationContent | ImageContent | TextContent | FunctionResultContent | FunctionCallContent | FileReferenceContent | StreamingAnnotationContent | StreamingFileReferenceContent, FieldInfo(annotation=NoneType, required=True, discriminator='content_type')]]

metadata

metadata: dict[str, Any]

name

name: str | None

role

role: AuthorRole