Skip to content

Commit

Permalink
Fix mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed Dec 12, 2023
1 parent 926a90a commit 5507a10
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libs/core/langchain_core/messages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ def _merge_kwargs_dict(
elif isinstance(merged[k], dict):
merged[k] = self._merge_kwargs_dict(merged[k], v)
elif isinstance(merged[k], list):
merged[k] = merged[k].copy()
for i, e in enumerate(v):
if isinstance(e, dict) and isinstance(e.get("index"), int):
i = e["index"]
if i < len(merged[k]):
merged[k][i] = self._merge_kwargs_dict(merged[k][i], e)
else:
merged[k].append(e)
merged[k] = merged[k] + [e]
else:
raise TypeError(
f"Additional kwargs key {k} already exists in this message."
Expand Down

0 comments on commit 5507a10

Please sign in to comment.