Closed estuday closed 8 months ago
🤖
Hello @estuday,
I'm Dosu, a bot designed to assist with issues related to the LangChain repository. I can help you troubleshoot bugs, answer questions, and guide you on becoming a contributor. While we wait for a human maintainer to join us, feel free to ask any questions you may have. I'm here to help!
Based on the information you've provided and the similar issues I found in the LangChain repository, it seems that not all models in the LangChain framework support the SystemMessage
feature out of the box. The SystemMessage
feature is part of the langchain_core.messages
module and can be used across different models and agents in the LangChain framework. However, each model may require specific handling for SystemMessage
types.
In your case, the ERNIE-Bot model is raising a TypeError
with the message "Got unknown type {message}". This error is raised in the _convert_message_to_dict
function when the message type is not one of the expected types (ChatMessage
, HumanMessage
, AIMessage
). Here is the relevant code:
def _convert_message_to_dict(message: BaseMessage) -> dict:
if isinstance(message, ChatMessage):
message_dict = {"role": message.role, "content": message.content}
elif isinstance(message, HumanMessage):
message_dict = {"role": "user", "content": message.content}
elif isinstance(message, AIMessage):
message_dict = {"role": "assistant", "content": message.content}
else:
raise ValueError(f"Got unknown type {message}")
return message_dict
To resolve this issue, you can modify the _convert_message_to_dict
function in your ERNIE-Bot model to handle SystemMessage
types. Here's an example of how you can do this:
def _convert_message_to_dict(message: BaseMessage) -> dict:
...
elif isinstance(message, SystemMessage):
message_dict = {"role": "system", "content": message.content}
else:
raise TypeError(f"Got unknown type {message}")
...
return message_dict
This code checks if the message is an instance of SystemMessage
. If it is, it creates a dictionary with the role set to "system" and the content set to the content of the message.
You can refer to the following solved issue for more details: chat_models.QianfanEndpoint Not Compatiable with SystemMessage
I hope this helps! If you have any other questions, feel free to ask.
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
System Info
None
Who can help?
No response
Information
Related Components
Reproduction
My chat model is ERNIE-Bot, running the following code reported an error: But after I removed SystemMessage it works fine. So I want to know, do all models support SystemMessage?
Expected behavior
None