hello
i am using chat/completions api in project but i am not getting any response form api. All time error come
Exception: Error: DioException [bad response]: The request returned an invalid status code of 429.
api - v1/chat/completions
{
'model': model,
'messages': [
{
'role': 'system',
'content': 'You have to give concise and short answers'
},
{
'role': 'user',
'content': [
{
'type': 'text',
'text':
'GPT, your task is to identify plant health issues with precision. Analyze any image of a plant or leaf I provide, and detect all abnormal conditions, whether they are diseases, pests, deficiencies, or decay. Respond strictly with the name of the condition identified, and nothing else—no explanations, no additional text. If a condition is unrecognizable, reply with \'I don\'t know\'. If the image is not plant-related, say \'Please pick another image\'',
},
{
'type': 'image_url',
'image_url': {
'url': 'data:image/jpeg;base64,$base64Image',
},
},
],
},
],
'max_tokens': maxTokens,
}
hello
i want to detect plant issue using the api but it is not give me right solution.
please help me.
I am using below api calling to getting solution.
Future sendImageToGPT4Vision({
required File image,
int maxTokens = 300,
String model = “gpt-4-turbo”,
}) async
{
final String base64Image = await encodeImage(image);
try {
final response = await _dio.post(
"$BASE_URL/chat/completions",
options: Options(
headers: {
HttpHeaders.authorizationHeader: 'Bearer $API_KEY',
HttpHeaders.contentTypeHeader: "application/json",
},
),
data: jsonEncode({
'model': model,
'messages': [
{
'role': 'system',
'content': 'You have to give concise and short answers'
},
{
'role': 'user',
'content': 'GPT, your task is to identify plant health issues with precision. Analyze the image provided and detect any plant conditions. Respond only with the name of the condition identified. If a condition is unrecognizable, reply "I don\'t know". If the image is not plant-related, say "Please pick another image".'
},
{
'role': 'user',
'content': 'data:image/jpg;base64,$base64Image'
}
],
'max_tokens': maxTokens,
}),
);
final jsonResponse = response.data;
if (jsonResponse['error'] != null) {
throw HttpException(jsonResponse['error']["message"]);
}
return jsonResponse["choices"][0]["message"]["content"];
} catch (e) {
throw Exception('Error: $e');
}