mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-17 16:39:52 +00:00
core[patch]: make BaseMessage subscriptable
This commit is contained in:
parent
1051fa5729
commit
cde3b1eb48
@ -118,6 +118,9 @@ class BaseMessage(Serializable):
|
|||||||
def pretty_print(self) -> None:
|
def pretty_print(self) -> None:
|
||||||
print(self.pretty_repr(html=is_interactive_env())) # noqa: T201
|
print(self.pretty_repr(html=is_interactive_env())) # noqa: T201
|
||||||
|
|
||||||
|
def __getitem__(self, item: str) -> Any:
|
||||||
|
return self.model_dump()[item]
|
||||||
|
|
||||||
|
|
||||||
def merge_content(
|
def merge_content(
|
||||||
first_content: Union[str, list[Union[str, dict]]],
|
first_content: Union[str, list[Union[str, dict]]],
|
||||||
|
@ -1008,3 +1008,9 @@ def test_tool_message_tool_call_id() -> None:
|
|||||||
ToolMessage("foo", tool_call_id=uuid.uuid4())
|
ToolMessage("foo", tool_call_id=uuid.uuid4())
|
||||||
ToolMessage("foo", tool_call_id=1)
|
ToolMessage("foo", tool_call_id=1)
|
||||||
ToolMessage("foo", tool_call_id=1.0)
|
ToolMessage("foo", tool_call_id=1.0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_message_getitem() -> None:
|
||||||
|
msg = BaseMessage(content="foo", role="bar", id=1, type="baz")
|
||||||
|
for k in msg.model_fields:
|
||||||
|
assert msg[k] == getattr(msg, k)
|
||||||
|
Loading…
Reference in New Issue
Block a user