upgraded config system

This commit is contained in:
Saifeddine ALOUI 2023-06-21 01:28:25 +02:00
parent ae812c568e
commit fd043bae32
6 changed files with 24 additions and 17 deletions

View File

@ -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

View File

@ -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):

@ -1 +1 @@
Subproject commit 854400ff86978e212dbb768d5ff575a4521f2272
Subproject commit dc6ac41b445ee20678e115f51818968c869e3cb8

View File

@ -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}")

View File

@ -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}")

View File

@ -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}")