mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
community: re-arrange function call message parse logic for Qianfan (#27935)
the [PR](https://github.com/langchain-ai/langchain/pull/26208) two month ago has a potential bug which causes malfunction of `tool_call` for `QianfanChatEndpoint` waiting for fix
This commit is contained in:
parent
41b7a5169d
commit
395674d503
@ -66,17 +66,13 @@ def convert_message_to_dict(message: BaseMessage) -> dict:
|
||||
message_dict = {"role": "user", "content": message.content}
|
||||
elif isinstance(message, AIMessage):
|
||||
message_dict = {"role": "assistant", "content": message.content}
|
||||
if "function_call" in message.additional_kwargs:
|
||||
message_dict["function_call"] = message.additional_kwargs["function_call"]
|
||||
elif len(message.tool_calls) != 0:
|
||||
if len(message.tool_calls) != 0:
|
||||
tool_call = message.tool_calls[0]
|
||||
message_dict["function_call"] = {
|
||||
"name": tool_call["name"],
|
||||
"args": tool_call["args"],
|
||||
"arguments": json.dumps(tool_call["args"], ensure_ascii=False),
|
||||
}
|
||||
|
||||
# If function call only, content is None not empty string
|
||||
if "function_call" in message_dict and message_dict["content"] == "":
|
||||
# If function call only, content is None not empty string
|
||||
message_dict["content"] = None
|
||||
elif isinstance(message, (FunctionMessage, ToolMessage)):
|
||||
message_dict = {
|
||||
|
Loading…
Reference in New Issue
Block a user