Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions haystack/dataclasses/chat_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
logger = logging.getLogger(__name__)


LEGACY_INIT_PARAMETERS = {"role", "content", "meta", "name"}


class ChatRole(str, Enum):
"""
Enumeration representing the roles within a chat.
Expand Down Expand Up @@ -282,42 +279,6 @@ class ChatMessage:
_name: str | None = None
_meta: dict[str, Any] = field(default_factory=dict, hash=False)

def __new__(cls, *args: Any, **kwargs: Any) -> "ChatMessage": # noqa: ARG004
"""
This method is reimplemented to make the changes to the `ChatMessage` dataclass more visible.

:raises TypeError: If any legacy init parameters (`role`, `content`, `meta`, `name`) are passed.
"""

general_msg = (
"Use the `from_assistant`, `from_user`, `from_system`, and `from_tool` class methods to create a "
"ChatMessage. For more information about the new API and how to migrate, see the documentation:"
" https://docs.haystack.deepset.ai/docs/chatmessage"
)

if any(param in kwargs for param in LEGACY_INIT_PARAMETERS):
raise TypeError(
"The `role`, `content`, `meta`, and `name` init parameters of `ChatMessage` have been removed. "
f"{general_msg}"
)

return super(ChatMessage, cls).__new__(cls) # noqa: UP008

def __getattribute__(self, name: str) -> Any:
"""
This method is reimplemented to make the `content` attribute removal more visible.
"""

if name == "content":
msg = (
"The `content` attribute of `ChatMessage` has been removed. "
"Use the `text` property to access the textual value. "
"For more information about the new API and how to migrate, see the documentation: "
"https://docs.haystack.deepset.ai/docs/chatmessage"
)
raise AttributeError(msg)
return object.__getattribute__(self, name)

def __len__(self) -> int:
return len(self._content)

Expand Down
Loading