postChatStream<T> static method
Implementation
static Stream<T> postChatStream<T>({
required String fullPath,
required String apiKey,
required T Function(ChatStreamResponse) onSuccess,
required T Function(String) onError,
required Map<String, dynamic> body,
}) {
final controller = StreamController<T>();
final uri = Uri.parse(fullPath);
final headers = {
'apiKey': apiKey,
'Content-Type': 'application/json',
};
_streamingHttpClient()
.send(http.Request('POST', uri)
..headers.addAll(headers)
..body = jsonEncode(body))
.then((response) {
readStream(response.stream, controller, onSuccess, onError);
}).catchError((error) {
onError(error.toString());
});
return controller.stream;
}