diff --git a/lollms/app.py b/lollms/app.py index 166a52d..ccc8ca7 100644 --- a/lollms/app.py +++ b/lollms/app.py @@ -4,7 +4,7 @@ from lollms.paths import LollmsPaths from lollms.personality import PersonalityBuilder from lollms.binding import LLMBinding, BindingBuilder, ModelBuilder from lollms.config import InstallOption -import traceback +from lollms.helpers import trace_exception from lollms.terminal import MainMenu class LollmsApplication: @@ -29,6 +29,7 @@ class LollmsApplication: self.binding = self.load_binding() except Exception as ex: ASCIIColors.error(f"Failed to load binding.\nReturned exception: {ex}") + trace_exception(ex) if self.binding is not None: ASCIIColors.success(f"Binding {self.config.binding_name} loaded successfully.") @@ -41,6 +42,7 @@ class LollmsApplication: self.model = self.load_model() except Exception as ex: ASCIIColors.error(f"Failed to load model.\nReturned exception: {ex}") + trace_exception(ex) self.model = None else: self.model = None @@ -53,15 +55,6 @@ class LollmsApplication: self.model = None self.mount_personalities() - - def trace_exception(self, ex): - # Catch the exception and get the traceback as a list of strings - traceback_lines = traceback.format_exception(type(ex), ex, ex.__traceback__) - - # Join the traceback lines into a single string - traceback_text = ''.join(traceback_lines) - ASCIIColors.error(traceback_text) - def load_binding(self): try: binding = BindingBuilder().build_binding(self.config, self.lollms_paths) @@ -69,7 +62,12 @@ class LollmsApplication: print(ex) print(f"Couldn't find binding. Please verify your configuration file at {self.configuration_path} or use the next menu to select a valid binding") print(f"Trying to reinstall binding") - binding = BindingBuilder().build_binding(self.config, self.lollms_paths,installation_option=InstallOption.FORCE_INSTALL) + try: + binding = BindingBuilder().build_binding(self.config, self.lollms_paths,installation_option=InstallOption.FORCE_INSTALL) + except Exception as ex: + ASCIIColors.error("Couldn't reinstall model") + trace_exception(ex) + return binding def load_model(self): @@ -81,6 +79,7 @@ class LollmsApplication: except Exception as ex: ASCIIColors.error(f"Couldn't load model. Please verify your configuration file at {self.lollms_paths.personal_configuration_path} or use the next menu to select a valid model") ASCIIColors.error(f"Binding returned this exception : {ex}") + trace_exception(ex) ASCIIColors.error(f"{self.config.get_model_path_infos()}") print("Please select a valid model or install a new one from a url") model = None @@ -102,7 +101,7 @@ class LollmsApplication: except Exception as ex: ASCIIColors.error(f"Couldn't load personality. Please verify your configuration file at {self.lollms_paths.personal_configuration_path} or use the next menu to select a valid personality") ASCIIColors.error(f"Binding returned this exception : {ex}") - self.trace_exception(ex) + trace_exception(ex) ASCIIColors.error(f"{self.config.get_personality_path_infos()}") self.personality = None self.mounted_personalities.append(self.personality) diff --git a/lollms/binding.py b/lollms/binding.py index af71504..7130823 100644 --- a/lollms/binding.py +++ b/lollms/binding.py @@ -22,7 +22,7 @@ import importlib import subprocess from lollms.config import TypedConfig, InstallOption from lollms.main_config import LOLLMSConfig - +import traceback __author__ = "parisneo" __github__ = "https://github.com/ParisNeo/lollms_bindings_zoo" diff --git a/lollms/console.py b/lollms/console.py index f30de2e..d8530da 100644 --- a/lollms/console.py +++ b/lollms/console.py @@ -241,7 +241,7 @@ Participating personalities: antiprompt = self.personality.detect_antiprompt(bot_says) if antiprompt: self.bot_says = self.remove_text_from_string(bot_says,antiprompt) - print("Detected hallucination") + ASCIIColors.warning(f"Detected hallucination with antiprompt {antiprompt}") return False else: self.bot_says = bot_says diff --git a/lollms/helpers.py b/lollms/helpers.py index cd30374..d513fcd 100644 --- a/lollms/helpers.py +++ b/lollms/helpers.py @@ -1,4 +1,15 @@ +import traceback +def trace_exception(ex): + """ + Traces an exception (useful for debug) + """ + # Catch the exception and get the traceback as a list of strings + traceback_lines = traceback.format_exception(type(ex), ex, ex.__traceback__) + + # Join the traceback lines into a single string + traceback_text = ''.join(traceback_lines) + ASCIIColors.error(traceback_text) class ASCIIColors: # Reset diff --git a/lollms/personality.py b/lollms/personality.py index d9951a8..3286a1a 100644 --- a/lollms/personality.py +++ b/lollms/personality.py @@ -982,7 +982,7 @@ class APScript: antiprompt = self.personality.detect_antiprompt(bot_says) if antiprompt: self.bot_says = self.remove_text_from_string(bot_says,antiprompt) - ASCIIColors.warning("Detected hallucination") + ASCIIColors.warning(f"Detected hallucination with antiprompt: {antiprompt}") return False else: self.bot_says = bot_says diff --git a/lollms/terminal.py b/lollms/terminal.py index a1cffc2..a426c2c 100644 --- a/lollms/terminal.py +++ b/lollms/terminal.py @@ -7,6 +7,7 @@ if TYPE_CHECKING: from lollms.binding import BindingBuilder from lollms.config import InstallOption from lollms.personality import PersonalityBuilder +from lollms.helpers import trace_exception from tqdm import tqdm import pkg_resources @@ -277,6 +278,7 @@ class MainMenu: except Exception as ex: ASCIIColors.error(f"Couldn't load personality. Please verify your configuration file at {lollms_app.configuration_path} or use the next menu to select a valid personality") ASCIIColors.error(f"Binding returned this exception : {ex}") + trace_exception(ex) ASCIIColors.error(f"{lollms_app.config.get_personality_path_infos()}") print("Please select a valid model or install a new one from a url") self.select_model() diff --git a/setup.py b/setup.py index 2ac1bcc..2234769 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def get_all_files(path): setuptools.setup( name="lollms", - version="2.1.28", + version="2.1.32", author="Saifeddine ALOUI", author_email="aloui.saifeddine@gmail.com", description="A python library for AI personality definition",