mirror of
https://github.com/ParisNeo/lollms.git
synced 2024-12-18 20:27:58 +00:00
enhanced tool
This commit is contained in:
parent
83d6079e64
commit
8ef1f0cd70
@ -8,7 +8,7 @@ import traceback
|
||||
from lollms.terminal import MainMenu
|
||||
|
||||
class LollmsApplication:
|
||||
def __init__(self, app_name:str, config:LOLLMSConfig, lollms_paths:LollmsPaths) -> None:
|
||||
def __init__(self, app_name:str, config:LOLLMSConfig, lollms_paths:LollmsPaths, load_binding=True, load_model=True) -> None:
|
||||
"""
|
||||
Creates a LOLLMS Application
|
||||
"""
|
||||
@ -24,25 +24,31 @@ class LollmsApplication:
|
||||
ASCIIColors.warning(f"No binding selected")
|
||||
ASCIIColors.info("Please select a valid model or install a new one from a url")
|
||||
self.menu.select_binding()
|
||||
|
||||
try:
|
||||
self.binding = self.load_binding()
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Failed to load binding.\nReturned exception: {ex}")
|
||||
|
||||
if self.binding is not None:
|
||||
ASCIIColors.success(f"Binding {self.config.binding_name} loaded successfully.")
|
||||
if self.config.model_name is None:
|
||||
ASCIIColors.warning(f"No model selected")
|
||||
print("Please select a valid model")
|
||||
self.menu.select_model()
|
||||
if load_binding:
|
||||
try:
|
||||
self.model = self.load_model()
|
||||
self.binding = self.load_binding()
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Failed to load model.\nReturned exception: {ex}")
|
||||
ASCIIColors.error(f"Failed to load binding.\nReturned exception: {ex}")
|
||||
|
||||
if self.binding is not None:
|
||||
ASCIIColors.success(f"Binding {self.config.binding_name} loaded successfully.")
|
||||
if load_model:
|
||||
if self.config.model_name is None:
|
||||
ASCIIColors.warning(f"No model selected")
|
||||
print("Please select a valid model")
|
||||
self.menu.select_model()
|
||||
try:
|
||||
self.model = self.load_model()
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Failed to load model.\nReturned exception: {ex}")
|
||||
self.model = None
|
||||
else:
|
||||
self.model = None
|
||||
else:
|
||||
ASCIIColors.warning(f"Couldn't load binding {self.config.binding_name}.")
|
||||
self.binding = None
|
||||
self.model = None
|
||||
else:
|
||||
ASCIIColors.warning(f"Couldn't load binding {self.config.binding_name}.")
|
||||
self.binding = None
|
||||
self.model = None
|
||||
self.mount_personalities()
|
||||
|
@ -127,11 +127,13 @@ class LLMBinding:
|
||||
return None
|
||||
|
||||
if self.config.model_name.endswith(".reference"):
|
||||
ASCIIColors.yellow("Loading a reference model:")
|
||||
with open(str(self.lollms_paths.personal_models_path / f"{self.binding_folder_name}/{self.config.model_name}"), 'r') as f:
|
||||
model_path = Path(f.read())
|
||||
ASCIIColors.yellow(model_path)
|
||||
else:
|
||||
model_path = Path(self.lollms_paths.personal_models_path / f"{self.binding_folder_name}/{self.config.model_name}")
|
||||
|
||||
|
||||
return model_path
|
||||
|
||||
|
||||
@ -228,7 +230,7 @@ class LLMBinding:
|
||||
"""Lists the models for this binding
|
||||
"""
|
||||
models_dir = self.lollms_paths.personal_models_path/config["binding_name"] # replace with the actual path to the models folder
|
||||
return [f.name for f in models_dir.glob(self.file_extension)]
|
||||
return [f.name for f in models_dir.iterdir() if f.suffix == self.file_extension.replace("*","") or f.suffix==".reference"]
|
||||
|
||||
@staticmethod
|
||||
def reinstall_pytorch_with_cuda():
|
||||
|
@ -501,7 +501,19 @@ class LoLLMsServer(LollmsApplication):
|
||||
|
||||
|
||||
def run(self, host="localhost", port="9601"):
|
||||
if self.binding is None:
|
||||
ASCIIColors.warning("No binding selected. Please select one")
|
||||
self.menu.select_binding()
|
||||
|
||||
print(f"{ASCIIColors.color_red}Current binding (model) : {ASCIIColors.color_reset}{self.binding}")
|
||||
print(f"{ASCIIColors.color_red}Mounted personalities : {ASCIIColors.color_reset}{self.config.personalities}")
|
||||
if len(self.config.personalities)==0:
|
||||
ASCIIColors.warning("No personality selected. Selecting lollms. You can mount other personalities using lollms-settings application")
|
||||
self.config.personalities = ["english/generic/lollms"]
|
||||
self.config.save_config()
|
||||
|
||||
if self.config.active_personality_id>=len(self.config.personalities):
|
||||
self.config.active_personality_id = 0
|
||||
print(f"{ASCIIColors.color_red}Current personality : {ASCIIColors.color_reset}{self.config.personalities[self.config.active_personality_id]}")
|
||||
ASCIIColors.info(f"Serving on address: http://{host}:{port}")
|
||||
|
||||
|
@ -32,7 +32,7 @@ class Settings(LollmsApplication):
|
||||
# Load maoin configuration
|
||||
config = LOLLMSConfig.autoload(lollms_paths)
|
||||
|
||||
super().__init__("lollms-settings", config, lollms_paths)
|
||||
super().__init__("lollms-settings", config, lollms_paths, load_model=False)
|
||||
|
||||
if show_logo:
|
||||
self.menu.show_logo()
|
||||
|
Loading…
Reference in New Issue
Block a user