Skip to content

Commit

Permalink
fix bug issue Incorrect return type #96
Browse files Browse the repository at this point in the history
  • Loading branch information
redevrx committed Feb 28, 2024
1 parent f79c02f commit c4ce871
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,7 @@
- Cancel a run
# 3.0.2
- Fix bugs
## 3.0.3
- Fix bugs
- Update Demo App

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 22 additions & 16 deletions lib/src/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class Messages {
: _client = client,
_headers = headers;

Future<CreateMessageResponse> createMessage({
Future<MessageData> createMessage({
required String threadId,
required CreateMessage request,
}) {
return _client.post(
_client.apiUrl + kThread + "/$threadId/$kMessages",
request.toJson(),
headers: _headers,
onSuccess: CreateMessageResponse.fromJson,
onSuccess: MessageData.fromJson,
onCancel: (cancelData) => null,
);
}
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions lib/src/model/message/response/message_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class MessageData {
required this.id,
required this.content,
required this.object,
required this.assistantId,
required this.runId,
});

String threadId;
Expand All @@ -20,6 +22,8 @@ class MessageData {
String id;
List<Content> content;
String object;
String assistantId;
String runId;

factory MessageData.fromJson(Map<String, dynamic> json) => MessageData(
threadId: json["thread_id"] ?? '',
Expand All @@ -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<String, dynamic> toJson() => {
Expand All @@ -47,5 +53,7 @@ class MessageData {
"id": id,
"content": content.map((x) => x.toJson()).toList(),
"object": object,
'assistant_id': assistantId,
'run_id': runId,
};
}
34 changes: 20 additions & 14 deletions lib/src/runs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit c4ce871

Please sign in to comment.