1
This commit is contained in:
@@ -45,7 +45,7 @@ class StreamUtils {
|
||||
}
|
||||
//数据
|
||||
var bufferText = ""; //吐出来的内容
|
||||
|
||||
final completer = Completer<void>();
|
||||
//处理响应
|
||||
response.data?.stream
|
||||
.transform(_unit8Transformer())
|
||||
@@ -63,6 +63,9 @@ class StreamUtils {
|
||||
}
|
||||
Map<String, dynamic> dataJSON = jsonDecode(streamStr);
|
||||
//提取响应数据
|
||||
if (dataJSON['choices'].length == 0) {
|
||||
continue;
|
||||
}
|
||||
Map<String, dynamic> choices = dataJSON['choices'][0];
|
||||
//提取文字
|
||||
var word = choices['delta']['content'];
|
||||
@@ -80,12 +83,17 @@ class StreamUtils {
|
||||
},
|
||||
onDone: () {
|
||||
onEnd?.call();
|
||||
completer.complete();
|
||||
},
|
||||
onError: (error) {
|
||||
onError?.call();
|
||||
logger.e("流错误: $error");
|
||||
if (!completer.isCompleted) {
|
||||
completer.completeError(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/// 将Uint8List转换为List<int>
|
||||
|
||||
Reference in New Issue
Block a user