mirror of
https://github.com/hwchase17/langchain
synced 2024-11-18 09:25:54 +00:00
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.
This commit is contained in:
parent
08be477c24
commit
5d05df4bce
@ -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…
Reference in New Issue
Block a user