langchain/libs/core/langchain_core/messages
Jacob Lee c01467b1f4
core[patch]: RFC: Allow concatenation of messages with multi part content (#22002)
Anthropic's streaming treats tool calls as different content parts
(streamed back with a different index) from normal content in the
`content`.

This means that we need to update our chunk-merging logic to handle
chunks with multi-part content. The alternative is coerceing Anthropic's
responses into a string, but we generally like to preserve model
provider responses faithfully when we can. This will also likely be
useful for multimodal outputs in the future.

This current PR does unfortunately make `index` a magic field within
content parts, but Anthropic and OpenAI both use it at the moment to
determine order anyway. To avoid cases where we have content arrays with
holes and to simplify the logic, I've also restricted merging to chunks
in order.

TODO: tests

CC @baskaryan @ccurme @efriis
2024-06-03 09:46:40 -07:00
..
__init__.py core[patch]: Fix imports defined in messages sub-package (#20500) 2024-04-16 14:19:51 +00:00
ai.py core, partners: add token usage attribute to AIMessage (#21944) 2024-05-23 14:21:58 -04:00
base.py core[patch]: RFC: Allow concatenation of messages with multi part content (#22002) 2024-06-03 09:46:40 -07:00
chat.py core: Assign missing message ids in BaseChatModel (#19863) 2024-04-02 01:18:36 +00:00
function.py core: Assign missing message ids in BaseChatModel (#19863) 2024-04-02 01:18:36 +00:00
human.py infra: rm unused # noqa violations (#22049) 2024-05-22 15:21:08 -07:00
system.py infra: rm unused # noqa violations (#22049) 2024-05-22 15:21:08 -07:00
tool.py remove placeholder error message (#20340) 2024-04-26 13:48:48 +00:00
utils.py core[patch]: Fixes for convert_messages (#21207) 2024-05-02 16:55:42 +00:00