createMultimodalMessage static method

Message createMultimodalMessage({
  1. required String text,
  2. required ProcessedImage processedImage,
  3. required ModelType modelType,
  4. 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 {
    debugPrint('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) {
    debugPrint('MultimodalImageHandler: Failed to create multimodal message - $e');

    // Try to create a fallback text-only message
    final fallbackText = '$text\n[Note: Image could not be processed properly]';
    return Message.text(text: fallbackText, isUser: isUser);
  }
}