This commit is contained in:
zhutao
2025-09-05 18:00:26 +08:00
parent 70aa3e6ab6
commit 193d29b0ce
23 changed files with 1071 additions and 338 deletions

View File

@@ -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>