createMultimodalMessage static method
Message
createMultimodalMessage({
- required String text,
- required ProcessedImage processedImage,
- required ModelType modelType,
- bool isUser = true,
Creates a properly formatted message for multimodal AI models
Implementation
static Message createMultimodalMessage({
required String text,
required ProcessedImage processedImage,
required ModelType modelType,
bool isUser = true,
}) {
try {
gemmaLog(
'MultimodalImageHandler: Creating multimodal message for $modelType...');
// Validate inputs
if (text.isEmpty) {
throw ArgumentError('Text content cannot be empty');
}
if (processedImage.base64String.isEmpty) {
throw ArgumentError('Processed image Base64 string cannot be empty');
}
// Create the message with proper image handling
return Message.withImage(
text: text,
imageBytes: processedImage.processedBytes,
isUser: isUser,
);
} catch (e) {
gemmaLog(
'MultimodalImageHandler: Failed to create multimodal message - $e');
// Do NOT silently drop the image into a text-only message — that makes
// the model answer as if no image was sent. Surface the failure so the
// caller can react (no-silent-fallbacks).
rethrow;
}
}