Skip to content

Commit

Permalink
Merge pull request #58 from biyidev/fix/stream-mode-error-handling
Browse files Browse the repository at this point in the history
[ Fix ] fixed stream mode can't handle error
  • Loading branch information
anasfik authored Jun 8, 2023
2 parents 8a6c7f5 + 81cdfd0 commit 6862f7d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/src/core/networking/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,11 @@ abstract class OpenAINetworkingClient {
.transform(utf8.decoder)
.transform(openAIChatStreamLineSplitter);

String respondData = "";
stream.listen(
(value) {
final data = value;
respondData += data;

final dataLines = data
.split("\n")
Expand All @@ -300,7 +302,10 @@ abstract class OpenAINetworkingClient {
continue;
}

final decodedData = decodeToMap(data);
Map<String, dynamic> decodedData = {};
try {
decodedData = decodeToMap(respondData);
} catch (error) {/** ignore, data has not been received */}

if (doesErrorExists(decodedData)) {
final error = decodedData[OpenAIStrings.errorFieldKey]
Expand Down

0 comments on commit 6862f7d

Please sign in to comment.