generateText method
Future<GeminiAIHttpResponse>
generateText({
- required String query,
- required String apiKey,
- required GenerationConfig? config,
- required List<
SafetySettings> ? safetySettings, - String model = 'gemini-pro',
Implementation
Future<GeminiAIHttpResponse> generateText({
required String query,
required String apiKey,
required GenerationConfig? config,
required List<SafetySettings>? safetySettings,
String model = 'gemini-pro',
}) async {
try {
final response = await _dio.post(
'${Constants.geminiAIEndpoint}/$model:generateContent',
queryParameters: {'key': apiKey},
data: {
"contents": [
{
"parts": [
{"text": query}
]
}
],
"safetySettings": _convertSafetySettings(safetySettings ?? []),
"generationConfig": config?.toJson(),
},
);
return GeminiAIHttpResponse.fromJson(response.data);
} catch (error) {
throw _handleError(error);
}
}