Files
driver_tripz/lib/controller/functions/llama_ai.dart
Hamza-Ayed 027d248e56 12/24/1
2023-12-24 21:28:31 +03:00

40 lines
1.3 KiB
Dart

import 'dart:convert';
import 'package:ride/constant/links.dart';
import 'package:ride/controller/functions/crud.dart';
class LlamaAi {
Future<Map> getCarRegistrationData(String input) async {
print(true);
Map exrtatDataFinal = {};
String oneLine = input.replaceAll('\n', ' ');
// var res = await CRUD().getLlama(link: AppLink.gemini, payload: oneLine);
var res = await CRUD().getLlama(link: AppLink.llama, payload: oneLine);
var decod = jsonDecode(res);
// print(decod);
exrtatDataFinal = jsonDecode(
extractDataFromJsonString(decod['choices'][0]['message']['content']));
// print(jsonEncode(exrtatDataFinal));
print(false);
return exrtatDataFinal;
}
String extractDataFromJsonString(String jsonString) {
// Remove any leading or trailing whitespace from the string
jsonString = jsonString.trim();
// Extract the JSON substring from the given string
final startIndex = jsonString.indexOf('{');
final endIndex = jsonString.lastIndexOf('}');
final jsonSubstring = jsonString.substring(startIndex, endIndex + 1);
// Parse the JSON substring into a Map
final jsonData = jsonDecode(jsonSubstring);
// Return the extracted data
// print(jsonEncode(jsonData));
return jsonEncode(jsonData);
}
}