agent_part.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. from collections.abc import Mapping
  2. from typing import TYPE_CHECKING, Any, Literal, TypeVar, Union, cast
  3. from attrs import define as _attrs_define
  4. from attrs import field as _attrs_field
  5. from ..types import UNSET, Unset
  6. if TYPE_CHECKING:
  7. from ..models.agent_part_source import AgentPartSource
  8. T = TypeVar("T", bound="AgentPart")
  9. @_attrs_define
  10. class AgentPart:
  11. """
  12. Attributes:
  13. id (str):
  14. session_id (str):
  15. message_id (str):
  16. type_ (Literal['agent']):
  17. name (str):
  18. source (Union[Unset, AgentPartSource]):
  19. """
  20. id: str
  21. session_id: str
  22. message_id: str
  23. type_: Literal["agent"]
  24. name: str
  25. source: Union[Unset, "AgentPartSource"] = UNSET
  26. additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
  27. def to_dict(self) -> dict[str, Any]:
  28. id = self.id
  29. session_id = self.session_id
  30. message_id = self.message_id
  31. type_ = self.type_
  32. name = self.name
  33. source: Union[Unset, dict[str, Any]] = UNSET
  34. if not isinstance(self.source, Unset):
  35. source = self.source.to_dict()
  36. field_dict: dict[str, Any] = {}
  37. field_dict.update(self.additional_properties)
  38. field_dict.update(
  39. {
  40. "id": id,
  41. "sessionID": session_id,
  42. "messageID": message_id,
  43. "type": type_,
  44. "name": name,
  45. }
  46. )
  47. if source is not UNSET:
  48. field_dict["source"] = source
  49. return field_dict
  50. @classmethod
  51. def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
  52. from ..models.agent_part_source import AgentPartSource
  53. d = dict(src_dict)
  54. id = d.pop("id")
  55. session_id = d.pop("sessionID")
  56. message_id = d.pop("messageID")
  57. type_ = cast(Literal["agent"], d.pop("type"))
  58. if type_ != "agent":
  59. raise ValueError(f"type must match const 'agent', got '{type_}'")
  60. name = d.pop("name")
  61. _source = d.pop("source", UNSET)
  62. source: Union[Unset, AgentPartSource]
  63. if isinstance(_source, Unset):
  64. source = UNSET
  65. else:
  66. source = AgentPartSource.from_dict(_source)
  67. agent_part = cls(
  68. id=id,
  69. session_id=session_id,
  70. message_id=message_id,
  71. type_=type_,
  72. name=name,
  73. source=source,
  74. )
  75. agent_part.additional_properties = d
  76. return agent_part
  77. @property
  78. def additional_keys(self) -> list[str]:
  79. return list(self.additional_properties.keys())
  80. def __getitem__(self, key: str) -> Any:
  81. return self.additional_properties[key]
  82. def __setitem__(self, key: str, value: Any) -> None:
  83. self.additional_properties[key] = value
  84. def __delitem__(self, key: str) -> None:
  85. del self.additional_properties[key]
  86. def __contains__(self, key: str) -> bool:
  87. return key in self.additional_properties