From 5ac0d1f67b4eed2d39d69c82a59ab835d04b968c Mon Sep 17 00:00:00 2001 From: Maxime Perrin <63123596+maximeperrindev@users.noreply.github.com> Date: Sat, 6 Apr 2024 02:22:14 +0200 Subject: [PATCH] partners[anthropic]: fix anthropic chat model message type lookup keys (#19034) - **Description:** Fixing message formatting issue in ChatAnthropic model by adding dictionary keys for `AIMessageChunk `and `HumanMessageChunk` - **Issue:** #19025 - **Twitter handle:** @maximeperrin_ Co-authored-by: Maxime Perrin Co-authored-by: Erick Friis --- libs/partners/anthropic/langchain_anthropic/chat_models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.py index 6b2aa154e01..ef09aa37995 100644 --- a/libs/partners/anthropic/langchain_anthropic/chat_models.py +++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py @@ -56,7 +56,12 @@ from langchain_core.utils.function_calling import convert_to_openai_tool from langchain_anthropic.output_parsers import ToolsOutputParser -_message_type_lookups = {"human": "user", "ai": "assistant"} +_message_type_lookups = { + "human": "user", + "ai": "assistant", + "AIMessageChunk": "assistant", + "HumanMessageChunk": "user", +} def _format_image(image_url: str) -> Dict: