From c59fa57547a8801ef07919c4a575fa3f73615c4f Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Wed, 8 Nov 2023 15:20:24 +0100 Subject: [PATCH] upgraded notification --- lollms/app.py | 10 +++++++--- lollms/binding.py | 15 ++++++++++++--- setup.py | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lollms/app.py b/lollms/app.py index dfc3136..d03b777 100644 --- a/lollms/app.py +++ b/lollms/app.py @@ -22,7 +22,8 @@ class LollmsApplication: load_model=True, try_select_binding=False, try_select_model=False, - callback=None + callback=None, + notification_callback:Callable=None ) -> None: """ Creates a LOLLMS Application @@ -36,7 +37,7 @@ class LollmsApplication: self.personality = None self.mounted_extensions = [] - + self.notification_callback = notification_callback self.binding=None self.model=None @@ -149,6 +150,9 @@ class LollmsApplication: return generated_text def notify(self, content, is_success, client_id=None): + if self.notification_callback: + return self.notification_callback(content, is_success, client_id) + if is_success: ASCIIColors.yellow(content) else: @@ -156,7 +160,7 @@ class LollmsApplication: def load_binding(self): try: - binding = BindingBuilder().build_binding(self.config, self.lollms_paths) + binding = BindingBuilder().build_binding(self.config, self.lollms_paths, notification_callback=self.notify) return binding except Exception as ex: print(ex) diff --git a/lollms/binding.py b/lollms/binding.py index 6cdaac7..c992353 100644 --- a/lollms/binding.py +++ b/lollms/binding.py @@ -59,7 +59,8 @@ class LLMBinding: installation_option:InstallOption=InstallOption.INSTALL_IF_NECESSARY, supported_file_extensions='*.bin', binding_type:BindingType=BindingType.TEXT_ONLY, - models_dir_names:list=None + models_dir_names:list=None, + notification_callback:Callable=None ) -> None: self.binding_type = binding_type @@ -71,6 +72,7 @@ class LLMBinding: self.binding_config = binding_config self.supported_file_extensions = supported_file_extensions self.seed = config["seed"] + self.notification_callback = notification_callback self.configuration_file_path = lollms_paths.personal_configuration_path/"bindings"/self.binding_folder_name/f"config.yaml" self.configuration_file_path.parent.mkdir(parents=True, exist_ok=True) @@ -94,6 +96,11 @@ class LLMBinding: for models_folder in self.models_folders: models_folder.mkdir(parents=True, exist_ok=True) + def notify(self, content:str, status:bool): + if self.notification_callback: + self.notification_callback(content, status) + + def settings_updated(self): """ To be implemented by the bindings @@ -465,14 +472,16 @@ class BindingBuilder: self, config: LOLLMSConfig, lollms_paths:LollmsPaths, - installation_option:InstallOption=InstallOption.INSTALL_IF_NECESSARY + installation_option:InstallOption=InstallOption.INSTALL_IF_NECESSARY, + notification_callback:Callable=None )->LLMBinding: binding:LLMBinding = self.getBinding(config, lollms_paths, installation_option) return binding( config, lollms_paths=lollms_paths, - installation_option = installation_option + installation_option = installation_option, + notification_callback=notification_callback ) def getBinding( diff --git a/setup.py b/setup.py index f0cb256..193faf9 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def get_all_files(path): setuptools.setup( name="lollms", - version="6.1.0", + version="6.1.1", author="Saifeddine ALOUI", author_email="aloui.saifeddine@gmail.com", description="A python library for AI personality definition",