This commit is contained in:
Hamza Aleghwairyeen
2024-04-26 18:23:45 +03:00
parent a9c570cab7
commit dcf02cc36d
22 changed files with 600 additions and 344 deletions

View File

@@ -158,6 +158,82 @@ class AI extends GetxController {
}
}
Future<void> geminiAiExtraction(String prompt, payload) async {
var requestBody = jsonEncode({
'contents': [
{
'parts': [
// {
// 'inlineData': {
// 'mimeType': 'image/jpeg',
// 'data': imageData,
// },
// },
{
'text':
"Extract the desired information from the following passage as json decoded like $prompt just in this:\n\n$payload"
},
],
},
],
'generationConfig': {
'temperature': 0.4,
'topK': 32,
'topP': 1,
'maxOutputTokens': 4096,
'stopSequences': [],
},
'safety_settings': [
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE"
},
]
});
print(requestBody);
final response = await http.post(
Uri.parse(
// 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision:generateContent?key=${AK.geminiApi}'),
'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=AIzaSyCyoLcSkDzK5_SMe00nhut56SSXWPR074w'),
headers: {'Content-Type': 'application/json'},
body: requestBody,
);
if (response.statusCode == 200) {
var responseData = jsonDecode(response.body);
// Process the responseData as needed
// print(responseData);
var result = responseData['candidates'][0]['content']['parts'][0]['text'];
// print(jsonEncode(result));
// print((result));
// print(result['dob']);
RegExp regex = RegExp(r"```json([^`]*)```");
String? jsonString =
regex.firstMatch(responseData.toString())?.group(1)?.trim();
if (jsonString != null) {
// Convert the JSON object to a String
jsonString = jsonEncode(json.decode(jsonString));
print(jsonString);
} else {
print("JSON string not found");
}
// Rest of your code...
} else {
print('Request failed with status: ${response.statusCode}');
print('Request failed with status: ${response.body}');
}
}
Future<void> getDriverLicenseJordanContent() async {
await pickImage();
isloading = true;