Closed liye199033 closed 10 months ago
🤖
Hello,
Thank you for reaching out. The error you're encountering is due to the _convert_message_to_dict
function in the ErnieBotChat
class. This function is designed to convert a message object into a dictionary, but it only knows how to handle instances of ChatMessage
, HumanMessage
, and AIMessage
. If it receives an instance of any other type, it raises a ValueError.
The error message you're seeing indicates that the function received a tuple with two elements: 'content'
and '请列出清朝的所有皇帝的姓名和年号'
. This is not an instance of any of the three types the function knows how to handle, so it raises a ValueError.
To fix this issue, you need to ensure that the _convert_message_to_dict
function is only ever called with instances of ChatMessage
, HumanMessage
, or AIMessage
. Check the part of your code where you're calling this function, and make sure you're not accidentally passing in a tuple instead of a message object.
Here is the relevant part of the 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
And here is where it's being used:
payload = {
"messages": [_convert_message_to_dict(m) for m in messages],
"top_p": self.top_p,
"temperature": self.temperature,
"penalty_score": self.penalty_score,
**kwargs,
}
The expected type of the messages
parameter in the generate
method of the ErnieBotChat
class in the LangChain codebase is List[BaseMessage]
. This is evident from the method signature:
def _generate(
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> ChatResult:
Here, messages: List[BaseMessage]
indicates that messages
should be a list of instances of the BaseMessage
class.
I hope this helps! If you have any other questions, feel free to ask.
Best, Dosu
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.
Thank you. See what the problem is
Issue you'd like to raise.
my test code
it's return error:
in ernie.py file function _convert_message_to_dict,the variable message is of type tuple。
Suggestion:
No response