in content_api.py [0:0]
def from_dict(cls, *, data: dict[str, Any]) -> 'ProcessorPart':
"""Deserializes a ProcessorPart from a JSON-compatible dictionary.
This method reconstructs a ProcessorPart instance from a dictionary
that was typically generated by the `to_dict()` method of another
ProcessorPart instance.
Args:
data: A JSON-compatible dictionary containing the serialized data for the
ProcessorPart.
It is expected to have the following keys:
* 'part' (dict): A dictionary representing the underlying
`google.genai.types.Part` object.
* 'role' (str): The role of the part (e.g., 'user', 'model').
* 'substream_name' (str): The substream name.
* 'mimetype' (str): The MIME type of the part.
* 'metadata' (dict[str, Any]): Auxiliary metadata.
Returns:
A new ProcessorPart instance.
Raises:
pydantic.ValidationError: If the `part` field in `data` is not a valid
dictionary representation of a GenAI part.
KeyError: If 'part' is missing from `data`.
Example:
```py
text_part = ProcessorPart("Hello", role="user")
part_as_dict = text_part.to_dict()
reconstructed = ProcessorPart.from_dict(data=part_as_dict)
print(reconstructed)
```
"""
return cls(
genai_types.Part.model_validate(data['part']),
role=data.get('role', ''),
substream_name=data.get('substream_name', ''),
mimetype=data.get('mimetype'),
metadata=data.get('metadata'),
)