mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2025-02-21 01:31:20 +00:00
Working dev version
This commit is contained in:
parent
20ed2218c0
commit
25c2c2aa45
@ -19,6 +19,7 @@ from lollms.personality import AIPersonality, PersonalityBuilder
|
||||
from lollms.binding import LOLLMSConfig, BindingBuilder, LLMBinding, ModelBuilder
|
||||
from lollms.paths import LollmsPaths
|
||||
from lollms.helpers import ASCIIColors
|
||||
from lollms.app import LollmsApplication
|
||||
import multiprocessing as mp
|
||||
import threading
|
||||
import time
|
||||
@ -89,39 +90,13 @@ def parse_requirements_file(requirements_path):
|
||||
# ===========================================================
|
||||
|
||||
|
||||
class LoLLMsAPPI():
|
||||
class LoLLMsAPPI(LollmsApplication):
|
||||
def __init__(self, config:LOLLMSConfig, socketio, config_file_path:str, lollms_paths: LollmsPaths) -> None:
|
||||
self.lollms_paths = lollms_paths
|
||||
self.config = config
|
||||
self.is_ready = True
|
||||
self.menu = MainMenu(self)
|
||||
|
||||
super().__init__("Lollms_webui",config, lollms_paths)
|
||||
self.is_ready = True
|
||||
|
||||
self.socketio = socketio
|
||||
# Check model
|
||||
if config.binding_name is None:
|
||||
self.menu.select_binding()
|
||||
|
||||
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths)
|
||||
|
||||
# Check model
|
||||
if config.model_name is None:
|
||||
self.menu.select_model()
|
||||
|
||||
self.mounted_personalities = []
|
||||
try:
|
||||
self.model = self.binding.build_model()
|
||||
self.mounted_personalities = self.rebuild_personalities()
|
||||
if self.config["active_personality_id"]<len(self.mounted_personalities):
|
||||
self.personality:AIPersonality = self.mounted_personalities[self.config["active_personality_id"]]
|
||||
else:
|
||||
self.personality:AIPersonality = None
|
||||
if config["debug"]:
|
||||
print(print(f"{self.personality}"))
|
||||
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Couldn't load model:\nException generated:{ex}")
|
||||
self.model = None
|
||||
self.config_file_path = config_file_path
|
||||
self.cancel_gen = False
|
||||
|
||||
@ -530,46 +505,6 @@ class LoLLMsAPPI():
|
||||
return mounted_personalities
|
||||
# ================================== LOLLMSApp
|
||||
|
||||
def load_binding(self):
|
||||
if self.config.binding_name is None:
|
||||
print(f"No bounding selected")
|
||||
print("Please select a valid model or install a new one from a url")
|
||||
self.menu.select_binding()
|
||||
# cfg.download_model(url)
|
||||
else:
|
||||
try:
|
||||
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths)
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
print(f"Couldn't find binding. Please verify your configuration file at {self.config.file_path} or use the next menu to select a valid binding")
|
||||
print(f"Trying to reinstall binding")
|
||||
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, InstallOption.FORCE_INSTALL)
|
||||
self.menu.select_binding()
|
||||
|
||||
def load_model(self):
|
||||
try:
|
||||
self.active_model = ModelBuilder(self.binding).get_model()
|
||||
ASCIIColors.success("Model loaded successfully")
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Couldn't load model.")
|
||||
ASCIIColors.error(f"Binding returned this 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")
|
||||
self.menu.select_model()
|
||||
|
||||
def load_personality(self):
|
||||
try:
|
||||
self.personality = PersonalityBuilder(self.lollms_paths, self.config, self.model).build_personality()
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Couldn't load personality.")
|
||||
ASCIIColors.error(f"Binding returned this exception : {ex}")
|
||||
ASCIIColors.error(f"{self.config.get_personality_path_infos()}")
|
||||
print("Please select a valid model or install a new one from a url")
|
||||
self.menu.select_model()
|
||||
self.cond_tk = self.personality.model.tokenize(self.personality.personality_conditioning)
|
||||
self.n_cond_tk = len(self.cond_tk)
|
||||
|
||||
|
||||
#properties
|
||||
@property
|
||||
def message_id(self):
|
||||
@ -756,7 +691,6 @@ class LoLLMsAPPI():
|
||||
anti_prompt_to_remove = prompt.lower()
|
||||
|
||||
if not detected_anti_prompt:
|
||||
ASCIIColors.green(f"generated:{len(self.current_generated_text.split())} words", end='\r', flush=True)
|
||||
self.socketio.emit('message', {
|
||||
'data': self.current_generated_text,
|
||||
'user_message_id':self.current_user_message_id,
|
||||
|
52
app.py
52
app.py
@ -92,17 +92,28 @@ def get_ip_address():
|
||||
|
||||
class LoLLMsWebUI(LoLLMsAPPI):
|
||||
def __init__(self, _app, _socketio, config:LOLLMSConfig, config_file_path:Path|str, lollms_paths:LollmsPaths) -> None:
|
||||
if len(config.personalities)==0:
|
||||
config.personalities.append("english/generic/lollms")
|
||||
config["active_personality_id"] = 0
|
||||
config.save_config()
|
||||
|
||||
if config["active_personality_id"]>=len(config["personalities"]) or config["active_personality_id"]<0:
|
||||
config["active_personality_id"] = 0
|
||||
super().__init__(config, _socketio, config_file_path, lollms_paths)
|
||||
|
||||
self.app = _app
|
||||
self.cancel_gen = False
|
||||
|
||||
app.template_folder = "web/dist"
|
||||
if config["active_personality_id"]>=len(config["personalities"]):
|
||||
config["active_personality_id"] = 0
|
||||
self.personality_language= config["personalities"][config["active_personality_id"]].split("/")[0]
|
||||
self.personality_category= config["personalities"][config["active_personality_id"]].split("/")[1]
|
||||
self.personality_name= config["personalities"][config["active_personality_id"]].split("/")[2]
|
||||
|
||||
if len(config["personalities"])>0:
|
||||
self.personality_language= config["personalities"][config["active_personality_id"]].split("/")[0]
|
||||
self.personality_category= config["personalities"][config["active_personality_id"]].split("/")[1]
|
||||
self.personality_name= config["personalities"][config["active_personality_id"]].split("/")[2]
|
||||
else:
|
||||
self.personality_language = "english"
|
||||
self.personality_category = "generic"
|
||||
self.personality_name = "lollms"
|
||||
|
||||
# =========================================================================================
|
||||
# Endpoints
|
||||
@ -123,9 +134,11 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
||||
|
||||
|
||||
self.add_endpoint("/list_mounted_personalities", "list_mounted_personalities", self.list_mounted_personalities, methods=["POST"])
|
||||
self.add_endpoint("/mount_personality", "mount_personality", self.mount_personality, methods=["POST"])
|
||||
self.add_endpoint("/unmount_personality", "unmount_personality", self.unmount_personality, methods=["POST"])
|
||||
self.add_endpoint("/select_personality", "select_personality", self.select_personality, methods=["POST"])
|
||||
|
||||
self.add_endpoint("/mount_personality", "mount_personality", self.p_mount_personality, methods=["POST"])
|
||||
self.add_endpoint("/unmount_personality", "unmount_personality", self.p_unmount_personality, methods=["POST"])
|
||||
self.add_endpoint("/select_personality", "select_personality", self.p_select_personality, methods=["POST"])
|
||||
|
||||
self.add_endpoint("/get_personality_settings", "get_personality_settings", self.get_personality_settings, methods=["POST"])
|
||||
|
||||
self.add_endpoint("/get_active_personality_settings", "get_active_personality_settings", self.get_active_personality_settings, methods=["GET"])
|
||||
@ -872,7 +885,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
||||
return jsonify({"status":False, 'error':str(ex)})
|
||||
|
||||
|
||||
def mount_personality(self):
|
||||
def p_mount_personality(self):
|
||||
print("- Mounting personality")
|
||||
try:
|
||||
data = request.get_json()
|
||||
@ -908,7 +921,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
||||
ASCIIColors.error(f"nok : Personality not found @ {pth}")
|
||||
return jsonify({"status": False, "error":f"Personality not found @ {pth}"})
|
||||
|
||||
def unmount_personality(self):
|
||||
def p_unmount_personality(self):
|
||||
print("- Unmounting personality ...")
|
||||
try:
|
||||
data = request.get_json()
|
||||
@ -1050,7 +1063,7 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
||||
|
||||
|
||||
|
||||
def select_personality(self):
|
||||
def p_select_personality(self):
|
||||
|
||||
data = request.get_json()
|
||||
id = data['id']
|
||||
@ -1275,11 +1288,18 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
||||
return jsonify(self.config.to_dict())
|
||||
|
||||
def get_current_personality_path_infos(self):
|
||||
return jsonify({
|
||||
"personality_language":self.personality_language,
|
||||
"personality_category":self.personality_category,
|
||||
"personality_name":self.personality_name
|
||||
})
|
||||
if self.personality is None:
|
||||
return jsonify({
|
||||
"personality_language":"",
|
||||
"personality_category":"",
|
||||
"personality_name":""
|
||||
})
|
||||
else:
|
||||
return jsonify({
|
||||
"personality_language":self.personality_language,
|
||||
"personality_category":self.personality_category,
|
||||
"personality_name":self.personality_name
|
||||
})
|
||||
|
||||
def main(self):
|
||||
return render_template("main.html")
|
||||
|
Loading…
x
Reference in New Issue
Block a user