prependUserContext function
Prepend user context as a system-reminder message.
Implementation
List<Map<String, dynamic>> prependUserContext({
required List<Map<String, dynamic>> messages,
required Map<String, String> context,
}) {
if (context.isEmpty) return messages;
final contextStr = context.entries
.map((e) => '# ${e.key}\n${e.value}')
.join('\n');
final reminderMessage = <String, dynamic>{
'type': 'user',
'content':
'<system-reminder>\nAs you answer the user\'s questions, you can use '
'the following context:\n$contextStr\n\n'
' IMPORTANT: this context may or may not be relevant to your '
'tasks. You should not respond to this context unless it is highly '
'relevant to your task.\n</system-reminder>\n',
'isMeta': true,
};
return [reminderMessage, ...messages];
}