mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
[Anthropic] Shallow Copy (#27105)
Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
parent
c6533616b6
commit
0a3e089827
@ -1,3 +1,4 @@
|
||||
import copy
|
||||
import re
|
||||
import warnings
|
||||
from operator import itemgetter
|
||||
@ -116,7 +117,6 @@ def _merge_messages(
|
||||
"""Merge runs of human/tool messages into single human messages with content blocks.""" # noqa: E501
|
||||
merged: list = []
|
||||
for curr in messages:
|
||||
curr = curr.model_copy(deep=True)
|
||||
if isinstance(curr, ToolMessage):
|
||||
if (
|
||||
isinstance(curr.content, list)
|
||||
@ -143,12 +143,12 @@ def _merge_messages(
|
||||
if isinstance(last.content, str):
|
||||
new_content: List = [{"type": "text", "text": last.content}]
|
||||
else:
|
||||
new_content = last.content
|
||||
new_content = copy.copy(last.content)
|
||||
if isinstance(curr.content, str):
|
||||
new_content.append({"type": "text", "text": curr.content})
|
||||
else:
|
||||
new_content.extend(curr.content)
|
||||
last.content = new_content
|
||||
merged[-1] = curr.model_copy(update={"content": new_content}, deep=False)
|
||||
else:
|
||||
merged.append(curr)
|
||||
return merged
|
||||
@ -178,9 +178,11 @@ def _format_messages(
|
||||
raise ValueError("System message must be at beginning of message list.")
|
||||
if isinstance(message.content, list):
|
||||
system = [
|
||||
block
|
||||
if isinstance(block, dict)
|
||||
else {"type": "text", "text": "block"}
|
||||
(
|
||||
block
|
||||
if isinstance(block, dict)
|
||||
else {"type": "text", "text": "block"}
|
||||
)
|
||||
for block in message.content
|
||||
]
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user