buildMessageJson static method
Build the JSON message for the Conversation API.
Format: {"role": "user", "content": [{"type": "text", "text": "..."}]}
Supports multiple images via imagesBytes list.
Implementation
static String buildMessageJson(
String text, {
List<Uint8List>? imagesBytes,
Uint8List? audioBytes,
}) {
final content = <Map<String, dynamic>>[];
if (imagesBytes != null) {
for (final imageBytes in imagesBytes) {
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});
}