getModels method
Lists the currently available models, and provides basic information about each one such as the owner and availability.
Implementation
Future<List<GptModelDto>> getModels({
required String apiKey,
required String organizationId,
}) 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/models");
}
else {
endpoint = Uri.http(
baseUrl, "/v1/models");
}
var response = await
http.get(endpoint, headers: headers);
if (response.statusCode == 200 || response.statusCode == 201) {
return GptModelListDto.fromJson(jsonDecode(response.body)).data;
}
else {
var error = ServerError.fromJson(jsonDecode(response.body));
throw ModelsException(statusCode: response.statusCode, message: error.message);
}
}