listFiles method
Future<List<GptFile> >
listFiles({
- required String apiKey,
- required String organizationId,
- required ListFilesRequest request,
Returns a list of files that belong to the user's organization.
Implementation
Future<List<GptFile>> listFiles({
required String apiKey,
required String organizationId,
required ListFilesRequest request,
}) async {
Map<String, String> headers = {
"Authorization": "Bearer $apiKey",
"OpenAI-Organization": organizationId,
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*", // Required for CORS support to work
};
Uri endpoint;
if(secure) {
endpoint = Uri.https(
baseUrl, "/v1/files", request.toJson().toQueryParam());
}
else {
endpoint = Uri.http(
baseUrl, "v1/files",request.toJson().toQueryParam());
}
var response = await
http.get(endpoint, headers: headers);
if (response.statusCode == 200 || response.statusCode == 201) {
return GptList.fromJson(jsonDecode(const Utf8Decoder().convert(response.bodyBytes)), (json)=> GptFile.fromJson(json as Map<String, dynamic>)).data;
}
else {
var error = ServerError.fromJson(jsonDecode(response.body));
throw FilesException(statusCode: response.statusCode, message: error.message);
}
}