ChatMessage.fromMap constructor
Creates a ChatMessage instance from a map.
The map should contain a 'role' key with one of the following values:
- 'user': to create a UserChatMessage
- 'assistant': to create an AssistantChatMessage
- 'system': to create a SystemChatMessage
The map should also contain a 'content' key with the message content.
Throws an Exception if the 'role' value is invalid.
Implementation
factory ChatMessage.fromMap(Map<String, dynamic> map) {
switch (map['role']) {
case 'user':
return UserChatMessage(map['content']);
case 'assistant':
return AssistantChatMessage(map['content']);
case 'system':
return SystemChatMessage(map['content']);
default:
throw Exception('Invalid role');
}
}