diff --git a/CHANGELOG.md b/CHANGELOG.md index dac382a..89e9c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -216,4 +216,7 @@ - Cancel a run # 3.0.2 - Fix bugs +## 3.0.3 + - Fix bugs + - Update Demo App \ No newline at end of file diff --git a/README.md b/README.md index 4d3fdd7..6723b10 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ supervised and reinforcement learning techniques. ## Install Package ```dart -chat_gpt_sdk: 3.0.2 +chat_gpt_sdk: 3.0.3 ``` ## Create OpenAI Instance diff --git a/lib/src/messages.dart b/lib/src/messages.dart index a28472c..67a3fc6 100644 --- a/lib/src/messages.dart +++ b/lib/src/messages.dart @@ -14,7 +14,7 @@ class Messages { : _client = client, _headers = headers; - Future createMessage({ + Future createMessage({ required String threadId, required CreateMessage request, }) { @@ -22,7 +22,7 @@ class Messages { _client.apiUrl + kThread + "/$threadId/$kMessages", request.toJson(), headers: _headers, - onSuccess: CreateMessageResponse.fromJson, + onSuccess: MessageData.fromJson, onCancel: (cancelData) => null, ); } @@ -34,13 +34,16 @@ class Messages { String? after, String? before, }) { - String url = after != null || before != null - ? _client.apiUrl + - kThread + - "/$threadId/$kMessages?limit=$limit&order=$order&after=$after&before=$before" - : _client.apiUrl + - kThread + - "/$threadId/$kMessages?limit=$limit&order=$order"; + String url = _client.apiUrl + + kThread + + "/$threadId/$kMessages?limit=$limit&order=$order"; + + if (before != null && before.isNotEmpty) { + url += '&before=$before'; + } + if (after != null && after.isNotEmpty) { + url += '&after=$after'; + } return _client.get( url, @@ -64,13 +67,16 @@ class Messages { String? after, String? before, }) { - String url = after != null || before != null - ? _client.apiUrl + - kThread + - "/$threadId/$kMessages/$messageId/$kFile?limit=$limit&order=$order&after=$after&before=$before" - : _client.apiUrl + - kThread + - "/$threadId/$kMessages/$messageId/$kFile?limit=$limit&order=$order"; + String url = _client.apiUrl + + kThread + + "/$threadId/$kMessages/$messageId/$kFile?limit=$limit&order=$order"; + + if (before != null && before.isNotEmpty) { + url += '&before=$before'; + } + if (after != null && after.isNotEmpty) { + url += '&after=$after'; + } return _client.get( url, diff --git a/lib/src/model/message/response/message_data.dart b/lib/src/model/message/response/message_data.dart index 37e5e3c..f2a8272 100644 --- a/lib/src/model/message/response/message_data.dart +++ b/lib/src/model/message/response/message_data.dart @@ -10,6 +10,8 @@ class MessageData { required this.id, required this.content, required this.object, + required this.assistantId, + required this.runId, }); String threadId; @@ -20,6 +22,8 @@ class MessageData { String id; List content; String object; + String assistantId; + String runId; factory MessageData.fromJson(Map json) => MessageData( threadId: json["thread_id"] ?? '', @@ -36,6 +40,8 @@ class MessageData { json["content"].map((x) => Content.fromJson(x)), ), object: json["object"] ?? '', + assistantId: json['assistant_id'] ?? '', + runId: json['run_id'] ?? '', ); Map toJson() => { @@ -47,5 +53,7 @@ class MessageData { "id": id, "content": content.map((x) => x.toJson()).toList(), "object": object, + 'assistant_id': assistantId, + 'run_id': runId, }; } diff --git a/lib/src/runs.dart b/lib/src/runs.dart index 4c4abcb..4971de5 100644 --- a/lib/src/runs.dart +++ b/lib/src/runs.dart @@ -50,13 +50,16 @@ class Runs { String? after, String? before, }) { - String url = after != null || before != null - ? _client.apiUrl + - kThread + - "/$threadId/$kRuns?limit=$limit&order=$order&after=$after&before=$before" - : _client.apiUrl + - kThread + - "/$threadId/$kRuns?limit=$limit&order=$order"; + String url = _client.apiUrl + + kThread + + "/$threadId/$kRuns?limit=$limit&order=$order"; + + if (before != null && before.isNotEmpty) { + url += '&before=$before'; + } + if (after != null && after.isNotEmpty) { + url += '&after=$after'; + } return _client.get( url, @@ -74,13 +77,16 @@ class Runs { String? after, String? before, }) { - String url = after != null || before != null - ? _client.apiUrl + - kThread + - "/$threadId/$kRuns/$runId/steps?limit=$limit&order=$order&after=$after&before=$before" - : _client.apiUrl + - kThread + - "/$threadId/$kRuns/$runId/steps?limit=$limit&order=$order"; + String url = _client.apiUrl + + kThread + + "/$threadId/$kRuns/$runId/steps?limit=$limit&order=$order"; + + if (before != null && before.isNotEmpty) { + url += '&before=$before'; + } + if (after != null && after.isNotEmpty) { + url += '&after=$after'; + } return _client.get( url, diff --git a/pubspec.yaml b/pubspec.yaml index 7119001..7fb0755 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ 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: 3.0.2 +version: 3.0.3 homepage: https://www.facebook.com/REDEVRX repository: https://github.com/redevRx/Flutter-ChatGPT