11/21/1
This commit is contained in:
34
lib/controller/functions/llama_ai.dart
Normal file
34
lib/controller/functions/llama_ai.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user