mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-22 06:39:52 +00:00
fix: Handle response metadata in merge_messages_runs (#28453)
This commit is contained in:
parent
60021e54b5
commit
ecee41ab72
@ -556,6 +556,8 @@ def merge_message_runs(
|
||||
else:
|
||||
last_chunk = _msg_to_chunk(last)
|
||||
curr_chunk = _msg_to_chunk(curr)
|
||||
if curr_chunk.response_metadata:
|
||||
curr_chunk.response_metadata.clear()
|
||||
if (
|
||||
isinstance(last_chunk.content, str)
|
||||
and isinstance(curr_chunk.content, str)
|
||||
|
@ -59,6 +59,24 @@ def test_merge_message_runs_str_without_separator(
|
||||
assert messages == messages_model_copy
|
||||
|
||||
|
||||
def test_merge_message_runs_response_metadata() -> None:
|
||||
messages = [
|
||||
AIMessage("foo", id="1", response_metadata={"input_tokens": 1}),
|
||||
AIMessage("bar", id="2", response_metadata={"input_tokens": 2}),
|
||||
]
|
||||
expected = [
|
||||
AIMessage(
|
||||
"foo\nbar",
|
||||
id="1",
|
||||
response_metadata={"input_tokens": 1},
|
||||
)
|
||||
]
|
||||
actual = merge_message_runs(messages)
|
||||
assert actual == expected
|
||||
# Check it's not mutated
|
||||
assert messages[1].response_metadata == {"input_tokens": 2}
|
||||
|
||||
|
||||
def test_merge_message_runs_content() -> None:
|
||||
messages = [
|
||||
AIMessage("foo", id="1"),
|
||||
|
Loading…
Reference in New Issue
Block a user