Skip to content

Commit

Permalink
fig bug chunks error
Browse files Browse the repository at this point in the history
  • Loading branch information
redevrx committed Nov 9, 2023
1 parent 54a8472 commit 844dcd1
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 32 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,7 @@
- listFineTuneJob
- retrieveFineTuneJob
- cancelFineTuneJob
- cancelFineTuneJobStream
- cancelFineTuneJobStream

## 2.2.6
- Fix Bug Chunks error
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ supervised and reinforcement learning techniques.

## Install Package
```dart
chat_gpt_sdk: 2.2.5
chat_gpt_sdk: 2.2.6
```

## Create OpenAI Instance
Expand Down
28 changes: 14 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.2.5"
version: "2.2.6"
clock:
dependency: transitive
description:
Expand All @@ -52,10 +52,10 @@ packages:
dependency: transitive
description:
name: cross_file
sha256: fd832b5384d0d6da4f6df60b854d33accaaeb63aa9e10e736a87381f08dee2cb
sha256: "445db18de832dba8d851e287aff8ccf169bed30d2e94243cb54c7d2f1ed2142c"
url: "https://pub.dev"
source: hosted
version: "0.3.3+5"
version: "0.3.3+6"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -68,10 +68,10 @@ packages:
dependency: transitive
description:
name: dio
sha256: ce75a1b40947fea0a0e16ce73337122a86762e38b982e1ccb909daa3b9bc4197
sha256: "417e2a6f9d83ab396ec38ff4ea5da6c254da71e4db765ad737a42af6930140b7"
url: "https://pub.dev"
source: hosted
version: "5.3.2"
version: "5.3.3"
fake_async:
dependency: transitive
description:
Expand All @@ -92,10 +92,10 @@ packages:
dependency: transitive
description:
name: file_selector_macos
sha256: "182c3f8350cee659f7b115e956047ee3dc672a96665883a545e81581b9a82c72"
sha256: b15c3da8bd4908b9918111fa486903f5808e388b8d1c559949f584725a6594d6
url: "https://pub.dev"
source: hosted
version: "0.9.3+2"
version: "0.9.3+3"
file_selector_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -129,10 +129,10 @@ packages:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: f185ac890306b5779ecbd611f52502d8d4d63d27703ef73161ca0407e815f02c
sha256: b068ffc46f82a55844acfa4fdbb61fad72fa2aef0905548419d97f0f95c456da
url: "https://pub.dev"
source: hosted
version: "2.0.16"
version: "2.0.17"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -171,10 +171,10 @@ packages:
dependency: transitive
description:
name: image_picker_android
sha256: d32a997bcc4ee135aebca8e272b7c517927aa65a74b9c60a81a2764ef1a0462d
sha256: d6a6e78821086b0b737009b09363018309bbc6de3fd88cc5c26bc2bb44a4957f
url: "https://pub.dev"
source: hosted
version: "0.8.7+5"
version: "0.8.8+2"
image_picker_for_web:
dependency: transitive
description:
Expand All @@ -187,10 +187,10 @@ packages:
dependency: transitive
description:
name: image_picker_ios
sha256: c5538cacefacac733c724be7484377923b476216ad1ead35a0d2eadcdc0fc497
sha256: "76ec722aeea419d03aa915c2c96bf5b47214b053899088c9abb4086ceecf97a7"
url: "https://pub.dev"
source: hosted
version: "0.8.8+2"
version: "0.8.8+4"
image_picker_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -373,5 +373,5 @@ packages:
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.1.0 <4.0.0"
dart: ">=3.1.5 <4.0.0"
flutter: ">=3.7.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0

environment:
sdk: '>=3.1.0 <4.0.0'
sdk: '>=3.1.5 <4.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
4 changes: 2 additions & 2 deletions example_app/openai_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ packages:
path: "../.."
relative: true
source: path
version: "2.2.4"
version: "2.2.5"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -557,5 +557,5 @@ packages:
source: hosted
version: "1.0.0"
sdks:
dart: ">=3.1.0 <4.0.0"
dart: ">=3.1.5 <4.0.0"
flutter: ">=3.3.0"
2 changes: 1 addition & 1 deletion example_app/openai_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.1+4

environment:
sdk: '>=3.1.0 <4.0.0'
sdk: '>=3.1.5 <4.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
26 changes: 17 additions & 9 deletions lib/src/client/openai_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class OpenAIClient extends OpenAIWrapper {
}) {
final controller = StreamController<T>.broadcast();
final cancelData = CancelData(cancelToken: CancelToken());

final List<int> chunks = [];
onCancel(cancelData);

log.log("starting request");
Expand All @@ -86,7 +86,10 @@ class OpenAIClient extends OpenAIWrapper {
(it) {
(it.data.stream as Stream).listen(
(it) {
final rawData = utf8.decode(it);
chunks.addAll(it);
},
onDone: () {
final rawData = utf8.decode(chunks);

final dataList = rawData
.split("\n")
Expand All @@ -105,12 +108,11 @@ class OpenAIClient extends OpenAIWrapper {
controller
..sink
..add(onSuccess(json.decode(data)));

controller.close();
}
}
},
onDone: () {
controller.close();
},
onError: (err, t) {
log.error(err, t);
controller
Expand Down Expand Up @@ -241,6 +243,8 @@ class OpenAIClient extends OpenAIWrapper {
log.log("request body :$request");
final controller = StreamController<T>.broadcast();
final cancelData = CancelData(cancelToken: CancelToken());
final List<int> chunks = [];

try {
onCancel(cancelData);
_dio
Expand All @@ -254,7 +258,10 @@ class OpenAIClient extends OpenAIWrapper {
(it) {
it.data.stream.listen(
(it) {
final raw = utf8.decode(it);
chunks.addAll(it);
},
onDone: () {
final raw = utf8.decode(chunks);
final dataList = raw
.split("\n")
.where((element) => element.isNotEmpty)
Expand All @@ -276,16 +283,17 @@ class OpenAIClient extends OpenAIWrapper {
controller
..sink
..add(complete(jsonMap[jsonMap.keys.last]));

controller.close();
} else {
log.log("stream response invalid try regenerate");
log.log("last json error :$mData");

controller.close();
}
}
}
},
onDone: () {
controller.close();
},
onError: (err, t) {
log.error(err, t);
if (err is DioException) {
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: chat_gpt_sdk
description: create chat bot and other bot with ChatGPT SDK Support GPT-4 , 3.5 and SSE Generate Prompt (Stream)
version: 2.2.5
version: 2.2.6
homepage: https://www.facebook.com/REDEVRX
repository: https://github.com/redevRx/Flutter-ChatGPT

environment:
sdk: '>=3.1.0 <4.0.0'
sdk: '>=3.1.5 <4.0.0'

dependencies:
dio: ^5.2.1+1
dio: ^5.3.3
http_parser: ^4.0.2

dev_dependencies:
Expand Down

0 comments on commit 844dcd1

Please sign in to comment.