LlamaMessage.fromMap constructor
Creates a LlamaMessage instance from a map.
The map should contain a 'role' key with one of the following values:
- 'user': to create a UserLlamaMessage
- 'assistant': to create an AssistantLlamaMessage
- 'system': to create a SystemLlamaMessage
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');
}
}