complete method
Completes a user prompt.
Implementation
@override
Future<Completion?> complete(String prompt) async {
final url = Uri.parse("https://api.openai.com/v1/chat/completions");
_getMessages(prompt);
final data = {
"model": model,
"tools": tools,
"messages": _getMessages(prompt)
};
final headers = {
"Content-Type": "application/json",
"Authorization": "Bearer $apiKey"
};
final response =
await http.post(url, body: jsonEncode(data), headers: headers);
if (response.statusCode != 200) {
throw Exception('Error: ${response.body}');
}
final result = Completion.fromJson(response.body);
updateTool(result);
return result;
}