mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-01-18 02:39:46 +00:00
enhanced lollms
This commit is contained in:
parent
2c8dda35e3
commit
0f16fe605a
@ -10,7 +10,17 @@ from lollms.terminal import MainMenu
|
||||
import subprocess
|
||||
|
||||
class LollmsApplication:
|
||||
def __init__(self, app_name:str, config:LOLLMSConfig, lollms_paths:LollmsPaths, load_binding=True, load_model=True, try_select_binding=False, try_select_model=False) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
app_name:str,
|
||||
config:LOLLMSConfig,
|
||||
lollms_paths:LollmsPaths,
|
||||
load_binding=True,
|
||||
load_model=True,
|
||||
try_select_binding=False,
|
||||
try_select_model=False,
|
||||
callback=None
|
||||
) -> None:
|
||||
"""
|
||||
Creates a LOLLMS Application
|
||||
"""
|
||||
@ -18,7 +28,7 @@ class LollmsApplication:
|
||||
self.config = config
|
||||
self.lollms_paths = lollms_paths
|
||||
|
||||
self.menu = MainMenu(self)
|
||||
self.menu = MainMenu(self, callback)
|
||||
self.mounted_personalities = []
|
||||
self.personality = None
|
||||
|
||||
@ -105,9 +115,9 @@ class LollmsApplication:
|
||||
return model
|
||||
|
||||
|
||||
def mount_personality(self, id:int):
|
||||
def mount_personality(self, id:int, callback=None):
|
||||
try:
|
||||
personality = PersonalityBuilder(self.lollms_paths, self.config, self.model).build_personality(id)
|
||||
personality = PersonalityBuilder(self.lollms_paths, self.config, self.model, callback=callback).build_personality(id)
|
||||
if personality.model is not None:
|
||||
self.cond_tk = personality.model.tokenize(personality.personality_conditioning)
|
||||
self.n_cond_tk = len(self.cond_tk)
|
||||
@ -127,11 +137,11 @@ class LollmsApplication:
|
||||
self.mounted_personalities.append(personality)
|
||||
return personality
|
||||
|
||||
def mount_personalities(self):
|
||||
def mount_personalities(self, callback = None):
|
||||
self.mounted_personalities = []
|
||||
to_remove = []
|
||||
for i in range(len(self.config["personalities"])):
|
||||
p = self.mount_personality(i)
|
||||
p = self.mount_personality(i, callback = None)
|
||||
if p is None:
|
||||
to_remove.append(i)
|
||||
to_remove.sort(reverse=True)
|
||||
@ -164,9 +174,9 @@ class LollmsApplication:
|
||||
return False
|
||||
|
||||
|
||||
def load_personality(self):
|
||||
def load_personality(self, callback=None):
|
||||
try:
|
||||
personality = PersonalityBuilder(self.lollms_paths, self.config, self.model).build_personality()
|
||||
personality = PersonalityBuilder(self.lollms_paths, self.config, self.model, callback=callback).build_personality()
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Couldn't load personality. Please verify your configuration file at {self.configuration_path} or use the next menu to select a valid personality")
|
||||
ASCIIColors.error(f"Binding returned this exception : {ex}")
|
||||
|
@ -995,7 +995,9 @@ class APScript(StateMachine):
|
||||
else:
|
||||
ASCIIColors.error("Pytorch installed successfully!!")
|
||||
|
||||
def add_file(self, path):
|
||||
def add_file(self, path, callback=None):
|
||||
if callback is not None:
|
||||
callback("File added successfully",MSG_TYPE.MSG_TYPE_INFO)
|
||||
self.files.append(path)
|
||||
return True
|
||||
|
||||
@ -1281,7 +1283,7 @@ class APScript(StateMachine):
|
||||
if callback:
|
||||
callback(step_text, MSG_TYPE.MSG_TYPE_STEP_PROGRESS, {'progress':progress})
|
||||
|
||||
def new_message(self, step_text:str, message_type:MSG_TYPE, callback: Callable[[str, int, dict], bool]=None):
|
||||
def new_message(self, message_text:str, message_type:MSG_TYPE, callback: Callable[[str, int, dict], bool]=None):
|
||||
"""This sends step rogress to front end
|
||||
|
||||
Args:
|
||||
@ -1292,7 +1294,20 @@ class APScript(StateMachine):
|
||||
callback = self.callback
|
||||
|
||||
if callback:
|
||||
callback(step_text, MSG_TYPE.MSG_TYPE_NEW_MESSAGE, {'type':message_type})
|
||||
callback(message_text, MSG_TYPE.MSG_TYPE_NEW_MESSAGE, {'type':message_type})
|
||||
|
||||
def finished_message(self, message_text:str="", callback: Callable[[str, int, dict], bool]=None):
|
||||
"""This sends step rogress to front end
|
||||
|
||||
Args:
|
||||
step_text (dict): The step progress in %
|
||||
callback (callable, optional): A callable with this signature (str, MSG_TYPE) to send the progress to. Defaults to None.
|
||||
"""
|
||||
if not callback and self.callback:
|
||||
callback = self.callback
|
||||
|
||||
if callback:
|
||||
callback(message_text, MSG_TYPE.MSG_TYPE_FINISHED_MESSAGE)
|
||||
|
||||
#Helper method to convert outputs path to url
|
||||
def path2url(file):
|
||||
@ -1315,12 +1330,14 @@ class PersonalityBuilder:
|
||||
lollms_paths:LollmsPaths,
|
||||
config:LOLLMSConfig,
|
||||
model:LLMBinding,
|
||||
installation_option:InstallOption=InstallOption.INSTALL_IF_NECESSARY
|
||||
installation_option:InstallOption=InstallOption.INSTALL_IF_NECESSARY,
|
||||
callback=None
|
||||
):
|
||||
self.config = config
|
||||
self.lollms_paths = lollms_paths
|
||||
self.model = model
|
||||
self.installation_option = installation_option
|
||||
self.callback = callback
|
||||
|
||||
|
||||
def build_personality(self, id:int=None):
|
||||
@ -1339,7 +1356,8 @@ class PersonalityBuilder:
|
||||
self.lollms_paths,
|
||||
self.config,
|
||||
self.model,
|
||||
installation_option=self.installation_option
|
||||
installation_option=self.installation_option,
|
||||
callback=self.callback
|
||||
)
|
||||
else:
|
||||
self.personality = AIPersonality(
|
||||
@ -1348,7 +1366,8 @@ class PersonalityBuilder:
|
||||
self.config,
|
||||
self.model,
|
||||
is_relative_path=False,
|
||||
installation_option=self.installation_option
|
||||
installation_option=self.installation_option,
|
||||
callback=self.callback
|
||||
)
|
||||
return self.personality
|
||||
|
||||
|
@ -121,9 +121,10 @@ class Menu:
|
||||
print("Invalid response. Please answer with 'yes' or 'no' (or 'y'/'n').")
|
||||
|
||||
class MainMenu(Menu):
|
||||
def __init__(self, lollms_app:'LollmsApplication'):
|
||||
def __init__(self, lollms_app:'LollmsApplication', callback=None):
|
||||
self.binding_infs = []
|
||||
self.lollms_app = lollms_app
|
||||
self.callback = callback
|
||||
main_menu_options = [
|
||||
{'name': 'Main settings', 'fn': self.main_settings, 'help': "Show main settings."},
|
||||
{'name': 'Select Binding', 'fn': self.select_binding, 'help': "Choose a binding."},
|
||||
@ -316,7 +317,7 @@ class MainMenu(Menu):
|
||||
name = personality_names[choice - 1]
|
||||
print(f"You selected personality: {ASCIIColors.color_green}{name}{ASCIIColors.color_reset}")
|
||||
self.lollms_app.config["personalities"].append(f"{language}/{category}/{name}")
|
||||
self.lollms_app.mount_personality(len(self.lollms_app.config["personalities"])-1)
|
||||
self.lollms_app.mount_personality(len(self.lollms_app.config["personalities"])-1, callback = self.callback)
|
||||
self.lollms_app.config.save_config()
|
||||
print("Personality mounted successfully!")
|
||||
elif 1 <= choice <= len(personality_names):
|
||||
@ -406,10 +407,10 @@ class MainMenu(Menu):
|
||||
|
||||
|
||||
|
||||
def reinstall_personality(self):
|
||||
def reinstall_personality(self, callback=None):
|
||||
lollms_app = self.lollms_app
|
||||
try:
|
||||
lollms_app.personality = PersonalityBuilder(lollms_app.lollms_paths, lollms_app.config, lollms_app.model, installation_option=InstallOption.FORCE_INSTALL).build_personality()
|
||||
lollms_app.personality = PersonalityBuilder(lollms_app.lollms_paths, lollms_app.config, lollms_app.model, installation_option=InstallOption.FORCE_INSTALL, callback=callback).build_personality()
|
||||
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}")
|
||||
|
@ -27,6 +27,8 @@ class MSG_TYPE(Enum):
|
||||
|
||||
#Commands
|
||||
MSG_TYPE_NEW_MESSAGE = 15# A new message
|
||||
MSG_TYPE_FINISHED_MESSAGE = 17# End of current message
|
||||
|
||||
|
||||
class GenerationPresets:
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user