getModelById method
Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
Implementation
Future<GptModelDto> getModelById({
required String apiKey,
required String organizationId,
required String modelId,
}) 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/$modelId");
}
else {
endpoint = Uri.http(
baseUrl, "/v1/models/$modelId");
}
var response = await
http.get(endpoint, headers: headers);
if (response.statusCode == 200 || response.statusCode == 201) {
return GptModelDto.fromJson(jsonDecode(response.body));
}
else {
var error = ServerError.fromJson(jsonDecode(response.body));
throw ModelsException(statusCode: response.statusCode, message: error.message);
}
}