createChat method

Future<Completion> createChat({
  1. required List<Message> messages,
  2. String? model,
  3. Map<String, dynamic>? options,
})

Implementation

Future<Completion> createChat(
    {required List<Message> messages,
    String? model,
    Map<String, dynamic>? options}) async {
  final res = await http.post(
    Uri.parse('$baseUrl/chat/completions'),
    headers: _headers..['Content-Type'] = 'application/json',
    body: jsonEncode({
      'messages': messages.map((e) => e.toMap()).toList(),
      'model': model ?? Models.chat.name,
      ...?options,
    }),
  );

  if (res.statusCode != 200) {
    throw DeepSeekException.fromBody(res.body, res.statusCode);
  }
  // make sure the response is utf8
  return Completion(utf8.decode(res.bodyBytes));
}