From f7ced5b2110f404751ff77cb9e7b6946ed7b3283 Mon Sep 17 00:00:00 2001 From: Dobiichi-Origami <56953648+Dobiichi-Origami@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:33:32 +0800 Subject: [PATCH] community: read function call from `tool_calls` for Qianfan (#26208) I added one more 'elif' to read tool call message from `tool_calls` --------- Co-authored-by: Chester Curme --- .../chat_models/baidu_qianfan_endpoint.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/chat_models/baidu_qianfan_endpoint.py b/libs/community/langchain_community/chat_models/baidu_qianfan_endpoint.py index 741528d9152..93f32e9a83e 100644 --- a/libs/community/langchain_community/chat_models/baidu_qianfan_endpoint.py +++ b/libs/community/langchain_community/chat_models/baidu_qianfan_endpoint.py @@ -68,9 +68,16 @@ def convert_message_to_dict(message: BaseMessage) -> dict: message_dict = {"role": "assistant", "content": message.content} if "function_call" in message.additional_kwargs: message_dict["function_call"] = message.additional_kwargs["function_call"] - # If function call only, content is None not empty string - if message_dict["content"] == "": - message_dict["content"] = None + elif len(message.tool_calls) != 0: + tool_call = message.tool_calls[0] + message_dict["function_call"] = { + "name": tool_call["name"], + "args": tool_call["args"], + } + + # If function call only, content is None not empty string + if "function_call" in message_dict and message_dict["content"] == "": + message_dict["content"] = None elif isinstance(message, (FunctionMessage, ToolMessage)): message_dict = { "role": "function",