generateTextAndImages method

Future<GeminiAIHttpResponse> generateTextAndImages({
  1. required String query,
  2. required String apiKey,
  3. required dynamic image,
  4. required GenerationConfig? config,
  5. required List<SafetySettings>? safetySettings,
  6. String model = 'gemini-pro-vision',
})

Implementation

Future<GeminiAIHttpResponse> generateTextAndImages({
  required String query,
  required String apiKey,
  required dynamic image,
  required GenerationConfig? config,
  required List<SafetySettings>? safetySettings,
  String model = 'gemini-pro-vision',
}) async {
  try {
    final response = await _dio.post(
      '${Constants.geminiAIEndpoint}/$model:generateContent',
      queryParameters: {'key': apiKey},
      data: {
        "contents": [
          {
            "parts": [
              {"text": query},
              {
                "inline_data": {"mime_type": "image/jpeg", "data": image}
              },
            ],
          }
        ],
        "safetySettings": _convertSafetySettings(safetySettings ?? []),
        "generationConfig": config?.toJson(),
      },
    );

    return GeminiAIHttpResponse.fromJson(response.data);
  } catch (error, s) {
    print("this is throwing an error in $s");
    throw _handleError(error);
  }
}