mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
community[patch]: support convert FunctionMessage for Tongyi (#23569)
**Description:** For function call agent with Tongyi, cause the AgentAction will be converted to FunctionMessage by47f69fe0d8/libs/core/langchain_core/agents.py (L188)
But now Tongyi's *convert_message_to_dict* doesn't support FunctionMessage47f69fe0d8/libs/community/langchain_community/chat_models/tongyi.py (L184-L207)
Then next round conversation will be failed by the *TypeError* exception. This patch adds the support to convert FunctionMessage for Tongyi. **Issue:** N/A **Dependencies:** N/A
This commit is contained in:
parent
d45ece0e58
commit
70834cd741
@ -32,6 +32,7 @@ from langchain_core.messages import (
|
||||
BaseMessageChunk,
|
||||
ChatMessage,
|
||||
ChatMessageChunk,
|
||||
FunctionMessage,
|
||||
HumanMessage,
|
||||
HumanMessageChunk,
|
||||
SystemMessage,
|
||||
@ -202,6 +203,13 @@ def convert_message_to_dict(message: BaseMessage) -> dict:
|
||||
"content": message.content,
|
||||
"name": message.name,
|
||||
}
|
||||
elif isinstance(message, FunctionMessage):
|
||||
message_dict = {
|
||||
"role": "tool",
|
||||
"tool_call_id": "",
|
||||
"content": message.content,
|
||||
"name": message.name,
|
||||
}
|
||||
else:
|
||||
raise TypeError(f"Got unknown type {message}")
|
||||
return message_dict
|
||||
|
@ -1,5 +1,6 @@
|
||||
from langchain_core.messages import (
|
||||
AIMessage,
|
||||
FunctionMessage,
|
||||
HumanMessage,
|
||||
SystemMessage,
|
||||
)
|
||||
@ -83,3 +84,15 @@ def test__convert_message_to_dict_system() -> None:
|
||||
result = convert_message_to_dict(message)
|
||||
expected_output = {"role": "system", "content": "foo"}
|
||||
assert result == expected_output
|
||||
|
||||
|
||||
def test__convert_message_to_dict_tool() -> None:
|
||||
message = FunctionMessage(name="foo", content="bar")
|
||||
result = convert_message_to_dict(message)
|
||||
expected_output = {
|
||||
"role": "tool",
|
||||
"tool_call_id": "",
|
||||
"content": "bar",
|
||||
"name": "foo",
|
||||
}
|
||||
assert result == expected_output
|
||||
|
Loading…
Reference in New Issue
Block a user