Future sendMessage()

in pkgs/google_generative_ai/lib/src/chat.dart [66:82]


  Future<GenerateContentResponse> sendMessage(Content message) async {
    final lock = await _mutex.acquire();
    try {
      final response = await _generateContent(_history.followedBy([message]),
          safetySettings: _safetySettings, generationConfig: _generationConfig);
      if (response.candidates case [final candidate, ...]) {
        _history.add(message);
        final normalizedContent = candidate.content.role == null
            ? Content('model', candidate.content.parts)
            : candidate.content;
        _history.add(normalizedContent);
      }
      return response;
    } finally {
      lock.release();
    }
  }