buildMessageJson static method

String buildMessageJson(
  1. String text, {
  2. Uint8List? imageBytes,
  3. Uint8List? audioBytes,
})

Build the JSON message for the Conversation API.

Format: {"role": "user", "content": [{"type": "text", "text": "..."}]}

Implementation

static String buildMessageJson(String text,
    {Uint8List? imageBytes, Uint8List? audioBytes}) {
  final content = <Map<String, dynamic>>[];
  if (imageBytes != null) {
    content.add({
      'type': 'image',
      'blob': base64Encode(imageBytes),
    });
  }
  if (audioBytes != null) {
    content.add({
      'type': 'audio',
      'blob': base64Encode(audioBytes),
    });
  }
  content.add({'type': 'text', 'text': text});
  return jsonEncode({'role': 'user', 'content': content});
}