Skip to content

Commit

Permalink
community: read function call from tool_calls for Qianfan (langchai…
Browse files Browse the repository at this point in the history
…n-ai#26208)

I added one more 'elif' to read tool call message from `tool_calls`

---------

Co-authored-by: Chester Curme <[email protected]>
  • Loading branch information
2 people authored and yanomaly committed Nov 8, 2024
1 parent 8ec8cd5 commit f91d3fe
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f91d3fe

Please sign in to comment.