diff --git a/lollms/__init__.py b/lollms/__init__.py index 3f07595..ef01284 100644 --- a/lollms/__init__.py +++ b/lollms/__init__.py @@ -38,18 +38,21 @@ class BindingBuilder: # use importlib to load the module from the file path loader = importlib.machinery.SourceFileLoader(module_name, str(absolute_path / "__init__.py")) binding_module = loader.load_module() - binding = getattr(binding_module, binding_module.binding_name) - return binding + binding:LLMBinding = getattr(binding_module, binding_module.binding_name) + return binding( + cfg, + force_reinstall = force_reinstall + ) class ModelBuilder: - def __init__(self, binding:LLMBinding, config:LOLLMSConfig): + def __init__(self, binding:LLMBinding): self.binding = binding self.model = None - self.build_model(config) + self.build_model(binding.config) def build_model(self, cfg: LOLLMSConfig): - self.model = self.binding(cfg) + self.model = self.binding.build_model() def get_model(self): return self.model diff --git a/lollms/binding.py b/lollms/binding.py index 4d2aa56..f2c3f7a 100644 --- a/lollms/binding.py +++ b/lollms/binding.py @@ -63,6 +63,8 @@ class LLMBinding: self.config = config self.binding_config = binding_config + self.models_folder = None + self.configuration_file_path = lollms_paths.personal_configuration_path/f"binding_{self.binding_folder_name}.yaml" self.binding_config.config.file_path = self.configuration_file_path if not self.configuration_file_path.exists() or force_install: @@ -74,7 +76,16 @@ class LLMBinding: self.models_folder = config.lollms_paths.personal_models_path / self.binding_folder_name self.models_folder.mkdir(parents=True, exist_ok=True) + def build_model(self): + """ + Build the model. + This method is responsible for constructing the model for the LOLLMS class. + + Returns: + the model + """ + return self.models_folder def install(self): """ @@ -176,13 +187,6 @@ class LLMBinding: """ return " ".join(tokens_list) - @staticmethod - def list_models(config:dict, root_path="."): - """Lists the models for this binding - """ - root_path = Path(root_path) - models_dir =(root_path/'models')/config["binding_name"] # replace with the actual path to the models folder - return [f.name for f in models_dir.glob(LLMBinding.file_extension)] @staticmethod def install_binding(binding_path, config:LOLLMSConfig): diff --git a/lollms/bindings_zoo b/lollms/bindings_zoo index 854400f..dc6ac41 160000 --- a/lollms/bindings_zoo +++ b/lollms/bindings_zoo @@ -1 +1 @@ -Subproject commit 854400ff86978e212dbb768d5ff575a4521f2272 +Subproject commit dc6ac41b445ee20678e115f51818968c869e3cb8 diff --git a/lollms/console.py b/lollms/console.py index 2a88292..d0f128c 100644 --- a/lollms/console.py +++ b/lollms/console.py @@ -106,7 +106,7 @@ class MainMenu: if hasattr(self.lollms_app,"binding") and hasattr(self.lollms_app.binding,"list_models"): models_list = [f'{v["filename"]} (by {v["owner"]})' for v in self.lollms_app.binding.list_models(self.lollms_app.config)] + ["Install model", "Change binding", "Back"] else: - models_list = [m.name for m in models_dir.iterdir() if m.name.lower() not in [".ds_dtore","thumb.db"]] + ["Install model", "Change binding", "Back"] + models_list = [m.name for m in models_dir.iterdir() if m.name.lower() not in [".ds_dtore","thumb.db",".keep"]] + ["Install model", "Change binding", "Back"] choice = self.show_menu(models_list) if 1 <= choice <= len(models_list)-3: print(f"You selected model: {ASCIIColors.color_green}{models_list[choice - 1]}{ASCIIColors.color_reset}") @@ -392,7 +392,7 @@ Participating personalities: def load_model(self): try: - self.model = ModelBuilder(self.binding, self.config).get_model() + self.model = ModelBuilder(self.binding).get_model() except Exception as ex: ASCIIColors.error(f"Couldn't load model. Please verify your configuration file at {self.configuration_path} or use the next menu to select a valid model") ASCIIColors.error(f"Binding returned this exception : {ex}") diff --git a/lollms/server.py b/lollms/server.py index 513d6e0..32b822c 100644 --- a/lollms/server.py +++ b/lollms/server.py @@ -146,7 +146,7 @@ class LoLLMsServer: def load_model(self): try: - self.model = ModelBuilder(self.binding, self.config).get_model() + self.model = ModelBuilder(self.binding).get_model() except Exception as ex: ASCIIColors.error(f"Couldn't load model.") ASCIIColors.error(f"Binding returned this exception : {ex}") diff --git a/lollms/settings.py b/lollms/settings.py index f1a3ebe..5c2aca1 100644 --- a/lollms/settings.py +++ b/lollms/settings.py @@ -153,7 +153,7 @@ Participating personalities: def load_model(self): try: - self.model = ModelBuilder(self.binding, self.config).get_model() + self.model = ModelBuilder(self.binding).get_model() except Exception as ex: ASCIIColors.error(f"Couldn't load model. Please verify your configuration file at {self.cfg_path} or use the next menu to select a valid model") ASCIIColors.error(f"Binding returned this exception : {ex}")