generateTextFromQueryAndImages method

Future<GeminiAIResponse> generateTextFromQueryAndImages({
  1. required String query,
  2. required File image,
})

Implementation

Future<GeminiAIResponse> generateTextFromQueryAndImages({
  required String query,
  required File image,
}) async {
  var convertedImage = FileConverter.convertIntoBase64(image);
  try {
    final httpResponse = await _geminiService.generateTextAndImages(
      query: query,
      apiKey: apiKey,
      image: convertedImage,
      config: config,
      safetySettings: safetySettings,
      model: Strings.geminiVisionModel,
    );

    final text = httpResponse.candidates
        .map((candidate) => candidate.content!['parts'])
        .expand((parts) => parts)
        .map((part) => part['text'])
        .join('');

    return GeminiAIResponse(text: text, response: httpResponse);
  } catch (error) {
    throw Exception('Error generating response: $error');
  }
}