diff --git a/libs/community/langchain_community/chat_models/tongyi.py b/libs/community/langchain_community/chat_models/tongyi.py index ab2958d5c7..be4373a505 100644 --- a/libs/community/langchain_community/chat_models/tongyi.py +++ b/libs/community/langchain_community/chat_models/tongyi.py @@ -383,8 +383,10 @@ class ChatTongyi(BaseChatModel): system_message_indices = [ i for i, m in enumerate(message_dicts) if m["role"] == "system" ] - if len(system_message_indices) != 1 or system_message_indices[0] != 0: + if len(system_message_indices) == 1 and system_message_indices[0] != 0: raise ValueError("System message can only be the first message.") + elif len(system_message_indices) > 1: + raise ValueError("There can be only one system message at most.") params["messages"] = message_dicts