File tree Expand file tree Collapse file tree 3 files changed +12
-5
lines changed Expand file tree Collapse file tree 3 files changed +12
-5
lines changed Original file line number Diff line number Diff line change
1
+ ## 0.0.6
2
+
3
+ * Handle parsing case where stream response has multiple chunks in byte stream
4
+
1
5
## 0.0.5
2
6
3
7
* Use substring instead of replaceFirst for parsing stream response
Original file line number Diff line number Diff line change @@ -103,17 +103,20 @@ class ChatGPTClient {
103
103
104
104
var responseText = "" ;
105
105
await for (final byte in byteStream) {
106
- var decoded = utf8.decode (byte).trim ();
107
- if (decoded.startsWith ("data: " ) && ! decoded.endsWith ("[DONE]" )) {
108
- decoded = decoded.substring (6 );
109
- final map = jsonDecode (decoded) as Map ;
106
+ var decoded = utf8.decode (byte);
107
+ final strings = decoded.split ("data: " );
108
+ for (final string in strings) {
109
+ final trimmedString = string.trim ();
110
+ if (trimmedString.isNotEmpty && ! trimmedString.endsWith ("[DONE]" )) {
111
+ final map = jsonDecode (trimmedString) as Map ;
110
112
final choices = map["choices" ] as List ;
111
113
final delta = choices[0 ]["delta" ] as Map ;
112
114
if (delta["content" ] != null ) {
113
115
final content = delta["content" ] as String ;
114
116
responseText += content;
115
117
yield content;
116
118
}
119
+ }
117
120
}
118
121
}
119
122
Original file line number Diff line number Diff line change 1
1
name : chatgpt_client
2
2
description : ChatGPT API Client for Dart
3
- version : 0.0.5
3
+ version : 0.0.6
4
4
homepage : https://github.com/alfianlosari/chatgpt_api_dart
5
5
6
6
environment :
You can’t perform that action at this time.
0 commit comments