setPrompt method

void setPrompt(
  1. List<Map<String, dynamic>> messages
)

Set the prompt to be processed by the model. The prompt will be formatted according to the selected format.

This unified method automatically detects if any message contains 'media_data' and routes to the appropriate internal API:

  • If media_data is present: uses SetMultimodalPrompt (requires projector to be loaded)
  • If no media_data: uses SetPrompt (text-only path)

messages must be a list of maps with the following properties:

  • 'role' (String): The role (e.g., "system", "user", "assistant")
  • 'content' (String): The text content of the message
  • 'media_data' (List<Map<String, dynamic>>, optional): Media attachments, each containing:
    • 'media_type' (String): Type of media (e.g., "image")
    • 'file_path' (String): Path to the media file
    • 'width' (int, optional): Media width in pixels
    • 'height' (int, optional): Media height in pixels

Throws an Exception if media_data is provided but multimodal projector is not loaded. Call openMultimodalProjectorFile() first in that case.

Implementation

void setPrompt(List<Map<String, dynamic>> messages) {
  if (pLLm == nullptr) {
    throw Exception("ailia LLM not initialized.");
  }

  bool hasMedia = _hasMediaData(messages);

  // If media_data exists, check that the multimodal projector is loaded
  if (hasMedia) {
    if (!_multimodalProjectorOpened) {
      throw Exception(
          "media_data was provided but multimodal projector is not loaded. "
          "Call openMultimodalProjectorFile() first to enable multimodal generation.");
    }
    // Use multimodal path
    _setMultimodalPromptInternal(messages);
  } else {
    // Use text-only path
    _setTextPromptInternal(messages);
  }
}