chatAsk method
Send a chat-style list of messages to the model and return the text.
Implementation
Future<String> chatAsk(
List<Map<String, String>> messages, {
double temperature = 0.2,
}) async {
final payload = buildChatPayload(messages, temperature);
final uri = Uri.parse(
'https://generativelanguage.googleapis.com/v1beta2/${model}:generateText',
);
final resp = await http.post(
uri,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $apiKey',
},
body: jsonEncode(payload),
);
if (resp.statusCode != 200) {
throw Exception('Request failed: ${resp.statusCode} ${resp.body}');
}
return _extractText(resp.body);
}