completionStream method
Method to do text completion based on the given
input prompt
request is a required parameter
the return type can be null
Implementation
Stream<Completion>? completionStream({
required CompletionRequest request,
}) {
String url = '$_baseUrl/completions';
try {
var promptRequest = request.toJson();
promptRequest.putIfAbsent('stream', () => true);
_dio
.post(
url,
data: promptRequest,
options: Options(
headers: _headers,
responseType: ResponseType.stream,
),
)
.then((value) {
_controller.sink.addStream(value.data.stream);
});
// stream.listen((rawString) {
// print(rawString);
// String data = utf8.decode(rawString.data);
// if (data.startsWith('data:')) {
// data = data.substring(6);
// if (data.startsWith('[DONE]')) {
// } else {
// Completion completion = Completion.fromMap(jsonDecode(data));
// _controller
// ..sink
// ..add(completion);
// }
// }
// });
return _controller.stream;
} on DioError {
return null;
}
}