diff --git a/libs/langchain/langchain/chains/conversational_retrieval/base.py b/libs/langchain/langchain/chains/conversational_retrieval/base.py index ec6c80502e..b35f93167f 100644 --- a/libs/langchain/langchain/chains/conversational_retrieval/base.py +++ b/libs/langchain/langchain/chains/conversational_retrieval/base.py @@ -42,8 +42,11 @@ def _get_chat_history(chat_history: List[CHAT_TURN_TYPE]) -> str: buffer = "" for dialogue_turn in chat_history: if isinstance(dialogue_turn, BaseMessage): - role_prefix = _ROLE_MAP.get(dialogue_turn.type, f"{dialogue_turn.type}: ") - buffer += f"\n{role_prefix}{dialogue_turn.content}" + if len(dialogue_turn.content) > 0: + role_prefix = _ROLE_MAP.get( + dialogue_turn.type, f"{dialogue_turn.type}: " + ) + buffer += f"\n{role_prefix}{dialogue_turn.content}" elif isinstance(dialogue_turn, tuple): human = "Human: " + dialogue_turn[0] ai = "Assistant: " + dialogue_turn[1]