mirror of
				https://github.com/MaidFoundation/maid.git
				synced 2023-12-01 22:17:36 +03:00 
			
		
		
		
	remove unecisary class
This commit is contained in:
		@@ -5,7 +5,7 @@
 | 
			
		||||
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 | 
			
		||||
    
 | 
			
		||||
       <application
 | 
			
		||||
        android:label="maid"
 | 
			
		||||
        android:label="Maid"
 | 
			
		||||
        android:name="${applicationName}"
 | 
			
		||||
        android:icon="@mipmap/launcher_icon"
 | 
			
		||||
        android:requestLegacyExternalStorage="true"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										53
									
								
								lib/lib.dart
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								lib/lib.dart
									
									
									
									
									
								
							@@ -8,11 +8,9 @@ import 'dart:ffi' as ffi;
 | 
			
		||||
import 'dart:isolate';
 | 
			
		||||
import 'dart:math';
 | 
			
		||||
import 'package:ffi/ffi.dart';
 | 
			
		||||
import 'package:file_picker/file_picker.dart';
 | 
			
		||||
 | 
			
		||||
import 'package:path_provider/path_provider.dart';
 | 
			
		||||
import 'package:flutter/services.dart';
 | 
			
		||||
import 'package:permission_handler/permission_handler.dart';
 | 
			
		||||
import 'package:maid/model.dart';
 | 
			
		||||
 | 
			
		||||
import 'package:maid/llama_bindings.dart';
 | 
			
		||||
