Share via


TextContent Class

This represents text response content.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Constructor

TextContent(*, inner_content: Any | None = None, ai_model_id: str | None = None, metadata: dict[str, Any] = None, content_type: Literal[ContentTypes.TEXT_CONTENT] = 'text', text: str, encoding: str | None = None)

Parameters

Name Description
inner_content
Required

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.

ai_model_id
Required

str | None - The id of the AI model that generated this response.

metadata
Required

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

text
Required

str | None - The text of the response.

encoding
Required

str | None - The encoding of the text.

Keyword-Only Parameters

Name Description
inner_content
Required
ai_model_id
Required
metadata
Required
content_type
Default value: text
text
Required
encoding
Required

Methods

from_element

Create an instance from an Element.

to_dict

Convert the instance to a dictionary.

to_element

Convert the instance to an Element.

from_element

Create an instance from an Element.

from_element(element: Element) -> _T

Parameters

Name Description
element
Required

to_dict

Convert the instance to a dictionary.

to_dict() -> dict[str, str]

to_element

Convert the instance to an Element.

to_element() -> Element

Attributes

content_type

content_type: Literal[ContentTypes.TEXT_CONTENT]

encoding

encoding: str | None

tag

tag: ClassVar[str] = 'text'

text

text: str