Skip to content

fix(google-common): Handle multiple function calls and complex parts/generations #7706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 21, 2025

Conversation

afirstenberg
Copy link
Contributor

Cleanup responseToChatGenerations() so it is more readable.
The combineGenerations() function has much of its work, but also splits things up so that content, text, toolCalls, and kwargs are now combined in a more reasonable way.

The previous implementation only handled cases where there was one function call and there was no text content along with it. And it did it in a huge loop over all the parts that was difficult to untangle.
These changes clean things up, separate some of the logic so it is clearer what is going on, and handles multiple parts better. It also sets things up so future changes can handle new part types easier.

Fixes #7705

The combineGenerations() function has much of its work, but also splits things up so that content, text, toolCalls, and kwargs are now combined in a more reasonable way.
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 17, 2025
Copy link

vercel bot commented Feb 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Feb 21, 2025 0:51am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Feb 21, 2025 0:51am


gen.forEach((item: ChatGeneration) => {
const message: AIMessageChunk = item?.message as AIMessageChunk;
ret.tool_calls!.push(...(message?.tool_calls ?? []));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really what we want to do vs. just chunks?

Will each item have unique tool calls?

We do have a concat method internally that handles this:

import { concat } from "@langchain/core/utils/stream";

const combinedChunk = concat(chunk1, chunk2);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is (although I've changed it to use concat(). Certainly this seems to be at least part of the issue that was reported.

I've added a comment to make it more clear that the AIMessageChunk isn't really the objective here - it is just a convenient object to carry all the tool calling related arrays.

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! See comments

@afirstenberg
Copy link
Contributor Author

Thank you! See comments

And thank you for reviewing! Hopefully these three updates address all the issues.

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all of this! Will cut a minor release of everything later tonight

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Feb 21, 2025
@jacoblee93 jacoblee93 merged commit fe01840 into langchain-ai:main Feb 21, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm PRs that are ready to be merged as-is size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gemini Flash 2 not making function calls In Langgraphjs
2 participants