@@ -189,6 +187,7 @@ class Lib {
 | 
			
		||||
  SendPort? isolateSendPort;
 | 
			
		||||
 | 
			
		||||
  Future<void> executeBinary({
 | 
			
		||||
    required Model model,
 | 
			
		||||
    required void Function(String log) printLnLog,
 | 
			
		||||
    required void Function(String log) printLog,
 | 
			
		||||
    required String promptPassed,
 | 
			
		||||
@@ -211,6 +210,7 @@ class Lib {
 | 
			
		||||
      if (message is SendPort) {
 | 
			
		||||
        isolateSendPort = message;
 | 
			
		||||
        isolateSendPort?.send(ParsingDemand(
 | 
			
		||||
          modelPath: model.modelPath,
 | 
			
		||||
          rootIsolateToken: token,
 | 
			
		||||
          promptPassed: promptPassed,
 | 
			
		||||
          firstInteraction: firstInteraction,
 | 
			
		||||
@@ -287,10 +287,9 @@ class Lib {
 | 
			
		||||
      "llamamaid loaded",
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    var filePath = await ModelFilePath.getFilePath();
 | 
			
		||||
    print("filePath : $filePath");
 | 
			
		||||
    if (filePath == null) {
 | 
			
		||||
      log("no filePath");
 | 
			
		||||
    var modelPathUtf8 = parsingDemand.modelPath?.toNativeUtf8().cast<Char>();
 | 
			
		||||
    if (modelPathUtf8 == null) {
 | 
			
		||||
      log("modelPath is null");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -301,7 +300,8 @@ class Lib {
 | 
			
		||||
    Pointer<show_output_cb> show_output = Pointer.fromFunction(showOutput);
 | 
			
		||||
 | 
			
		||||
    NativeLibrary llamamaidBinded = NativeLibrary(llamamaid);
 | 
			
		||||
    llamamaidBinded.llamamaid_start(filePath.toNativeUtf8().cast<Char>(), prompt.toNativeUtf8().cast<Char>(), stopToken.trim().toNativeUtf8().cast<Char>(), show_output);
 | 
			
		||||
    llamamaidBinded.llamamaid_start(modelPathUtf8, prompt.toNativeUtf8().cast<Char>(), stopToken.trim().toNativeUtf8().cast<Char>(), show_output);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    print('FirstInteraction: $firstInteraction');
 | 
			
		||||
    // if first line of conversation was provided, pass it now
 | 
			
		||||
@@ -359,6 +359,7 @@ class MessageNewPrompt {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ParsingDemand {
 | 
			
		||||
  String? modelPath;
 | 
			
		||||
  RootIsolateToken? rootIsolateToken;
 | 
			
		||||
  String promptPassed;
 | 
			
		||||
  String firstInteraction;
 | 
			
		||||
@@ -366,6 +367,7 @@ class ParsingDemand {
 | 
			
		||||
  ParamsLlama paramsLlama;
 | 
			
		||||
 | 
			
		||||
  ParsingDemand({
 | 
			
		||||
    required this.modelPath,
 | 
			
		||||
    required this.rootIsolateToken,
 | 
			
		||||
    required this.promptPassed,
 | 
			
		||||
    required this.firstInteraction,
 | 
			
		||||
@@ -424,43 +426,6 @@ class ParamsLlama {
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ModelFilePath {
 | 
			
		||||
  static Future<String?> getFilePath() async {
 | 
			
		||||
    var prefs = await SharedPreferences.getInstance();
 | 
			
		||||
    if (prefs.getString('path') != null) {
 | 
			
		||||
      var path = prefs.getString('path')!;
 | 
			
		||||
      return path;
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
      await Permission.storage.request();
 | 
			
		||||
    } catch (e) {}
 | 
			
		||||
    FilePickerResult? result = await FilePicker.platform.pickFiles(
 | 
			
		||||
      type: FileType.custom,
 | 
			
		||||
      allowedExtensions: ['bin'],
 | 
			
		||||
    );
 | 
			
		||||
    if (result?.files.single.path != null) {
 | 
			
		||||
      prefs.setString('path', result!.files.single.path!);
 | 
			
		||||
      return result.files.single.path;
 | 
			
		||||
    } else {
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static Future<bool> filePathExists() async {
 | 
			
		||||
    var prefs = await SharedPreferences.getInstance();
 | 
			
		||||
    if (prefs.getString('path') != null) {
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static detachModelFile() {
 | 
			
		||||
    SharedPreferences.getInstance().then((prefs) {
 | 
			
		||||
      prefs.remove('path');
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
enum FileState {
 | 
			
		||||
  notFound,
 | 
			
		||||
  found,
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ class MaidApp extends StatelessWidget {
 | 
			
		||||
      debugShowCheckedModeBanner: false,
 | 
			
		||||
      title: 'Maid',
 | 
			
		||||
      theme: MaidTheme().getTheme(),
 | 
			
		||||
      home: const MyHomePage(title: 'Maid'),
 | 
			
		||||
      home: const MaidHomePage(title: 'Maid'),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -50,16 +50,16 @@ class MaidTheme {
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class MyHomePage extends StatefulWidget {
 | 
			
		||||
  const MyHomePage({super.key, required this.title});
 | 
			
		||||
class MaidHomePage extends StatefulWidget {
 | 
			
		||||
  const MaidHomePage({super.key, required this.title});
 | 
			
		||||
 | 
			
		||||
  final String title;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  State<MyHomePage> createState() => _MyHomePageState();
 | 
			
		||||
  State<MaidHomePage> createState() => _MaidHomePageState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _MyHomePageState extends State<MyHomePage> {
 | 
			
		||||
class _MaidHomePageState extends State<MaidHomePage> {
 | 
			
		||||
 
 | 
			
		||||
  Model model = Model();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,9 @@ import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter/services.dart';
 | 
			
		||||
import 'package:shared_preferences/shared_preferences.dart';
 | 
			
		||||
import 'package:maid/lib.dart';
 | 
			
		||||
import 'package:file_picker/file_picker.dart';
 | 
			
		||||
import 'package:permission_handler/permission_handler.dart';
 | 
			
		||||
import 'package:path/path.dart' as path;
 | 
			
		||||
 | 
			
		||||
class Model {
 | 
			
		||||
  bool inProgress = false;
 | 
			
		||||
@@ -18,7 +21,14 @@ class Model {
 | 
			
		||||
 | 
			
		||||
  TextEditingController promptController = TextEditingController();
 | 
			
		||||
  TextEditingController reversePromptController = TextEditingController();
 | 
			
		||||
 | 
			
		||||
  TextEditingController prePromptController = TextEditingController();
 | 
			
		||||
  List<TextEditingController> examplePromptControllers = [];
 | 
			
		||||
  List<TextEditingController> exampleResponseControllers = [];
 | 
			
		||||
 | 
			
		||||
  TextEditingController userAliasController = TextEditingController()..text = "User:";
 | 
			
		||||
  TextEditingController responseAliasController = TextEditingController()..text = "Maid:";
 | 
			
		||||
 | 
			
		||||
  TextEditingController seedController = TextEditingController()..text = "-1";
 | 
			
		||||
  TextEditingController n_threadsController = TextEditingController()..text = "4";
 | 
			
		||||
  TextEditingController n_predictController = TextEditingController()..text = "512";
 | 
			
		||||
@@ -34,6 +44,9 @@ class Model {
 | 
			
		||||
  var boolKeys = {};
 | 
			
		||||
  var stringKeys = {};
 | 
			
		||||
 | 
			
		||||
  String modelName = "";
 | 
			
		||||
  String modelPath = "";
 | 
			
		||||
 | 
			
		||||
  FileState fileState = FileState.notFound;
 | 
			
		||||
 | 
			
		||||
  Model() {
 | 
			
		||||
@@ -161,29 +174,29 @@ class Model {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void openFile() async {
 | 
			
		||||
    if (fileState != FileState.notFound) {
 | 
			
		||||
      await ModelFilePath.detachModelFile();
 | 
			
		||||
      fileState = FileState.notFound;
 | 
			
		||||
    try {
 | 
			
		||||
      await Permission.storage.request();
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      print(e);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    fileState = FileState.opening;
 | 
			
		||||
 | 
			
		||||
    var filePath = await ModelFilePath.getFilePath(); // getting file path
 | 
			
		||||
 | 
			
		||||
    if (filePath == null) {
 | 
			
		||||
      print("file not found");
 | 
			
		||||
      fileState = FileState.notFound;
 | 
			
		||||
      return;
 | 
			
		||||
    try {
 | 
			
		||||
        FilePickerResult? result = await FilePicker.platform.pickFiles(
 | 
			
		||||
            type: FileType.custom,
 | 
			
		||||
            allowedExtensions: ['bin'],
 | 
			
		||||
        );
 | 
			
		||||
        if (result != null) {
 | 
			
		||||
            String? filePath = result.files.single.path;
 | 
			
		||||
            if (filePath != null) {
 | 
			
		||||
                modelPath = filePath;
 | 
			
		||||
                modelName = path.basename(filePath);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
        print(e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var file = File(filePath);
 | 
			
		||||
    if (!file.existsSync()) {
 | 
			
		||||
      print("file not found 2");
 | 
			
		||||
      fileState = FileState.notFound;
 | 
			
		||||
      await ModelFilePath.detachModelFile();
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fileState = FileState.found;
 | 
			
		||||
    print(modelPath);
 | 
			
		||||
    print(modelName);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -47,6 +47,7 @@ class _ChatWidgetState extends State<ChatWidget> {
 | 
			
		||||
    if (lib == null) {
 | 
			
		||||
      lib = Lib();
 | 
			
		||||
      lib?.executeBinary(
 | 
			
		||||
        model: model,
 | 
			
		||||
        paramsLlama: ParamsLlama(
 | 
			
		||||
          memory_f16: model.memory_f16,
 | 
			
		||||
          random_prompt: model.random_prompt,
 | 
			
		||||
 
 | 
			
		||||
@@ -67,8 +67,8 @@ class _SettingsWidgetState extends State<SettingsWidget> {
 | 
			
		||||
    if (Platform.isIOS) {
 | 
			
		||||
      (await SharedPreferences.getInstance()).remove('path');
 | 
			
		||||
    }
 | 
			
		||||
    var found = await ModelFilePath.filePathExists();
 | 
			
		||||
    if (found) {
 | 
			
		||||
 | 
			
		||||
    if (model.modelPath != "" && await File(model.modelPath).exists()) {
 | 
			
		||||
      setState(() {
 | 
			
		||||
        model.fileState = FileState.found;
 | 
			
		||||
      });
 | 
			
		||||
@@ -99,6 +99,21 @@ class _SettingsWidgetState extends State<SettingsWidget> {
 | 
			
		||||
            ),
 | 
			
		||||
            child: Text('Settings'),
 | 
			
		||||
          ),
 | 
			
		||||
          Row(
 | 
			
		||||
            mainAxisAlignment: MainAxisAlignment.center,
 | 
			
		||||
            children: [
 | 
			
		||||
              const Text("RAM: "),
 | 
			
		||||
              Text(
 | 
			
		||||
                _ram,
 | 
			
		||||
                style: TextStyle(
 | 
			
		||||
                  color: color,
 | 
			
		||||
                  fontWeight: FontWeight.bold,
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
          const SizedBox(height: 10.0),
 | 
			
		||||
          Text(model.modelPath),
 | 
			
		||||
          ElevatedButton(
 | 
			
		||||
            onPressed: () {
 | 
			
		||||
              model.openFile();
 | 
			
		||||
@@ -111,20 +126,7 @@ class _SettingsWidgetState extends State<SettingsWidget> {
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
          Row(
 | 
			
		||||
            children: [
 | 
			
		||||
              const Text("RAM: "),
 | 
			
		||||
              Expanded(
 | 
			
		||||
                child: Text(
 | 
			
		||||
                  _ram,
 | 
			
		||||
                  style: TextStyle(
 | 
			
		||||
                    color: color,
 | 
			
		||||
                    fontWeight: FontWeight.bold,
 | 
			
		||||
                  ),
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
          const SizedBox(height: 10.0),
 | 
			
		||||
          ElevatedButton(
 | 
			
		||||
            onPressed: () {
 | 
			
		||||
              model.resetAll(setState);
 | 
			
		||||
@@ -137,17 +139,67 @@ class _SettingsWidgetState extends State<SettingsWidget> {
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
          const SizedBox(height: 15.0),
 | 
			
		||||
          llamaParamTextField(
 | 
			
		||||
            'User alias:', model.userAliasController, 'User alias'),
 | 
			
		||||
          llamaParamTextField(
 | 
			
		||||
            'Response alias:', model.responseAliasController, 'Response alias'),
 | 
			
		||||
          ListTile(
 | 
			
		||||
            title: Text('PrePrompt'),
 | 
			
		||||
            title: const Text('PrePrompt:'),
 | 
			
		||||
            subtitle: TextField(
 | 
			
		||||
              keyboardType: TextInputType.multiline,
 | 
			
		||||
              maxLines: null,
 | 
			
		||||
              controller: model.prePromptController,
 | 
			
		||||
              decoration: InputDecoration(
 | 
			
		||||
              decoration: const InputDecoration(
 | 
			
		||||
                hintText: 'PrePrompt',
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
          Row(
 | 
			
		||||
            mainAxisAlignment: MainAxisAlignment.center,
 | 
			
		||||
            children: [
 | 
			
		||||
              ElevatedButton(
 | 
			
		||||
                onPressed: () {
 | 
			
		||||
                  setState(() {
 | 
			
		||||
                    model.examplePromptControllers.add(TextEditingController());
 | 
			
		||||
                    model.exampleResponseControllers.add(TextEditingController());
 | 
			
		||||
                  });
 | 
			
		||||
                },
 | 
			
		||||
                child: const Text(
 | 
			
		||||
                  "Add Example",
 | 
			
		||||
                  style: TextStyle(
 | 
			
		||||
                    color: Colors.white,
 | 
			
		||||
                    fontWeight: FontWeight.bold,
 | 
			
		||||
                  ),
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
              const SizedBox(width: 10.0),
 | 
			
		||||
              ElevatedButton(
 | 
			
		||||
                onPressed: () {
 | 
			
		||||
                  setState(() {
 | 
			
		||||
                    model.examplePromptControllers.removeLast();
 | 
			
		||||
                    model.exampleResponseControllers.removeLast();
 | 
			
		||||
                  });
 | 
			
		||||
                },
 | 
			
		||||
                child: const Text(
 | 
			
		||||
                  "Remove Example",
 | 
			
		||||
                  style: TextStyle(
 | 
			
		||||
                    color: Colors.white,
 | 
			
		||||
                    fontWeight: FontWeight.bold,
 | 
			
		||||
                  ),
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
          ...List.generate(
 | 
			
		||||
            (model.examplePromptControllers.length == model.exampleResponseControllers.length) ? model.examplePromptControllers.length : 0,
 | 
			
		||||
            (index) => Column(
 | 
			
		||||
              children: [
 | 
			
		||||
                llamaParamTextField('Example prompt:', model.examplePromptControllers[index], 'Example prompt'),
 | 
			
		||||
                llamaParamTextField('Example response:', model.exampleResponseControllers[index], 'Example response'),
 | 
			
		||||
              ],
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
          llamaParamSwitch(
 | 
			
		||||
            'memory_f16:', model.memory_f16, 'memory_f16'),
 | 
			
		||||
          llamaParamSwitch(
 | 
			
		||||
@@ -162,6 +214,7 @@ class _SettingsWidgetState extends State<SettingsWidget> {
 | 
			
		||||
            'ignore_eos:', model.ignore_eos, 'ignore_eos'),
 | 
			
		||||
          llamaParamSwitch(
 | 
			
		||||
            'perplexity:', model.perplexity, 'perplexity'),
 | 
			
		||||
          const SizedBox(height: 15.0),
 | 
			
		||||
          llamaParamTextField(
 | 
			
		||||
            'seed (-1 for random):', model.seedController, 'seed'),
 | 
			
		||||
          llamaParamTextField(
 | 
			
		||||
 
 | 
			
		||||
@@ -304,7 +304,7 @@ packages:
 | 
			
		||||
    source: hosted
 | 
			
		||||
    version: "2.1.0"
 | 
			
		||||
  path:
 | 
			
		||||
    dependency: transitive
 | 
			
		||||
    dependency: "direct main"
 | 
			
		||||
    description:
 | 
			
		||||
      name: path
 | 
			
		||||
      sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
 | 
			
		||||
 
 | 
			
		||||
@@ -43,6 +43,7 @@ dependencies:
 | 
			
		||||
  url_launcher: ^6.1.10
 | 
			
		||||
  file_picker: ^5.2.6
 | 
			
		||||
  device_info_plus: ^8.1.0
 | 
			
		||||
  path: ^1.8.3
 | 
			
		||||
 | 
			
		||||
dev_dependencies:
 | 
			
		||||
  msix: ^3.9.1
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user