-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(gemini): support image conversion when content coerced to content… #9279
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
base: main
Are you sure you want to change the base?
Conversation
… blocks by setting output_version = v1
|
christian-bromann
left a comment
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 @yt20chill for the contribution. Can we have unit tests for this to ensure we don't regress?
|
@christian-bromann I am sorry that I am pretty new to this repo and I can't even run the unit tests using pnpm. I got this error on both It will be very helpful if you could point me to some solutions. Meanwhile, I have duplicate all the unit tests for testing image_url cases and change the type from |
|
No worries at all. I think the problem here is that we haven't ported to Vitest for all Google packages as we are in the process of migrating them all into a single package in #9374, maybe worth double checking if this fix is correctly applied there too. In terms of test execution you can run standalone package tests via: pnpm --filter @langchain/google-common testIf I run this in current main I get: Can you share some more information about the issue? |
|
What I experienced in my current project is that after I migrate langchain to v1 and set the lc_output_version to v1. By setting the output version to v1, the message.content becomes the same type as contentBlocks which I like it more because it's standardized for all model providers, not just for openai. But then for gemini model, I got a parser error saying "image is not supported". When I look into the gemini part converting function, it is still using deprecated MessageContent and thus doesn't have the type: image case. So in this PR, I added a case to handle the standardize image block. I know it's a workaround but before langchain migrates everything to parsing contentBlocks, I think it might still be helpful to patch this. I hope I explain the issue better. |
… blocks by setting output_version = v1
Fixes # (issue)
Right now when LC_OUTPUT_VERSION=v1 is set, content will be mapped to ContentBlock[] (https://docs.langchain.com/oss/javascript/migrate/langchain-v1#standard-content)
However, in the current
gemini.tsfile, content type is still deprecatedMessageContent, causingContentBlock.Multimodal.Imagecannot be converted toGeminiPartand throws unrecognized type error.This fix only take care of the
{type: "image", url: string}block because it's the only one I used in my project and I lack knowledge about all types. A thorough fix will require passing the standardized contentBlocks instead of content to those mapping functions.I have tested the fix in my project by directly changing the gemini.js file in dependency and it convert the block correctly for gemini to see the attached image.