Skip to content

Commit 241c675

Browse files
authored
chore - remove legacy error messages from ChatMessage (#10887)
1 parent b84a38b commit 241c675

1 file changed

Lines changed: 0 additions & 39 deletions

File tree

haystack/dataclasses/chat_message.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
logger = logging.getLogger(__name__)
1717

1818

19-
LEGACY_INIT_PARAMETERS = {"role", "content", "meta", "name"}
20-
21-
2219
class ChatRole(str, Enum):
2320
"""
2421
Enumeration representing the roles within a chat.
@@ -282,42 +279,6 @@ class ChatMessage:
282279
_name: str | None = None
283280
_meta: dict[str, Any] = field(default_factory=dict, hash=False)
284281

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-
321282
def __len__(self) -> int:
322283
return len(self._content)
323284

0 commit comments

Comments
 (0)