-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
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 latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
||
gen.forEach((item: ChatGeneration) => { | ||
const message: AIMessageChunk = item?.message as AIMessageChunk; | ||
ret.tool_calls!.push(...(message?.tool_calls ?? [])); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this 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
…en't implemented by Google now).
And thank you for reviewing! Hopefully these three updates address all the issues. |
There was a problem hiding this 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
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