mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-08 22:42:05 +00:00
core[patch]: Treat type as a special field when merging lists (#22750)
Should we even log a warning? At least for Anthropic, it's expected to get e.g. `text_block` followed by `text_delta`. @ccurme @baskaryan @efriis
This commit is contained in:
@@ -203,6 +203,35 @@ def test_complex_ai_message_chunks() -> None:
|
||||
)
|
||||
), "Concatenating when both content arrays are dicts with separate indexes should not merge" # noqa: E501
|
||||
|
||||
assert (
|
||||
AIMessageChunk(content=[{"index": 0, "text": "I am", "type": "text_block"}])
|
||||
+ AIMessageChunk(
|
||||
content=[{"index": 0, "text": " indeed.", "type": "text_block"}]
|
||||
)
|
||||
== AIMessageChunk(
|
||||
content=[{"index": 0, "text": "I am indeed.", "type": "text_block"}]
|
||||
)
|
||||
), "Concatenating when both content arrays are dicts with the same index and type should merge" # noqa: E501
|
||||
|
||||
assert (
|
||||
AIMessageChunk(content=[{"index": 0, "text": "I am", "type": "text_block"}])
|
||||
+ AIMessageChunk(
|
||||
content=[{"index": 0, "text": " indeed.", "type": "text_block_delta"}]
|
||||
)
|
||||
== AIMessageChunk(
|
||||
content=[{"index": 0, "text": "I am indeed.", "type": "text_block"}]
|
||||
)
|
||||
), "Concatenating when both content arrays are dicts with the same index and different types should merge without updating type" # noqa: E501
|
||||
|
||||
assert (
|
||||
AIMessageChunk(content=[{"index": 0, "text": "I am", "type": "text_block"}])
|
||||
+ AIMessageChunk(content="", response_metadata={"extra": "value"})
|
||||
== AIMessageChunk(
|
||||
content=[{"index": 0, "text": "I am", "type": "text_block"}],
|
||||
response_metadata={"extra": "value"},
|
||||
)
|
||||
), "Concatenating when one content is an array and one is an empty string should not add a new item, but should concat other fields" # noqa: E501
|
||||
|
||||
|
||||
def test_function_message_chunks() -> None:
|
||||
assert FunctionMessageChunk(
|
||||
|
Reference in New Issue
Block a user