Adoird build migration and update
This commit is contained in:
parent
04f034971f
commit
7a5c8721dd
1062 changed files with 143083 additions and 221 deletions
|
|
@ -9,9 +9,19 @@ import 'package:go_router/go_router.dart';
|
|||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_hive/hive_registrar.g.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/appointment.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_employee.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/loyalty_card.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
|
||||
import 'package:pwa_install/pwa_install.dart';
|
||||
import 'mih_config/mih_env.dart';
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
import 'package:hive_ce_flutter/hive_ce_flutter.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
||||
|
|
@ -21,10 +31,41 @@ void main() async {
|
|||
apiDomain: AppEnviroment.baseApiUrl,
|
||||
apiBasePath: "/auth",
|
||||
);
|
||||
// Offine Hive Data
|
||||
await Hive.initFlutter('mih_offline_storage');
|
||||
Hive.registerAdapters();
|
||||
// Mzansi Profile Data
|
||||
await Hive.openBox<AppUser>('user_box');
|
||||
await Hive.openBox<Business>('business_box');
|
||||
await Hive.openBox<BusinessUser>('business_user_box');
|
||||
await Hive.openBox<UserConsent>('user_consent_box');
|
||||
await Hive.openBox<String>('image_urls_box');
|
||||
await Hive.openBox<ProfileLink>('personal_profile_links_box');
|
||||
await Hive.openBox<ProfileLink>('business_profile_links_box');
|
||||
await Hive.openBox<BusinessEmployee>('business_employees_box');
|
||||
// Mzansi Wallet Data
|
||||
await Hive.openBox<MIHLoyaltyCard>('loyalty_card_box');
|
||||
await Hive.openBox<MIHLoyaltyCard>('fav_loyalty_card_box');
|
||||
await Hive.openBox<Map>('wallet_modifications_queue');
|
||||
// About MIH Data
|
||||
await Hive.openBox<int>('about_mih_box');
|
||||
// Mih Calendar Data
|
||||
await Hive.openBox<Appointment>('personal_calendar_box');
|
||||
await Hive.openBox<Appointment>('business_calendar_box');
|
||||
|
||||
// await Firebase.initializeApp(
|
||||
// options: DefaultFirebaseOptions.currentPlatform,
|
||||
// // options: DefaultFirebaseOptions.currentPlatform,
|
||||
// options: (Platform.isLinux)
|
||||
// ? DefaultFirebaseOptions.web // Forces Linux to use the Web config
|
||||
// : DefaultFirebaseOptions.currentPlatform,
|
||||
// );
|
||||
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
|
||||
const List<String> testDeviceIds = ['733d4c68-9b54-453a-9622-2df407310f40'];
|
||||
MobileAds.instance.updateRequestConfiguration(
|
||||
RequestConfiguration(
|
||||
testDeviceIds: testDeviceIds,
|
||||
),
|
||||
);
|
||||
MobileAds.instance.initialize();
|
||||
} else {
|
||||
usePathUrlStrategy();
|
||||
|
|
@ -33,7 +74,7 @@ void main() async {
|
|||
debugPrint('APP INSTALLED!');
|
||||
});
|
||||
final GoRouter appRouter = MihGoRouter().mihRouter;
|
||||
(MzansiInnovationHub(
|
||||
runApp(MzansiInnovationHub(
|
||||
router: appRouter,
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,8 +129,7 @@ class _MihCircleAvatarState extends State<MihCircleAvatar> {
|
|||
),
|
||||
onPressed: () async {
|
||||
try {
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles(
|
||||
FilePickerResult? result = await FilePicker.pickFiles(
|
||||
type: FileType.image,
|
||||
);
|
||||
// print("Here 1");
|
||||
|
|
|
|||
|
|
@ -98,8 +98,7 @@ class _MihImageDisplayState extends State<MihImageDisplay> {
|
|||
color: MihColors.primary(),
|
||||
onPressed: () async {
|
||||
try {
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles(
|
||||
FilePickerResult? result = await FilePicker.pickFiles(
|
||||
type: FileType.image,
|
||||
);
|
||||
// print("Here 1");
|
||||
|
|
|
|||
|
|
@ -75,14 +75,13 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
|
|||
} else if (defaultTargetPlatform == TargetPlatform.linux ||
|
||||
defaultTargetPlatform == TargetPlatform.windows) {
|
||||
// Use File Picker to get a save path on Desktop
|
||||
String? outputFile = await FilePicker.platform.saveFile(
|
||||
String? outputFile = await FilePicker.saveFile(
|
||||
dialogTitle: 'Please select where to save your QR Code:',
|
||||
fileName: filename,
|
||||
bytes: imageBytes,
|
||||
);
|
||||
|
||||
if (outputFile != null) {
|
||||
final file = File(outputFile);
|
||||
await file.writeAsBytes(imageBytes);
|
||||
KenLogger.success("Saved to $outputFile");
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:io';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:file_saver/file_saver.dart';
|
||||
|
|
@ -75,13 +74,14 @@ class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
|
|||
} else if (defaultTargetPlatform == TargetPlatform.linux ||
|
||||
defaultTargetPlatform == TargetPlatform.windows) {
|
||||
// Use File Picker to get a save path on Desktop
|
||||
String? outputFile = await FilePicker.platform.saveFile(
|
||||
String? outputFile = await FilePicker.saveFile(
|
||||
dialogTitle: 'Please select where to save your QR Code:',
|
||||
fileName: filename,
|
||||
bytes: imageBytes,
|
||||
);
|
||||
if (outputFile != null) {
|
||||
final file = File(outputFile);
|
||||
await file.writeAsBytes(imageBytes);
|
||||
// final file = File(outputFile);
|
||||
// await file.writeAsBytes(imageBytes);
|
||||
KenLogger.success("Saved to $outputFile");
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -164,11 +164,9 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||
const SizedBox(width: 10),
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles(
|
||||
FilePickerResult? result = await FilePicker.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['jpg', 'png', 'pdf'],
|
||||
withData: true,
|
||||
);
|
||||
if (result == null) return;
|
||||
final selectedFile = result.files.first;
|
||||
|
|
|
|||
|
|
@ -1,41 +1,43 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart';
|
||||
import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart' as ai_toolkit;
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:ollama_dart/ollama_dart.dart';
|
||||
import 'package:ollama_dart/ollama_dart.dart' as ollama;
|
||||
import 'package:cross_file/cross_file.dart';
|
||||
|
||||
class OllamaProvider extends LlmProvider with ChangeNotifier {
|
||||
class OllamaProvider extends ai_toolkit.LlmProvider with ChangeNotifier {
|
||||
OllamaProvider({
|
||||
String? baseUrl,
|
||||
Map<String, String>? headers,
|
||||
Map<String, dynamic>? queryParams,
|
||||
required String baseUrl,
|
||||
// required Map<String, String> headers,
|
||||
// required Map<String, String> queryParams,
|
||||
required String model,
|
||||
String? systemPrompt,
|
||||
bool? think,
|
||||
}) : _client = OllamaClient(
|
||||
baseUrl: baseUrl,
|
||||
headers: headers,
|
||||
queryParams: queryParams,
|
||||
}) : _client = ollama.OllamaClient(
|
||||
config: ollama.OllamaConfig(
|
||||
baseUrl: baseUrl,
|
||||
// defaultHeaders: headers,
|
||||
// defaultQueryParams: queryParams,
|
||||
),
|
||||
),
|
||||
_model = model,
|
||||
_systemPrompt = systemPrompt,
|
||||
_think = think,
|
||||
_history = [];
|
||||
final OllamaClient _client;
|
||||
final ollama.OllamaClient _client;
|
||||
final String _model;
|
||||
final List<ChatMessage> _history;
|
||||
final List<ai_toolkit.ChatMessage> _history;
|
||||
final String? _systemPrompt;
|
||||
final bool? _think;
|
||||
|
||||
@override
|
||||
Stream<String> generateStream(
|
||||
String prompt, {
|
||||
Iterable<Attachment> attachments = const [],
|
||||
Iterable<ai_toolkit.Attachment> attachments = const [],
|
||||
}) async* {
|
||||
final messages = _mapToOllamaMessages([
|
||||
ChatMessage.user(prompt, attachments),
|
||||
ai_toolkit.ChatMessage.user(prompt, attachments),
|
||||
]);
|
||||
yield* _generateStream(messages);
|
||||
}
|
||||
|
|
@ -43,7 +45,7 @@ class OllamaProvider extends LlmProvider with ChangeNotifier {
|
|||
Stream<String> speechToText(XFile audioFile) async* {
|
||||
KenLogger.success("Inside Custom speechToText funtion");
|
||||
// 1. Convert the XFile to the attachment format needed for the LLM.
|
||||
final attachments = [await FileAttachment.fromFile(audioFile)];
|
||||
final attachments = [await ai_toolkit.FileAttachment.fromFile(audioFile)];
|
||||
KenLogger.success("added attachment for audio file");
|
||||
|
||||
// 2. Define the transcription prompt, mirroring the logic from LlmChatView.
|
||||
|
|
@ -66,11 +68,11 @@ class OllamaProvider extends LlmProvider with ChangeNotifier {
|
|||
@override
|
||||
Stream<String> sendMessageStream(
|
||||
String prompt, {
|
||||
Iterable<Attachment> attachments = const [],
|
||||
Iterable<ai_toolkit.Attachment> attachments = const [],
|
||||
}) async* {
|
||||
KenLogger.success("sendMessageStream called with: $prompt");
|
||||
final userMessage = ChatMessage.user(prompt, attachments);
|
||||
final llmMessage = ChatMessage.llm();
|
||||
final userMessage = ai_toolkit.ChatMessage.user(prompt, attachments);
|
||||
final llmMessage = ai_toolkit.ChatMessage.llm();
|
||||
_history.addAll([userMessage, llmMessage]);
|
||||
notifyListeners();
|
||||
KenLogger.success("History after adding messages: ${_history.length}");
|
||||
|
|
@ -86,7 +88,7 @@ class OllamaProvider extends LlmProvider with ChangeNotifier {
|
|||
}
|
||||
|
||||
@override
|
||||
Iterable<ChatMessage> get history => _history;
|
||||
Iterable<ai_toolkit.ChatMessage> get history => _history;
|
||||
|
||||
void resetChat() {
|
||||
_history.clear();
|
||||
|
|
@ -94,48 +96,41 @@ class OllamaProvider extends LlmProvider with ChangeNotifier {
|
|||
}
|
||||
|
||||
@override
|
||||
set history(Iterable<ChatMessage> history) {
|
||||
set history(Iterable<ai_toolkit.ChatMessage> history) {
|
||||
_history.clear();
|
||||
_history.addAll(history);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<String> _generateStream(List<Message> messages) async* {
|
||||
final allMessages = <Message>[];
|
||||
Stream<String> _generateStream(List<ollama.ChatMessage> messages) async* {
|
||||
final allMessages = <ollama.ChatMessage>[];
|
||||
if (_systemPrompt != null && _systemPrompt.isNotEmpty) {
|
||||
KenLogger.success("Adding system prompt to the conversation");
|
||||
allMessages.add(Message(
|
||||
role: MessageRole.system,
|
||||
content: _systemPrompt,
|
||||
allMessages.add(ollama.ChatMessage.system(
|
||||
_systemPrompt,
|
||||
));
|
||||
}
|
||||
allMessages.addAll(messages);
|
||||
|
||||
final stream = _client.generateChatCompletionStream(
|
||||
request: GenerateChatCompletionRequest(
|
||||
final stream = _client.chat.createStream(
|
||||
request: ollama.ChatRequest(
|
||||
model: _model,
|
||||
messages: allMessages,
|
||||
think: _think ?? false,
|
||||
think: ollama.ThinkValue.enabled(_think ?? false),
|
||||
),
|
||||
);
|
||||
// final stream = _client.generateChatCompletionStream(
|
||||
// request: GenerateChatCompletionRequest(
|
||||
// model: _model,
|
||||
// messages: messages,
|
||||
// ),
|
||||
// );
|
||||
|
||||
yield* stream.map((res) => res.message.content);
|
||||
yield* stream.map((res) => res.message?.content ?? '');
|
||||
}
|
||||
|
||||
List<Message> _mapToOllamaMessages(List<ChatMessage> messages) {
|
||||
List<ollama.ChatMessage> _mapToOllamaMessages(
|
||||
List<ai_toolkit.ChatMessage> messages) {
|
||||
return messages.map((message) {
|
||||
switch (message.origin) {
|
||||
case MessageOrigin.user:
|
||||
case ai_toolkit.MessageOrigin.user:
|
||||
if (message.attachments.isEmpty) {
|
||||
return Message(
|
||||
role: MessageRole.user,
|
||||
content: message.text ?? '',
|
||||
return ollama.ChatMessage.user(
|
||||
message.text ?? '',
|
||||
);
|
||||
}
|
||||
final imageAttachments = <String>[];
|
||||
|
|
@ -144,32 +139,30 @@ class OllamaProvider extends LlmProvider with ChangeNotifier {
|
|||
docAttachments.add(message.text!);
|
||||
}
|
||||
for (final attachment in message.attachments) {
|
||||
if (attachment is FileAttachment) {
|
||||
if (attachment is ai_toolkit.FileAttachment) {
|
||||
final mimeType = attachment.mimeType.toLowerCase();
|
||||
if (mimeType.startsWith('image/')) {
|
||||
imageAttachments.add(base64Encode(attachment.bytes));
|
||||
} else if (mimeType == 'application/pdf' ||
|
||||
mimeType.startsWith('text/')) {
|
||||
throw LlmFailureException(
|
||||
throw ai_toolkit.LlmFailureException(
|
||||
"\n\nAww, that file is a little too advanced for us right now ($mimeType)! We're still learning, but we'll get there! Please try sending us a different file type.\n\nHint: We can handle images quite well!",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw LlmFailureException(
|
||||
throw ai_toolkit.LlmFailureException(
|
||||
'Unsupported attachment type: $attachment',
|
||||
);
|
||||
}
|
||||
}
|
||||
return Message(
|
||||
role: MessageRole.user,
|
||||
content: docAttachments.join(' '),
|
||||
return ollama.ChatMessage.user(
|
||||
docAttachments.join(' '),
|
||||
images: imageAttachments,
|
||||
);
|
||||
|
||||
case MessageOrigin.llm:
|
||||
return Message(
|
||||
role: MessageRole.assistant,
|
||||
content: message.text ?? '',
|
||||
case ai_toolkit.MessageOrigin.llm:
|
||||
return ollama.ChatMessage.assistant(
|
||||
message.text ?? '',
|
||||
);
|
||||
}
|
||||
}).toList(growable: false);
|
||||
|
|
@ -177,7 +170,7 @@ class OllamaProvider extends LlmProvider with ChangeNotifier {
|
|||
|
||||
@override
|
||||
void dispose() {
|
||||
_client.endSession();
|
||||
_client.close();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue