mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-14 00:47:27 +00:00
anthropic[patch]: fix msg mutation (#20572)
This commit is contained in:
parent
719da8746e
commit
54e9271504
@ -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…
Reference in New Issue
Block a user