generateTextFromQuery method

Future<GeminiAIResponse> generateTextFromQuery(
  1. String query
)

Implementation

Future<GeminiAIResponse> generateTextFromQuery(String query) async {
  try {
    final httpResponse = await _geminiService.generateText(
      query: query,
      apiKey: apiKey,
      config: config,
      safetySettings: safetySettings,
      model: Strings.geminiTextModel,
    );

    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('Failure generating text: $error');
  }
}