fix(provider/google): support multimodal tool-result parts in function responses#12777
Conversation
|
Hey @GidianB, I've looked over this issue myself, and I have a question regarding the |
|
@R-Taneja I'm facing something similar, currently solving locally with |
felixarntz
left a comment
There was a problem hiding this comment.
@GidianB Thank you for this! Overall the logic looks great, but we need to continue supporting existing non-Gemini 3 models.
I'm pushing a few changes, mostly to refresh against recent example restructuring, plus reinstating the deleted example, plus also having those examples for streamText.
With those examples, you should be able to test the logic in support of the older Gemini models too. Could you please update the PR?
packages/google/src/convert-to-google-generative-ai-messages.ts
Outdated
Show resolved
Hide resolved
examples/ai-functions/src/generate-text/google/image-tool-result-base64.ts
Show resolved
Hide resolved
| const parsedDataUrl = parseBase64DataUrl(url); | ||
| if (parsedDataUrl == null) { | ||
| throw new UnsupportedFunctionalityError({ | ||
| functionality: `URL-based ${type} tool result parts are not supported. Use image-data/file-data or base64 data URLs.`, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Technically, this would not have caused an error before, so let's think about whether this is the best path forward.
Before, the URL would have just been passed to the model, as a URL. It probably wouldn't have been able to do anything with it, so that's also not a great situation either way. But maybe it's better to still do pass the URL in this case, rather than throw an error.
I think we should include a warning in this case (via warnings), rather than throw. Curious what you think @lgrammel
There was a problem hiding this comment.
I reverted this to the pre-error behavior for now: no throw and no warning, just fallback to the legacy text/JSON representation until we get more guidance.
According to https://ai.google.dev/api/caching#FunctionResponsePart, this is not supported; it says that only inline base64 files can be used. Now of course it might be that the documentation is incomplete, but we need a way to verify. Could you share more context on how exactly you solved it locally? code snippets or a full example would be helpful. |
|
Hey @felixarntz First off thanks for taking this on! it will help us a lot!
maybe its only on vertex models. Locally I called the vertex api directly, with some fake message history that links to a gcs file uri. This is was a file uri in tool response, but I also tried out in a model message (less useful IMO but still worked) |
|
@felixarntz I updated the PR to preserve the legacy tool-result conversion path for pre-Gemini 3 models, while keeping multimodal I also reverted the non- Verified with:
|
felixarntz
left a comment
There was a problem hiding this comment.
@GidianB Looks great, thanks for restoring the old functionality so that now all Gemini models should work!
I broke the logic into two separate functions to reduce complexity a bit, and tested thoroughly, including a temporary local change for testing the "file data" part documented on Vertex. But it didn't work, neither for Gemini API nor with Vertex API:
- Gemini API doesn't error, but clearly doesn't process the file
- Vertex API errors that it cannot download the image - probably only works with certain Google-owned URLs
I added examples covering these use-cases already, which currently fail. But I think it's a good idea to keep them in here, so we can hopefully make them pass in the future - potentially with Vertex only. Anyway, that's better as a separate follow up PR. Please feel free to work on it if you're interested!
|
|
…in function responses (#13684) This is an automated backport of #12777 to the release-v6.0 branch. FYI @GidianB ~~This backport has conflicts that need to be resolved manually.~~ Conflicts resolved. ### `git cherry-pick` output ``` Auto-merging packages/google/src/convert-to-google-generative-ai-messages.test.ts Auto-merging packages/google/src/convert-to-google-generative-ai-messages.ts CONFLICT (content): Merge conflict in packages/google/src/convert-to-google-generative-ai-messages.ts Auto-merging packages/google/src/google-generative-ai-language-model.ts error: could not apply 18c1970... fix(provider/google): support multimodal tool-result parts in function responses (#12777) hint: After resolving the conflicts, mark them with hint: "git add/rm <pathspec>", then run hint: "git cherry-pick --continue". hint: You can instead skip this commit with "git cherry-pick --skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick --abort". hint: Disable this message with "git config set advice.mergeConflict false" ``` --------- Co-authored-by: Gidian <gidianbateman@gmail.com> Co-authored-by: Felix Arntz <felix.arntz@vercel.com>
|
🚀 Published in:
|
Background
Google provider tool results with
output.type = 'content'were not fully mapped into GeminifunctionResponse.parts, which blocked reliable multimodal tool-result flows for images/files.Summary
This PR adds multimodal tool-result support for
@ai-sdk/googlefunction responses and documents provider limitations.Provider changes
Updated
packages/google/src/convert-to-google-generative-ai-messages.tsto:image-dataandfile-datatool-result parts intofunctionResponse.partsasinlineData.image-url,file-url) only when they are base64data:URLs.UnsupportedFunctionalityErrorfor remote HTTP(S) URL-style tool-result parts.Updated
packages/google/src/google-generative-ai-prompt.tstypes to allow:functionResponse.partswith inline media payloads.Tests
packages/google/src/convert-to-google-generative-ai-messages.test.tsfor:image-datamappingfile-datamappingimage-urlbase64data:URL mappingimage-urlfile-urlDocs
content/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx:data:URLs (remote HTTP(S) URLs are not supported).Examples
examples/ai-functions/src/generate-text/google-image-tool-result-base64.tsexamples/ai-functions/src/generate-text/google-image-tool-result-url.tsexamples/ai-functions/src/generate-text/google-pdf-tool-results-base64.tsexamples/ai-functions/src/generate-text/google-pdf-tool-results-url.tsexamples/ai-functions/src/generate-text/google-image-tool-results.tsChangeset
.changeset/google-multimodal-tool-results.md(patch for@ai-sdk/google).Manual Verification
pnpm --filter @ai-sdk/google test:node -- convert-to-google-generative-ai-messages.test.tspnpm --filter @ai-sdk/google type-checkpnpm --filter @example/ai-functions type-checkpnpm exec eslint ...pnpm exec prettier --check ...Checklist
pnpm changesetin the project root)Future Work
Related Issues
N/A