applyChatTemplate method

Future<ChatTemplateOutput> applyChatTemplate(
  1. List<ChatMessage> messages, {
  2. String? tools,
  3. bool enableThinking = false,
})

Apply chat template to format messages

Implementation

Future<ChatTemplateOutput> applyChatTemplate(
  List<ChatMessage> messages, {
  String? tools,
  bool enableThinking = false,
}) async {
  try {
    final result = await _channel.invokeMethod('applyChatTemplate', {
      'wrapperId': _wrapperId,
      'messages': messages.map((m) => m.toMap()).toList(),
      if (tools != null) 'tools': tools,
      'enableThinking': enableThinking,
    });
    return ChatTemplateOutput.fromMap(Map<String, dynamic>.from(result as Map));
  } on PlatformException catch (e) {
    throw Exception('Failed to apply chat template: ${e.message}');
  }
}