From 8dcfe877904eb53bd68b94aa08f6f0b73a66f65a Mon Sep 17 00:00:00 2001 From: "redev.rx" Date: Mon, 4 Mar 2024 12:19:37 +0700 Subject: [PATCH] Fix Thread Messages containing no content. #97 --- .flutter-plugins-dependencies | 2 +- .github/workflows/dart.yml | 2 +- example/pubspec.lock | 2 +- lib/src/messages.dart | 10 ++-------- lib/src/model/chat_complete/response/message.dart | 15 +++++++++++---- pubspec.yaml | 2 +- .../chat_complete/response/message_test.dart | 1 + 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index cb0fb63..1538f2b 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_android-2.2.2/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-02-28 08:03:33.229291","version":"3.19.1"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_android-2.2.2/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/redev.rx/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-03-04 12:19:00.387805","version":"3.19.2"} \ No newline at end of file diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 054f9e7..2afa66e 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -25,7 +25,7 @@ jobs: java-version: '11' - uses: subosito/flutter-action@v1 with: - flutter-version: '3.16.9' + flutter-version: '3.19.2' # - name: run analyze # run: flutter analyze diff --git a/example/pubspec.lock b/example/pubspec.lock index bf774c5..e8f39f3 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -31,7 +31,7 @@ packages: path: ".." relative: true source: path - version: "3.0.2" + version: "3.0.3" clock: dependency: transitive description: diff --git a/lib/src/messages.dart b/lib/src/messages.dart index 67a3fc6..26b56d9 100644 --- a/lib/src/messages.dart +++ b/lib/src/messages.dart @@ -27,7 +27,7 @@ class Messages { ); } - Future> listMessage({ + Future listMessage({ required String threadId, int limit = 20, String order = 'desc', @@ -48,13 +48,7 @@ class Messages { return _client.get( url, headers: _headers, - onSuccess: (it) => it['data'] == null - ? [] - : List.from( - it['data'].map( - (x) => CreateMessageResponse.fromJson(x), - ), - ), + onSuccess: CreateMessageResponse.fromJson, onCancel: (cancelData) => null, ); } diff --git a/lib/src/model/chat_complete/response/message.dart b/lib/src/model/chat_complete/response/message.dart index bc02ed6..9fa05a5 100644 --- a/lib/src/model/chat_complete/response/message.dart +++ b/lib/src/model/chat_complete/response/message.dart @@ -5,15 +5,22 @@ class Message { final Map? functionCall; final List>? toolCalls; - Message({required this.role, required this.content, this.functionCall, this.toolCalls}); + Message({ + required this.role, + required this.content, + this.functionCall, + this.toolCalls, + }); factory Message.fromJson(Map json) => Message( role: json["role"] ?? "", content: json["content"] ?? "", functionCall: json["function_call"], - toolCalls: json['tool_calls'] == null ? null : List>.from( - json["tool_calls"].map((x) => Map.from(x)), - ), + toolCalls: json['tool_calls'] == null + ? null + : List>.from( + json["tool_calls"].map((x) => Map.from(x)), + ), ); Map toJson() => { diff --git a/pubspec.yaml b/pubspec.yaml index 7fb0755..b005e22 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://www.facebook.com/REDEVRX repository: https://github.com/redevRx/Flutter-ChatGPT environment: - sdk: '>=3.2.6 <4.0.0' + sdk: '>=3.3.0 <4.0.0' dependencies: dio: ^5.4.0 diff --git a/test/model/chat_complete/response/message_test.dart b/test/model/chat_complete/response/message_test.dart index 5a8dfa8..5e1c6df 100644 --- a/test/model/chat_complete/response/message_test.dart +++ b/test/model/chat_complete/response/message_test.dart @@ -9,6 +9,7 @@ void main() { 'role': 'sender', 'content': 'Hello, world!', 'function_call': null, + 'tool_calls': null, }); });