Convert instance to dictionary including only non-None attributes.
(self)
| 90 | } |
| 91 | |
| 92 | def to_dict(self) -> Dict[str, Any]: |
| 93 | """Convert instance to dictionary including only non-None attributes.""" |
| 94 | result = {} |
| 95 | for field_name in self.__annotations__: |
| 96 | if field_name == "output_kind": |
| 97 | continue |
| 98 | value = getattr(self, field_name, None) |
| 99 | if isinstance(value, PoolingParams): |
| 100 | result[field_name] = value.to_dict() |
| 101 | else: |
| 102 | result[field_name] = value |
| 103 | if self.extra_kwargs: |
| 104 | result.update(self.extra_kwargs) |
| 105 | return result |
| 106 | |
| 107 | @classmethod |
| 108 | def from_dict(cls, data: Dict[str, Any]) -> "PoolingParams": |