From badd6b440a0b6bad311d4276fe5954bff4663715 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 24 Oct 2023 01:07:27 +0200 Subject: [PATCH] Added preloading models zoo --- lollms/app.py | 1 - lollms/binding.py | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lollms/app.py b/lollms/app.py index 64ff252..1cd512c 100644 --- a/lollms/app.py +++ b/lollms/app.py @@ -91,7 +91,6 @@ class LollmsApplication: trace_exception(ex) else: ASCIIColors.warning(f"Couldn't load binding {self.config.binding_name}.") - self.mount_personalities() self.mount_extensions() diff --git a/lollms/binding.py b/lollms/binding.py index e459317..05c1f96 100644 --- a/lollms/binding.py +++ b/lollms/binding.py @@ -94,6 +94,11 @@ class LLMBinding: for models_folder in self.models_folders: models_folder.mkdir(parents=True, exist_ok=True) + # Store the zoo in memory for fast access + self.modelsZoo = [] + self.modelsZoo = self.get_available_models() + + def handle_request(self, data: Dict[str, Any]) -> Dict[str, Any]: """ Handle client requests. @@ -385,14 +390,18 @@ class LLMBinding: def get_available_models(self): # Create the file path relative to the child class's directory - full_data = [] + if len(self.modelsZoo)>0: + return self.modelsZoo + modelsZoo = [] for models_dir_name in self.models_dir_names: file_path = self.lollms_paths.models_zoo_path/f"{models_dir_name}.yaml" with open(file_path, 'r') as file: + ASCIIColors.yellow(f"Loading: {file_path} ...",end="") yaml_data = yaml.safe_load(file) - full_data+=yaml_data + ASCIIColors.green(f"ok") + modelsZoo+=yaml_data - return full_data + return modelsZoo @staticmethod