|
16 | 16 | logger = logging.getLogger(__name__) |
17 | 17 |
|
18 | 18 |
|
19 | | -LEGACY_INIT_PARAMETERS = {"role", "content", "meta", "name"} |
20 | | - |
21 | | - |
22 | 19 | class ChatRole(str, Enum): |
23 | 20 | """ |
24 | 21 | Enumeration representing the roles within a chat. |
@@ -282,42 +279,6 @@ class ChatMessage: |
282 | 279 | _name: str | None = None |
283 | 280 | _meta: dict[str, Any] = field(default_factory=dict, hash=False) |
284 | 281 |
|
285 | | - def __new__(cls, *args: Any, **kwargs: Any) -> "ChatMessage": # noqa: ARG004 |
286 | | - """ |
287 | | - This method is reimplemented to make the changes to the `ChatMessage` dataclass more visible. |
288 | | -
|
289 | | - :raises TypeError: If any legacy init parameters (`role`, `content`, `meta`, `name`) are passed. |
290 | | - """ |
291 | | - |
292 | | - general_msg = ( |
293 | | - "Use the `from_assistant`, `from_user`, `from_system`, and `from_tool` class methods to create a " |
294 | | - "ChatMessage. For more information about the new API and how to migrate, see the documentation:" |
295 | | - " https://docs.haystack.deepset.ai/docs/chatmessage" |
296 | | - ) |
297 | | - |
298 | | - if any(param in kwargs for param in LEGACY_INIT_PARAMETERS): |
299 | | - raise TypeError( |
300 | | - "The `role`, `content`, `meta`, and `name` init parameters of `ChatMessage` have been removed. " |
301 | | - f"{general_msg}" |
302 | | - ) |
303 | | - |
304 | | - return super(ChatMessage, cls).__new__(cls) # noqa: UP008 |
305 | | - |
306 | | - def __getattribute__(self, name: str) -> Any: |
307 | | - """ |
308 | | - This method is reimplemented to make the `content` attribute removal more visible. |
309 | | - """ |
310 | | - |
311 | | - if name == "content": |
312 | | - msg = ( |
313 | | - "The `content` attribute of `ChatMessage` has been removed. " |
314 | | - "Use the `text` property to access the textual value. " |
315 | | - "For more information about the new API and how to migrate, see the documentation: " |
316 | | - "https://docs.haystack.deepset.ai/docs/chatmessage" |
317 | | - ) |
318 | | - raise AttributeError(msg) |
319 | | - return object.__getattribute__(self, name) |
320 | | - |
321 | 282 | def __len__(self) -> int: |
322 | 283 | return len(self._content) |
323 | 284 |
|
|
0 commit comments