Skip to content

Commit bc4251b

Browse files
authored
fix(core): fix index checking when merging lists (#32431)
**Description:** fix an issue I discovered when attempting to merge messages in which one message has an `index` key in its content dictionary and another does not.
1 parent 2543007 commit bc4251b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

libs/core/langchain_core/utils/_merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def merge_lists(left: Optional[list], *others: Optional[list]) -> Optional[list]
9797
to_merge = [
9898
i
9999
for i, e_left in enumerate(merged)
100-
if e_left["index"] == e["index"]
100+
if "index" in e_left and e_left["index"] == e["index"]
101101
]
102102
if to_merge:
103103
# TODO: Remove this once merge_dict is updated with special

libs/core/tests/unit_tests/test_messages.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,11 @@ def test_tool_message_str() -> None:
10191019
("foo", [["bar"]], ["foo", "bar"]),
10201020
(["foo"], ["bar"], ["foobar"]),
10211021
(["foo"], [["bar"]], ["foo", "bar"]),
1022+
(
1023+
[{"text": "foo"}],
1024+
[[{"index": 0, "text": "bar"}]],
1025+
[{"text": "foo"}, {"index": 0, "text": "bar"}],
1026+
),
10221027
],
10231028
)
10241029
def test_merge_content(

0 commit comments

Comments
 (0)