ShawnGarello commented on code in PR #1370:
URL: https://github.com/apache/flink-agents/pull/1370#discussion_r4663393997
##########
integrations/chat-models/gemini/src/main/java/org/apache/flink/agents/integrations/chatmodels/gemini/GeminiChatUtils.java:
##########
@@ -165,37 +167,37 @@ static Tool
convertTools(List<org.apache.flink.agents.api.tools.Tool> tools) {
}
/**
- * Converts a message to a Gemini turn. Only user messages can carry
media: image, audio, video
- * and document blocks become inline data (Base64) or file data (URL)
parts with the block's
- * media type. Media in an assistant message or a tool result throws {@link
- * UnsupportedContentBlockException}.
+ * Converts a message to a Gemini turn. Only user messages and tool
results can carry media:
+ * image, audio, video and document blocks become inline data (Base64) or
file data (URL) with
+ * the block's media type. A tool result's media become the parts of its
function response, in
+ * block order, and its text stays in the response's {@code result}. Media
in an assistant
+ * message throws {@link UnsupportedContentBlockException}.
*/
// Package-visible for unit testing of the message conversion.
static Content convertToContent(ChatMessage message, Map<String, String>
toolCallIdToName) {
if (message.getRole() == MessageRole.TOOL) {
ToolResultBlock result = (ToolResultBlock)
message.getBlocks().get(0);
- String text =
- result.getBlocks().stream()
- .map(
- block -> {
- if (block instanceof MediaBlock) {
- throw
mediaOutsideUserMessage(message, block);
- }
- if (!(block instanceof TextBlock)) {
- throw new IllegalArgumentException(
- "Gemini cannot send tool
result block "
- + block.getType());
- }
- return ((TextBlock) block).getText();
- })
- .collect(Collectors.joining());
+ List<FunctionResponsePart> media = new ArrayList<>();
+ for (DataContentBlock block : result.getBlocks()) {
+ if (block instanceof MediaBlock) {
Review Comment:
Done in f57d6289: tool results now accept only PNG/JPEG/WebP images and PDF
or plain-text documents, and reject audio, video and other types before the
request is sent. Tests and docs are updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]