-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class ThreadRequest { | ||
final List<Map<String, dynamic>>? messages; | ||
|
||
///Set of 16 key-value pairs that can be attached to an object. | ||
/// This can be useful for storing additional information about the | ||
/// object in a structured format. Keys can be a maximum of 64 | ||
/// characters long and values can be a maxium of 512 characters long. | ||
/// [metadata] | ||
final Map<String, dynamic>? metadata; | ||
|
||
ThreadRequest({this.messages, this.metadata}); | ||
|
||
Map<String, dynamic> toJson() => Map.of({ | ||
'messages': messages, | ||
'metadata': metadata, | ||
}) | ||
..removeWhere((_, value) => value == null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class ThreadDeleteResponse { | ||
ThreadDeleteResponse({ | ||
required this.deleted, | ||
required this.id, | ||
required this.object, | ||
}); | ||
|
||
bool deleted; | ||
String id; | ||
String object; | ||
|
||
factory ThreadDeleteResponse.fromJson(Map<String, dynamic> json) => | ||
ThreadDeleteResponse( | ||
deleted: json["deleted"] ?? false, | ||
id: json["id"] ?? '', | ||
object: json["object"] ?? '', | ||
); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"deleted": deleted, | ||
"id": id, | ||
"object": object, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class ThreadResponse { | ||
ThreadResponse({ | ||
required this.metadata, | ||
required this.createdAt, | ||
required this.id, | ||
required this.object, | ||
}); | ||
|
||
Map<String, dynamic> metadata; | ||
int createdAt; | ||
String id; | ||
String object; | ||
|
||
factory ThreadResponse.fromJson(Map<String, dynamic> json) => ThreadResponse( | ||
metadata: json["metadata"] ?? {}, | ||
createdAt: json["created_at"] ?? 0, | ||
id: json["id"] ?? '', | ||
object: json["object"] ?? '', | ||
); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"metadata": metadata, | ||
"created_at": createdAt, | ||
"id": id, | ||
"object": object, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'package:chat_gpt_sdk/src/client/openai_client.dart'; | ||
import 'package:chat_gpt_sdk/src/model/thread/request/thread_request.dart'; | ||
import 'package:chat_gpt_sdk/src/model/thread/response/thread_delete_response.dart'; | ||
import 'package:chat_gpt_sdk/src/model/thread/response/thread_response.dart'; | ||
import 'package:chat_gpt_sdk/src/utils/constants.dart'; | ||
|
||
class Threads { | ||
final OpenAIClient _client; | ||
|
||
Threads({required OpenAIClient client}) : _client = client; | ||
|
||
Map<String, String> _headers = {'OpenAI-Beta': 'assistants=v1'}; | ||
Map<String, String> get getHeader => _headers; | ||
|
||
void addHeader(Map<String, String> mHeader) { | ||
if (mHeader == {}) return; | ||
|
||
_headers.addAll(mHeader); | ||
} | ||
|
||
///Create a thread. | ||
/// [createThread] | ||
Future<ThreadResponse> createThread({ | ||
ThreadRequest? request, | ||
}) { | ||
return _client.post( | ||
_client.apiUrl + kThread, | ||
request == null ? {} : request.toJson(), | ||
headers: _headers, | ||
onSuccess: ThreadResponse.fromJson, | ||
onCancel: (cancelData) => null, | ||
); | ||
} | ||
|
||
///The ID of the thread to retrieve.[threadId] | ||
/// [retrieveThread] | ||
Future<ThreadResponse> retrieveThread({ | ||
required String threadId, | ||
}) { | ||
return _client.get( | ||
_client.apiUrl + kThread + "/$threadId", | ||
headers: _headers, | ||
onSuccess: ThreadResponse.fromJson, | ||
onCancel: (cancelData) => null, | ||
); | ||
} | ||
|
||
Future<ThreadResponse> modifyThread({ | ||
required String threadId, | ||
required Map<String, dynamic> metadata, | ||
}) { | ||
return _client.post( | ||
_client.apiUrl + kThread + "/$threadId", | ||
metadata, | ||
headers: _headers, | ||
onSuccess: ThreadResponse.fromJson, | ||
onCancel: (cancelData) => null, | ||
); | ||
} | ||
|
||
Future<ThreadDeleteResponse> deleteThread({ | ||
required String threadId, | ||
}) { | ||
return _client.delete( | ||
_client.apiUrl + kThread + "/$threadId", | ||
onSuccess: ThreadDeleteResponse.fromJson, | ||
onCancel: (cancelData) => null, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters