addQueryChunk method

  1. @override
Future<void> addQueryChunk(
  1. Message message
)
override

Implementation

@override
Future<void> addQueryChunk(Message message) async {
  if (kDebugMode) {
    print('🟒 WebModelSession.addQueryChunk() called - hasImage: ${message.hasImage}, supportImage: $supportImage');
  }

  final finalPrompt = message.transformToChatPrompt(type: modelType, fileType: fileType);

  // Add text part
  _promptParts.add(TextPromptPart(finalPrompt));
  if (kDebugMode) {
    print('🟒 Added text part: ${finalPrompt.substring(0, math.min(100, finalPrompt.length))}...');
  }

  // Handle image processing for web
  if (message.hasImage && message.imageBytes != null) {
    if (kDebugMode) {
      print('🟒 Processing image: ${message.imageBytes!.length} bytes');
    }
    if (!supportImage) {
      if (kDebugMode) {
        print('πŸ”΄ Model does not support images - throwing exception');
      }
      throw Exception('This model does not support images');
    }
    // Add image part
    final imagePart = ImagePromptPart.fromBytes(message.imageBytes!);
    _promptParts.add(imagePart);
    if (kDebugMode) {
      print('🟒 Added image part with dataUrl length: ${imagePart.dataUrl.length}');
    }
  }

  if (kDebugMode) {
    print('🟒 Total prompt parts: ${_promptParts.length}');
  }
}