LlamaMessage.fromMap constructor

LlamaMessage.fromMap(
  1. Map<String, dynamic> map
)

Creates a LlamaMessage instance from a map.

The map should contain a 'role' key with one of the following values:

The map should also contain a 'content' key with the message content.

Throws an Exception if the 'role' value is invalid.

Implementation

factory LlamaMessage.fromMap(Map<String, dynamic> map) {
  switch (map['role']) {
    case 'user':
      return UserLlamaMessage(map['content']);
    case 'assistant':
      return AssistantLlamaMessage(map['content']);
    case 'system':
      return SystemLlamaMessage(map['content']);
    default:
      throw Exception('Invalid role');
  }
}