From 5f87276c3a122bb0e4f96f0607d48dd5d968e4b5 Mon Sep 17 00:00:00 2001 From: Bagatur Date: Wed, 15 Jan 2025 13:35:04 -0800 Subject: [PATCH] cr --- libs/core/langchain_core/messages/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/core/langchain_core/messages/base.py b/libs/core/langchain_core/messages/base.py index bcc3e86d239..291f4f1dc49 100644 --- a/libs/core/langchain_core/messages/base.py +++ b/libs/core/langchain_core/messages/base.py @@ -119,7 +119,10 @@ class BaseMessage(Serializable): print(self.pretty_repr(html=is_interactive_env())) # noqa: T201 def __getitem__(self, item: str) -> Any: - return self.model_dump()[item] + if item in self.model_fields and hasattr(self, item): + return getattr(self, item) + else: + raise KeyError(item) def merge_content(