ChatMessageContent Class  
This is the class for chat message response content.
All Chat Completion Services should return an instance of this class as response. Or they can implement their own subclass of this class and return an instance.
Create a ChatMessageContent instance.
Constructor
ChatMessageContent(role: AuthorRole, items: list[AnnotationContent | BinaryContent | ImageContent | TextContent | FunctionResultContent | FunctionCallContent | FileReferenceContent | StreamingAnnotationContent | StreamingFileReferenceContent] | 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, *, content_type: Literal[ContentTypes.CHAT_MESSAGE_CONTENT] = 'message')Parameters
| Name | Description | 
|---|---|
| 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
			 | ChatRole - The role of the chat message. | 
| content | Optional[str] - The text of the response. Default value: None | 
| encoding | Optional[str] - The encoding of the text. Default value: None | 
| role 
				Required
			 | AuthorRole - The role of the chat message. | 
| items | list[TextContent, StreamingTextContent, FunctionCallContent, FunctionResultContent, ImageContent] 
 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 | 
| ai_model_id 
				Required
			 | Optional[str] - The id of the AI model that generated this response. | 
| metadata 
				Required
			 | Dict[str, Any] - Any metadata that should be attached to the response. | 
| **kwargs 
				Required
			 | Any - Any additional fields to set on the instance. | 
Keyword-Only Parameters
| Name | Description | 
|---|---|
| content_type | Default value: message | 
Methods
| from_element | Create a new instance of ChatMessageContent from an XML element. | 
| to_dict | Serialize the ChatMessageContent to a dictionary. | 
| to_element | Convert the ChatMessageContent to an XML Element. | 
| to_prompt | Convert the ChatMessageContent to a prompt. | 
from_element
Create a new instance of ChatMessageContent from an XML element.
from_element(element: Element) -> ChatMessageContentParameters
| Name | Description | 
|---|---|
| element 
				Required
			 | Element - The XML Element to create the ChatMessageContent from. | 
Returns
| Type | Description | 
|---|---|
| ChatMessageContent - The new instance of ChatMessageContent or a subclass. | 
to_dict
Serialize the ChatMessageContent to a dictionary.
to_dict(role_key: str = 'role', content_key: str = 'content') -> dict[str, Any]Parameters
| Name | Description | 
|---|---|
| role_key | Default value: role | 
| content_key | Default value: content | 
Returns
| Type | Description | 
|---|---|
| dict - The dictionary representing the ChatMessageContent. | 
to_element
Convert the ChatMessageContent to an XML Element.
to_element() -> ElementParameters
| 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 ChatMessageContent. | 
to_prompt
Convert the ChatMessageContent to a prompt.
to_prompt() -> strReturns
| Type | Description | 
|---|---|
| str - The prompt from the ChatMessageContent. | 
Attributes
content
Get the content of the response, will find the first TextContent's text.
ai_model_id
ai_model_id: str | Nonecontent_type
content_type: Literal[ContentTypes.CHAT_MESSAGE_CONTENT]encoding
encoding: str | Nonefinish_reason
finish_reason: FinishReason | Noneinner_content
inner_content: Annotated[Any | None, Field(exclude=True)]items
items: list[Annotated[AnnotationContent | BinaryContent | ImageContent | TextContent | FunctionResultContent | FunctionCallContent | FileReferenceContent | StreamingAnnotationContent | StreamingFileReferenceContent, FieldInfo(annotation=NoneType, required=True, discriminator='content_type')]]metadata
metadata: dict[str, Any]name
name: str | Nonerole
role: AuthorRoletag
tag: ClassVar[str] = 'message'