davsclaus commented on code in PR #27886:
URL: https://github.com/apache/camel/pull/27886#discussion_r4281060308
##########
components/camel-ai/camel-typesafe-ai/src/main/java/org/apache/camel/component/typesafeai/TypeSafeAiJson.java:
##########
@@ -187,6 +189,45 @@ private static void jsonValue(Object value) {
}
}
+ private static boolean mediaPart(Map<?, ?> map) {
+ // A discriminator and payload identify a media part; ordinary field
names and text do not.
+ if (map.get("type") instanceof String type) {
+ boolean media = switch (type.toLowerCase(Locale.ROOT)) {
+ case "image", "image_url", "input_image", "audio",
"audio_url", "input_audio",
+ "video", "video_url", "input_video", "input_file",
"binary" ->
+ true;
+ case "file", "document" -> map.containsKey("file_id") ||
map.containsKey("file_data")
+ || map.containsKey("file_url") ||
map.containsKey("file") || map.containsKey("bytes")
+ || fileSource(map.get("source"));
+ default -> false;
+ };
+ if (media && (map.containsKey("source") || map.containsKey("data")
|| map.containsKey("url")
Review Comment:
With `type` set to `image`, `audio`, `video` or `binary`, any `url`, `data`
or `source` key makes the map a media part. So ordinary application records are
rejected too, for example a product `{type: "image", url:
"https://shop/p/42.jpg", sku: 42}` or a CMS item `{type: "video", url: "...",
title: "..."}`. The provider only ever got those as JSON text. The docs accept
`{type: document, url: ..., source: legal}`, but these records are just as
ordinary.
If the aim is to stop users assuming that an image is evaluated, a narrower
rule would avoid this: reject the `$semanticInput` envelope, data URLs, the
provider content-part types (`image_url`, `input_image`, `input_audio`, ...)
with their payload, and byte payloads, but not a generic `type` plus `url`.
--
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]