Skip to content

Commit

Permalink
fix: fix stream text error
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwang committed Apr 2, 2023
1 parent 3875353 commit c17a711
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ void chatCompletionStsream(OpenaiClient client) {
model: Model.gpt3_5Turbo,
stream: true,
messages: [
ChatMessage(content: "hello", role: ChatMessageRole.user),
ChatMessage(
content: "Act as a golang runtime", role: ChatMessageRole.user),
],
),
onSuccess: (p0) {
// print(p0);
print(p0);
},
);
}
4 changes: 3 additions & 1 deletion lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class OpenaiClient {
if (e.startsWith(dataPrefix)) {
final result = e.split(dataPrefix);
if (result.length > 1) {
onSuccess?.call(jsonDecode(result[1]));
if (!result[1].contains('[DONE]')) {
onSuccess?.call(jsonDecode(result[1]));
}
}
} else {
final res = jsonDecode(e);
Expand Down

0 comments on commit c17a711

Please sign in to comment.