sendMessage method
Sends a message to the conversation and returns the response.
Implementation
Future<Message> sendMessage(
Message message, {
Map<String, Object?>? extraContext,
}) async {
final handle = _handle;
if (handle == null) {
throw const LiteRtLmException('Conversation is already disposed.');
}
final extraContextJson = extraContext == null || extraContext.isEmpty
? null
: jsonEncode(extraContext);
var currentMessage = message;
for (var round = 0; round < _recurringToolCallLimit; round += 1) {
final response = await LiteRtLmNativeRuntime.instance.sendMessage(
handle,
currentMessage.toJsonString(),
extraContextJson: extraContextJson,
);
if (!_automaticToolCalling || response.toolCalls.isEmpty) {
return response;
}
currentMessage = await _handleToolCalls(response.toolCalls);
}
throw const LiteRtLmException(
'Recurring tool call limit exceeded: $_recurringToolCallLimit.',
);
}