Skip to content

Conversation

@michalwarda
Copy link
Contributor

When using streaming with tools in ChatGoogleAI I've noticed that the merge method in tool_calls duplicated the name of the function.

Because of that the tool calls were not working. For some reason ChatGoogleAI sends the same message delta with tools twice.

Below you can see that the name of the function was being duplicated: image_1__generate_image converted into image_1__generate_imageimage_1__generate_image.

primary: %LangChain.MessageDelta{
  content: nil,
  status: :complete,
  index: 0,
  role: :assistant,
  tool_calls: [
    %LangChain.Message.ToolCall{
      status: :incomplete,
      type: :function,
      call_id: "call-image_1__generate_image",
      name: "image_1__generate_image",
      arguments: %{"prompt" => "a dog"},
      index: nil
    }
  ]
}
delta call: %LangChain.Message.ToolCall{
  status: :incomplete,
  type: :function,
  call_id: "call-image_1__generate_image",
  name: "image_1__generate_image",
  arguments: %{"prompt" => "a dog"},
  index: nil
}
merged call: %LangChain.Message.ToolCall{
  status: :incomplete,
  type: :function,
  call_id: "call-image_1__generate_image",
  name: "image_1__generate_imageimage_1__generate_image",
  arguments: %{"prompt" => "a dog"},
  index: nil
}

I've introduced a fix that makes same messagedelta with tool call not duplicate

@brainlid
Copy link
Owner

brainlid commented Sep 6, 2024

Yeesh! Thanks @michalwarda for figuring that out.

❤️💛💙💜

@brainlid brainlid merged commit 3820a22 into brainlid:main Sep 6, 2024
brainlid added a commit that referenced this pull request Oct 28, 2024
* 'main' of github.com:brainlid/langchain:
  Add AWS Bedrock support to ChatAnthropic (#154)
  Handle functions with no parameters for Google AI (#183)
  Handle missing token usage fields for Google AI (#184)
  Handle empty text parts from GoogleAI responses (#181)
  Support system instructions for Google AI (#182)
  feat: add OpenAI's new structured output API (#180)
  Support strict mode for tools (#173)
  Do not duplicate tool call parameters if they are identical (#174)
  🐛 cast tool_calls arguments correctly inside message_deltas (#175)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants