anthropic[patch]: fix msg mutation (#20572)

pull/20574/head^2
Bagatur 3 months ago committed by GitHub
parent 719da8746e
commit 54e9271504
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -95,11 +95,12 @@ def _format_image(image_url: str) -> Dict:
def _merge_messages(
messages: List[BaseMessage],
messages: Sequence[BaseMessage],
) -> List[Union[SystemMessage, AIMessage, HumanMessage]]:
"""Merge runs of human/tool messages into single human messages with content blocks.""" # noqa: E501
merged: list = []
for curr in messages:
curr = curr.copy(deep=True)
if isinstance(curr, ToolMessage):
if isinstance(curr.content, str):
curr = HumanMessage(

@ -1,6 +1,6 @@
[tool.poetry]
name = "langchain-anthropic"
version = "0.1.10"
version = "0.1.11"
description = "An integration package connecting AnthropicMessages and LangChain"
authors = []
readme = "README.md"

@ -165,6 +165,25 @@ def test__merge_messages() -> None:
assert expected == actual
def test__merge_messages_mutation() -> None:
original_messages = [
HumanMessage([{"type": "text", "text": "bar"}]),
HumanMessage("next thing"),
]
messages = [
HumanMessage([{"type": "text", "text": "bar"}]),
HumanMessage("next thing"),
]
expected = [
HumanMessage(
[{"type": "text", "text": "bar"}, {"type": "text", "text": "next thing"}]
),
]
actual = _merge_messages(messages)
assert expected == actual
assert messages == original_messages
@pytest.fixture()
def pydantic() -> Type[BaseModel]:
class dummy_function(BaseModel):

Loading…
Cancel
Save