community: Fixed bug of "system message check" in chat_models/tongyi. (#15631)

- **Description:** This PR is to fix a bug of "system message check" in
langchain_community/ chat_models/tongyi.py
- **Issue:** In term of current logic, if there's no system message in
the chat messages, an error of "System message can only be the first
message." will be wrongly raised.
  - **Dependencies:** No.
  - **Twitter handle:** I don't have a Twitter account.
pull/15544/head^2
Kai 9 months ago committed by GitHub
parent 08be477c24
commit 5d05df4bce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

Loading…
Cancel
Save