35 lines
1.1 KiB
Dart
35 lines
1.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:ride/constant/links.dart';
|
|
import 'package:ride/controller/functions/crud.dart';
|
|
|
|
class LlamaAi {
|
|
Future getExractionData(String input) async {
|
|
print(true);
|
|
|
|
String oneLine = input.replaceAll('\n', ' ');
|
|
var res = await CRUD().getLlama(link: AppLink.llama, payload: oneLine);
|
|
var decod = jsonDecode(res);
|
|
// print(decod['choices'][0]['message']['content']);
|
|
extractDataFromJsonString(decod['choices'][0]['message']['content']);
|
|
print(false);
|
|
}
|
|
|
|
Map<String, dynamic> 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 = json.decode(jsonSubstring);
|
|
|
|
// Return the extracted data
|
|
print(jsonData);
|
|
return jsonData;
|
|
}
|
|
}
|