feat(core): support DataBlock in all provider message converters#1933
Open
Buktal wants to merge 2 commits into
Open
feat(core): support DataBlock in all provider message converters#1933Buktal wants to merge 2 commits into
Buktal wants to merge 2 commits into
Conversation
- Add optional mimeType field to URLSource for extension-less URLs - Add convertDataBlockToContentPart to DashScopeMediaConverter - Add DataBlock branch to DashScopeMessageConverter (multimodal path and hasMediaContent) - Add convertToInlineDataPart(DataBlock) to GeminiMediaConverter - Add DataBlock branch to GeminiMessageConverter; fix extractSourceFromBlock - Add convertDataBlock to AnthropicMediaConverter (image modality) - Add DataBlock branch to AnthropicMessageConverter - Add DataBlock branch to OpenAIMessageConverter (image/audio/video routing) - Add resolveMimeType utility to OpenAIConverterUtils Closes agentscope-ai#1932
- Remove validateImageExtension in AnthropicMediaConverter.convertDataBlock: mimeType is already verified as image/* before the URL branch, so the extension check would break extension-less CDN URLs with a mimeType hint - Replace lastIndexOf-based extension extraction in GeminiMediaConverter with MediaUtils.getExtension to correctly handle signed URLs with query-string dots - Remove dead validateExtension parameter from DashScopeMediaConverter.sourceToUrl - Add DataBlock branch to AbstractBaseFormatter (hasMediaContent, convertToolResultToString, getSourceFromBlock) — affects all providers - Add DataBlock branch to GeminiConversationMerger (multi-agent history merge) - Add DataBlock unit tests to DashScopeMediaConverterTest, AnthropicMediaConverterTest, and GeminiMediaConverterTest
Contributor
|
Good addition! Supporting DataBlock in all provider formatters ensures consistent handling across providers. The hasMediaContent check and convertToolResultToString updates are thorough. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
1.0.12 (development)
Description
DataBlockis documented as the forward-looking unified container for all binary modalities (image / audio / video / file), replacing the legacyImageBlock/AudioBlock/VideoBlocksubclasses. However, none of the provider message converters handled it — when a user built a message withDataBlock, every provider silently dropped the block and the LLM received no media content.This PR fixes that gap.
Changes:
URLSource: Add optionalmimeTypefield for extension-less URLs (CDN signed URLs, API-generated media links). Backward-compatible — existing callers using the single-arg constructor or omittingmime_typein JSON are unaffected. MIME type resolution priority:Base64Source.mediaType>URLSource.mimeType> extension-based inference viaMediaUtils.determineMediaType.DashScope: Add
convertDataBlockToContentParttoDashScopeMediaConverter; addDataBlockbranch toDashScopeMessageConverter(bothconvertToMultimodalContentandhasMediaContent/convertContentBlocks).Gemini: Add
convertToInlineDataPart(DataBlock)toGeminiMediaConverter; addDataBlockbranch inGeminiMessageConverter; fixextractSourceFromBlockwhich previously threw onDataBlock.Anthropic: Add
convertDataBlocktoAnthropicMediaConverter(image-only — Anthropic SDK does not expose a generic binary content block param); addDataBlockbranch toAnthropicMessageConverter.OpenAI: Add
DataBlockbranch toOpenAIMessageConverter(routes to image / audio / video based on MIME prefix); addresolveMimeTypeutility toOpenAIConverterUtils.How to test:
Previously the image was silently dropped; now it is routed correctly to each provider's image slot.
For extension-less URLs:
Closes #1932
Checklist
mvn spotless:applymvn test)