buildChatPayload method
Build a chat-style payload from a list of messages (maps with 'author'/'content'). Ensures the system prompt is the first message.
Implementation
Map<String, dynamic> buildChatPayload(
List<Map<String, String>> messages,
double temperature,
) {
final msgs = <Map<String, String>>[];
// Ensure system prompt present as first message
if (messages.isEmpty || messages.first['author'] != 'system') {
msgs.add({'author': 'system', 'content': systemPrompt});
}
msgs.addAll(messages);
return {
'prompt': {'messages': msgs},
'temperature': temperature,
'maxOutputTokens': 800,
};
}