fetchStream method
Stream<String>
fetchStream({
- int retries = 2,
- FutureOr<
void> onError(- CompletionException error,
- int retriesRemaning
- void onJsonComplete()?,
override
Implementation
@override
Stream<String> fetchStream({
int retries = 2,
FutureOr<void> Function(CompletionException error, int retriesRemaning)?
onError,
void Function(Map<String, dynamic> chunk)? onJsonComplete,
}) async* {
var response = await dio.post(
url,
data: {
'model': model.toString(),
'messages': messages,
'stream': true,
},
options: Options(
responseType: ResponseType.stream,
),
);
// Fetches the content of the message
var stream = getJsonStreamFromResponse(response);
await for (var json in stream) {
if (onJsonComplete != null) onJsonComplete(json);
var content = readMessageChunk(json);
if (content != null) {
yield content;
}
}
}