Enhanced ui advanced the new fastapi version

This commit is contained in:
Saifeddine ALOUI 2024-01-07 03:18:13 +01:00
parent df046b0758
commit a8b2eaf1b3
17 changed files with 1653 additions and 169 deletions

View File

@ -19,7 +19,7 @@ from lollms.paths import LollmsPaths
from lollms.helpers import ASCIIColors, trace_exception
from lollms.com import NotificationType, NotificationDisplayType, LoLLMsCom
from lollms.app import LollmsApplication
from lollms.utilities import File64BitsManager, PromptReshaper, PackageManager, find_first_available_file_index
from lollms.utilities import File64BitsManager, PromptReshaper, PackageManager, find_first_available_file_index, terminate_thread
try:
from lollms.media import WebcamImageSender, AudioRecorder
Media_on=True
@ -56,22 +56,7 @@ from bs4 import BeautifulSoup
def terminate_thread(thread):
if thread:
if not thread.is_alive():
ASCIIColors.yellow("Thread not alive")
return
thread_id = thread.ident
exc = ctypes.py_object(SystemExit)
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, exc)
if res > 1:
ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, None)
del thread
gc.collect()
raise SystemError("Failed to terminate the thread.")
else:
ASCIIColors.yellow("Canceled successfully")
__author__ = "parisneo"
__github__ = "https://github.com/ParisNeo/lollms-webui"

189
app.py
View File

@ -249,12 +249,8 @@ try:
# Endpoints
# =========================================================================================
self.add_endpoint(
"/get_current_personality_files_list", "get_current_personality_files_list", self.get_current_personality_files_list, methods=["GET"]
)
self.add_endpoint(
"/clear_personality_files_list", "clear_personality_files_list", self.clear_personality_files_list, methods=["GET"]
)
self.add_endpoint("/get_current_personality_files_list", "get_current_personality_files_list", self.get_current_personality_files_list, methods=["GET"])
self.add_endpoint("/clear_personality_files_list", "clear_personality_files_list", self.clear_personality_files_list, methods=["GET"])
self.add_endpoint("/start_training", "start_training", self.start_training, methods=["POST"])
self.add_endpoint("/get_lollms_version", "get_lollms_version", self.get_lollms_version, methods=["GET"])
@ -307,53 +303,59 @@ try:
self.add_endpoint("/list_databases", "list_databases", self.list_databases, methods=["GET"])
self.add_endpoint("/select_database", "select_database", self.select_database, methods=["POST"])
self.add_endpoint("/uploads/<path:filename>", "serve_uploads", self.serve_uploads, methods=["GET"])
self.add_endpoint("/<path:filename>", "serve_static", self.serve_static, methods=["GET"])
self.add_endpoint("/user_infos/<path:filename>", "serve_user_infos", self.serve_user_infos, methods=["GET"])
self.add_endpoint("/bindings/<path:filename>", "serve_bindings", self.serve_bindings, methods=["GET"])
self.add_endpoint("/personalities/<path:filename>", "serve_personalities", self.serve_personalities, methods=["GET"])
self.add_endpoint("/extensions/<path:filename>", "serve_extensions", self.serve_extensions, methods=["GET"])
self.add_endpoint("/outputs/<path:filename>", "serve_outputs", self.serve_outputs, methods=["GET"])
self.add_endpoint("/data/<path:filename>", "serve_data", self.serve_data, methods=["GET"])
self.add_endpoint("/help/<path:filename>", "serve_help", self.serve_help, methods=["GET"])
self.add_endpoint("/audio/<path:filename>", "serve_audio", self.serve_audio, methods=["GET"])
self.add_endpoint("/images/<path:filename>", "serve_images", self.serve_images, methods=["GET"])
# ----
self.add_endpoint("/install_extension", "install_extension", self.install_extension, methods=["POST"])
self.add_endpoint("/reinstall_extension", "reinstall_extension", self.reinstall_extension, methods=["POST"])
self.add_endpoint("/mount_extension", "mount_extension", self.p_mount_extension, methods=["POST"])
self.add_endpoint("/remount_extension", "remount_extension", self.p_remount_extension, methods=["POST"])
self.add_endpoint("/unmount_extension", "unmount_extension", self.p_unmount_extension, methods=["POST"])
self.add_endpoint("/list_extensions_categories", "list_extensions_categories", self.list_extensions_categories, methods=["GET"])
self.add_endpoint("/list_extensions", "list_extensions", self.list_extensions, methods=["GET"])
self.add_endpoint("/get_all_extensions", "get_all_extensions", self.get_all_extensions, methods=["GET"])
self.add_endpoint("/list_discussions", "list_discussions", self.list_discussions, methods=["GET"])
# ----
self.add_endpoint("/switch_personal_path", "switch_personal_path", self.switch_personal_path, methods=["POST"])
self.add_endpoint("/upload_avatar", "upload_avatar", self.upload_avatar, methods=["POST"])
self.add_endpoint(
"/list_extensions_categories", "list_extensions_categories", self.list_extensions_categories, methods=["GET"]
)
self.add_endpoint(
"/list_extensions", "list_extensions", self.list_extensions, methods=["GET"]
)
self.add_endpoint(
"/list_discussions", "list_discussions", self.list_discussions, methods=["GET"]
)
self.add_endpoint("/", "", self.index, methods=["GET"])
self.add_endpoint("/settings/", "", self.index, methods=["GET"])
self.add_endpoint("/playground/", "", self.index, methods=["GET"])
self.add_endpoint("/<path:filename>", "serve_static", self.serve_static, methods=["GET"])
self.add_endpoint("/user_infos/<path:filename>", "serve_user_infos", self.serve_user_infos, methods=["GET"])
self.add_endpoint("/audio/<path:filename>", "serve_audio", self.serve_audio, methods=["GET"])
self.add_endpoint("/images/<path:filename>", "serve_images", self.serve_images, methods=["GET"])
self.add_endpoint("/extensions/<path:filename>", "serve_extensions", self.serve_extensions, methods=["GET"])
self.add_endpoint("/bindings/<path:filename>", "serve_bindings", self.serve_bindings, methods=["GET"])
self.add_endpoint("/personalities/<path:filename>", "serve_personalities", self.serve_personalities, methods=["GET"])
self.add_endpoint("/outputs/<path:filename>", "serve_outputs", self.serve_outputs, methods=["GET"])
self.add_endpoint("/data/<path:filename>", "serve_data", self.serve_data, methods=["GET"])
self.add_endpoint("/help/<path:filename>", "serve_help", self.serve_help, methods=["GET"])
self.add_endpoint("/uploads/<path:filename>", "serve_uploads", self.serve_uploads, methods=["GET"])
self.add_endpoint("/export_discussion", "export_discussion", self.export_discussion, methods=["GET"])
@ -1347,8 +1349,13 @@ try:
print(f"Couldn't load backend card : {f}\n\t{ex}")
return jsonify(bindings)
def get_extensions(self):
ASCIIColors.yellow("Listing all extensions")
def list_extensions(self):
return self.config.extensions
def get_all_extensions(self):
ASCIIColors.yellow("Gatting all extensions")
extensions_folder = self.lollms_paths.extensions_zoo_path
extensions = {}
@ -1415,12 +1422,7 @@ try:
except Exception as ex:
ASCIIColors.warning(f"Couldn't load personality from {extensions_folder} [{ex}]")
trace_exception(ex)
return extensions
def list_extensions(self):
return json.dumps(self.get_extensions())
return extensions
def list_models(self):
if self.binding is not None:
@ -1520,10 +1522,6 @@ try:
return jsonify({"status":True})
def list_extensions_categories(self):
extensions_categories_dir = self.lollms_paths.extensions_zoo_path # replace with the actual path to the models folder
extensions_categories = [f.stem for f in extensions_categories_dir.iterdir() if f.is_dir() and not f.name.startswith(".")]
return jsonify(extensions_categories)
def list_discussions(self):
@ -1687,41 +1685,7 @@ try:
})
def reinstall_extension(self):
try:
data = request.get_json()
# Further processing of the data
except Exception as e:
print(f"Error occurred while parsing JSON: {e}")
return jsonify({"status":False, 'error':str(e)})
if not 'name' in data.keys():
try:
data['name']=self.config.extensions[-1]
except Exception as ex:
self.error(ex)
return
try:
extension_path = self.lollms_paths.extensions_zoo_path / data['name']
ASCIIColors.info(f"- Reinstalling extension {data['name']}...")
ASCIIColors.info("Unmounting extension")
if data['name'] in self.config.extensions:
idx = self.config.extensions.index(data['name'])
print(f"index = {idx}")
if len(self.mount_extensions)>idx:
del self.mounted_extensions[idx]
gc.collect()
try:
self.mounted_extensions.append(ExtensionBuilder().build_extension(extension_path,self.lollms_paths, self, InstallOption.FORCE_INSTALL))
return jsonify({"status":True})
except Exception as ex:
ASCIIColors.error(f"Extension file not found or is corrupted ({data['name']}).\nReturned the following exception:{ex}\nPlease verify that the personality you have selected exists or select another personality. Some updates may lead to change in personality name or category, so check the personality selection in settings to be sure.")
trace_exception(ex)
ASCIIColors.info("Trying to force reinstall")
return jsonify({"status":False, 'error':str(e)})
except Exception as e:
return jsonify({"status":False, 'error':str(e)})
def reinstall_personality(self):
try:
data = request.get_json()
@ -2189,7 +2153,70 @@ try:
else:
return jsonify({'status':False})
def install_extension(self):
try:
data = request.get_json()
# Further processing of the data
except Exception as e:
print(f"Error occurred while parsing JSON: {e}")
return jsonify({"status":False, 'error':str(e)})
if not 'name' in data.keys():
try:
data['name']=self.config.extensions[-1]
except Exception as ex:
self.error(ex)
return
try:
extension_path = self.lollms_paths.extensions_zoo_path / data['name']
ASCIIColors.info(f"- Installing extension {data['name']}...")
try:
self.mounted_extensions.append(ExtensionBuilder().build_extension(extension_path,self.lollms_paths, self, InstallOption.FORCE_INSTALL))
return jsonify({"status":True})
except Exception as ex:
ASCIIColors.error(f"Extension file not found or is corrupted ({data['name']}).\nReturned the following exception:{ex}\nPlease verify that the personality you have selected exists or select another personality. Some updates may lead to change in personality name or category, so check the personality selection in settings to be sure.")
trace_exception(ex)
ASCIIColors.info("Trying to force reinstall")
return jsonify({"status":False, 'error':str(e)})
except Exception as e:
return jsonify({"status":False, 'error':str(e)})
def reinstall_extension(self):
try:
data = request.get_json()
# Further processing of the data
except Exception as e:
print(f"Error occurred while parsing JSON: {e}")
return jsonify({"status":False, 'error':str(e)})
if not 'name' in data.keys():
try:
data['name']=self.config.extensions[-1]
except Exception as ex:
self.error(ex)
return
try:
extension_path = self.lollms_paths.extensions_zoo_path / data['name']
ASCIIColors.info(f"- Reinstalling extension {data['name']}...")
ASCIIColors.info("Unmounting extension")
if data['name'] in self.config.extensions:
idx = self.config.extensions.index(data['name'])
print(f"index = {idx}")
if len(self.mount_extensions)>idx:
del self.mounted_extensions[idx]
gc.collect()
try:
self.mounted_extensions.append(ExtensionBuilder().build_extension(extension_path,self.lollms_paths, self, InstallOption.FORCE_INSTALL))
return jsonify({"status":True})
except Exception as ex:
ASCIIColors.error(f"Extension file not found or is corrupted ({data['name']}).\nReturned the following exception:{ex}\nPlease verify that the personality you have selected exists or select another personality. Some updates may lead to change in personality name or category, so check the personality selection in settings to be sure.")
trace_exception(ex)
ASCIIColors.info("Trying to force reinstall")
return jsonify({"status":False, 'error':str(e)})
except Exception as e:
return jsonify({"status":False, 'error':str(e)})
def p_mount_extension(self):
print("- Mounting extension")
@ -2304,7 +2331,13 @@ try:
ASCIIColors.yellow(f"Available personalities: {[p.name for p in self.mounted_personalities]}")
return jsonify({"status": False, "error":"Couldn't unmount personality"})
def list_extensions_categories(self):
extensions_categories_dir = self.lollms_paths.extensions_zoo_path # replace with the actual path to the models folder
extensions_categories = [f.stem for f in extensions_categories_dir.iterdir() if f.is_dir() and not f.name.startswith(".")]
return jsonify(extensions_categories)
def set_active_binding_settings(self):
print("- Setting binding settings")
try:

View File

@ -83,4 +83,4 @@ def select_database(data:DatabaseSelectionParameters):
lollmsElfServer.error(f"Couldn't vectorize the database:{ex}")
return {"status":False}
return {"status":True}
return {"status":True}

View File

@ -0,0 +1,108 @@
"""
project: lollms
file: lollms_discussion_events.py
author: ParisNeo
description:
This module contains a set of Socketio routes that provide information about the Lord of Large Language and Multimodal Systems (LoLLMs) Web UI
application. These routes are specific to discussion operation
"""
from fastapi import APIRouter, Request
from fastapi import HTTPException
from pydantic import BaseModel
import pkg_resources
from lollms.server.elf_server import LOLLMSElfServer
from fastapi.responses import FileResponse
from lollms.binding import BindingBuilder, InstallOption
from ascii_colors import ASCIIColors
from lollms.personality import MSG_TYPE, AIPersonality
from lollms.types import MSG_TYPE, SENDER_TYPES
from lollms.utilities import load_config, trace_exception, gc
from lollms.utilities import find_first_available_file_index, convert_language_name
from lollms_webui import LOLLMSWebUI
from pathlib import Path
from typing import List
import socketio
import threading
import os
from api.db import Discussion
from datetime import datetime
router = APIRouter()
lollmsElfServer = LOLLMSWebUI.get_instance()
# ----------------------------------- events -----------------------------------------
def add_events(sio:socketio):
@sio.on('new_discussion')
async def new_discussion(sid, environ, data):
ASCIIColors.yellow("New descussion requested")
client_id = sid
title = data["title"]
if lollmsElfServer.connections[client_id]["current_discussion"] is not None:
if lollmsElfServer.long_term_memory is not None:
title, content = lollmsElfServer.connections[client_id]["current_discussion"].export_for_vectorization()
skill = lollmsElfServer.learn_from_discussion(title, content)
lollmsElfServer.long_term_memory.add_document(title, skill, chunk_size=lollmsElfServer.config.data_vectorization_chunk_size, overlap_size=lollmsElfServer.config.data_vectorization_overlap_size, force_vectorize=False, add_as_a_bloc=False, add_to_index=True)
ASCIIColors.yellow("4- Saving database")
lollmsElfServer.long_term_memory.save_to_json()
lollmsElfServer.connections[client_id]["current_discussion"] = lollmsElfServer.db.create_discussion(title)
# Get the current timestamp
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Return a success response
if lollmsElfServer.connections[client_id]["current_discussion"] is None:
lollmsElfServer.connections[client_id]["current_discussion"] = lollmsElfServer.db.load_last_discussion()
if lollmsElfServer.personality.welcome_message!="":
if lollmsElfServer.config.force_output_language_to_be and lollmsElfServer.config.force_output_language_to_be.lower().strip() !="english":
welcome_message = lollmsElfServer.personality.fast_gen(f"!@>instruction: Translate the following text to {lollmsElfServer.config.force_output_language_to_be.lower()}:\n{lollmsElfServer.personality.welcome_message}\n!@>translation:")
else:
welcome_message = lollmsElfServer.personality.welcome_message
message = lollmsElfServer.connections[client_id]["current_discussion"].add_message(
message_type = MSG_TYPE.MSG_TYPE_FULL.value if lollmsElfServer.personality.include_welcome_message_in_disucssion else MSG_TYPE.MSG_TYPE_FULL_INVISIBLE_TO_AI.value,
sender_type = SENDER_TYPES.SENDER_TYPES_AI.value,
sender = lollmsElfServer.personality.name,
content = welcome_message,
metadata = None,
rank = 0,
parent_message_id = -1,
binding = lollmsElfServer.config.binding_name,
model = lollmsElfServer.config.model_name,
personality = lollmsElfServer.config.personalities[lollmsElfServer.config.active_personality_id],
created_at=None,
finished_generating_at=None
)
await lollmsElfServer.socketio.emit('discussion_created',
{'id':lollmsElfServer.connections[client_id]["current_discussion"].discussion_id},
to=client_id
)
else:
await lollmsElfServer.socketio.emit('discussion_created',
{'id':0},
to=client_id
)
@sio.on('load_discussion')
async def load_discussion(sid, data):
client_id = sid
ASCIIColors.yellow(f"Loading discussion for client {client_id} ... ", end="")
if "id" in data:
discussion_id = data["id"]
lollmsElfServer.connections[client_id]["current_discussion"] = Discussion(discussion_id, lollmsElfServer.db)
else:
if lollmsElfServer.connections[client_id]["current_discussion"] is not None:
discussion_id = lollmsElfServer.connections[client_id]["current_discussion"].discussion_id
lollmsElfServer.connections[client_id]["current_discussion"] = Discussion(discussion_id, lollmsElfServer.db)
else:
lollmsElfServer.connections[client_id]["current_discussion"] = lollmsElfServer.db.create_discussion()
messages = lollmsElfServer.connections[client_id]["current_discussion"].get_messages()
jsons = [m.to_json() for m in messages]
await lollmsElfServer.socketio.emit('discussion',
jsons,
to=client_id
)
ASCIIColors.green(f"ok")

View File

@ -0,0 +1,123 @@
"""
project: lollms
file: lollms_generation_events.py
author: ParisNeo
description:
This module contains a set of Socketio routes that provide information about the Lord of Large Language and Multimodal Systems (LoLLMs) Web UI
application. These routes are specific to text generation operation
"""
from fastapi import APIRouter, Request
from fastapi import HTTPException
from pydantic import BaseModel
import pkg_resources
from lollms.server.elf_server import LOLLMSElfServer
from fastapi.responses import FileResponse
from lollms.binding import BindingBuilder, InstallOption
from ascii_colors import ASCIIColors
from lollms.personality import MSG_TYPE, AIPersonality
from lollms.types import MSG_TYPE, SENDER_TYPES
from lollms.utilities import load_config, trace_exception, gc
from lollms.utilities import find_first_available_file_index, convert_language_name
from lollms_webui import LOLLMSWebUI
from pathlib import Path
from typing import List
import socketio
import threading
import os
router = APIRouter()
lollmsElfServer = LOLLMSWebUI.get_instance()
# ----------------------------------- events -----------------------------------------
def add_events(sio:socketio):
@sio.on('generate_msg')
def handle_generate_msg(sid, environ, data):
client_id = sid
lollmsElfServer.cancel_gen = False
lollmsElfServer.connections[client_id]["generated_text"]=""
lollmsElfServer.connections[client_id]["cancel_generation"]=False
lollmsElfServer.connections[client_id]["continuing"]=False
lollmsElfServer.connections[client_id]["first_chunk"]=True
if not lollmsElfServer.model:
ASCIIColors.error("Model not selected. Please select a model")
lollmsElfServer.error("Model not selected. Please select a model", client_id=client_id)
return
if not lollmsElfServer.busy:
if lollmsElfServer.connections[client_id]["current_discussion"] is None:
if lollmsElfServer.db.does_last_discussion_have_messages():
lollmsElfServer.connections[client_id]["current_discussion"] = lollmsElfServer.db.create_discussion()
else:
lollmsElfServer.connections[client_id]["current_discussion"] = lollmsElfServer.db.load_last_discussion()
prompt = data["prompt"]
ump = lollmsElfServer.config.discussion_prompt_separator +lollmsElfServer.config.user_name.strip() if lollmsElfServer.config.use_user_name_in_discussions else lollmsElfServer.personality.user_message_prefix
message = lollmsElfServer.connections[client_id]["current_discussion"].add_message(
message_type = MSG_TYPE.MSG_TYPE_FULL.value,
sender_type = SENDER_TYPES.SENDER_TYPES_USER.value,
sender = ump.replace(lollmsElfServer.config.discussion_prompt_separator,"").replace(":",""),
content=prompt,
metadata=None,
parent_message_id=lollmsElfServer.message_id
)
ASCIIColors.green("Starting message generation by "+lollmsElfServer.personality.name)
lollmsElfServer.connections[client_id]['generation_thread'] = threading.Thread(target=lollmsElfServer.start_message_generation, args=(message, message.id, client_id))
lollmsElfServer.connections[client_id]['generation_thread'].start()
lollmsElfServer.socketio.sleep(0.01)
ASCIIColors.info("Started generation task")
lollmsElfServer.busy=True
#tpe = threading.Thread(target=lollmsElfServer.start_message_generation, args=(message, message_id, client_id))
#tpe.start()
else:
lollmsElfServer.error("I am busy. Come back later.", client_id=client_id)
@sio.on('generate_msg_from')
def handle_generate_msg_from(sid, environ, data):
client_id = sid
lollmsElfServer.cancel_gen = False
lollmsElfServer.connections[client_id]["continuing"]=False
lollmsElfServer.connections[client_id]["first_chunk"]=True
if lollmsElfServer.connections[client_id]["current_discussion"] is None:
ASCIIColors.warning("Please select a discussion")
lollmsElfServer.error("Please select a discussion first", client_id=client_id)
return
id_ = data['id']
generation_type = data.get('msg_type',None)
if id_==-1:
message = lollmsElfServer.connections[client_id]["current_discussion"].current_message
else:
message = lollmsElfServer.connections[client_id]["current_discussion"].load_message(id_)
if message is None:
return
lollmsElfServer.connections[client_id]['generation_thread'] = threading.Thread(target=lollmsElfServer.start_message_generation, args=(message, message.id, client_id, False, generation_type))
lollmsElfServer.connections[client_id]['generation_thread'].start()
@sio.on('continue_generate_msg_from')
def handle_continue_generate_msg_from(sid, environ, data):
client_id = sid
lollmsElfServer.cancel_gen = False
lollmsElfServer.connections[client_id]["continuing"]=True
lollmsElfServer.connections[client_id]["first_chunk"]=True
if lollmsElfServer.connections[client_id]["current_discussion"] is None:
ASCIIColors.yellow("Please select a discussion")
lollmsElfServer.error("Please select a discussion", client_id=client_id)
return
id_ = data['id']
if id_==-1:
message = lollmsElfServer.connections[client_id]["current_discussion"].current_message
else:
message = lollmsElfServer.connections[client_id]["current_discussion"].load_message(id_)
lollmsElfServer.connections[client_id]["generated_text"]=message.content
lollmsElfServer.connections[client_id]['generation_thread'] = threading.Thread(target=lollmsElfServer.start_message_generation, args=(message, message.id, client_id, True))
lollmsElfServer.connections[client_id]['generation_thread'].start()

@ -1 +1 @@
Subproject commit 9d8db7a0da156287f325adf0971cf0f5bce07b5e
Subproject commit 5a16ba20be506145a791754c36eef7ab71eda6e0

File diff suppressed because it is too large Load Diff

View File

@ -25,10 +25,6 @@ app = FastAPI()
# Create a Socket.IO server
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*") # Enable CORS for all origins
# Define a WebSocket event handler
@sio.event
async def connect(sid, environ):
ASCIIColors.yellow(f"Connected: {sid}")
@sio.event
async def disconnect(sid):
@ -61,27 +57,45 @@ if __name__ == "__main__":
config.port=args.port
LOLLMSWebUI.build_instance(config=config, lollms_paths=lollms_paths, socketio=sio)
lollmsElfServer = LOLLMSWebUI.get_instance()
# Import all endpoints
from lollms.server.endpoints.lollms_binding_files_server import router as lollms_binding_files_server_router
from lollms.server.endpoints.lollms_infos import router as lollms_infos_router
from lollms.server.endpoints.lollms_hardware_infos import router as lollms_hardware_infos_router
from lollms.server.endpoints.lollms_binding_infos import router as lollms_binding_infos_router
from lollms.server.endpoints.lollms_models_infos import router as lollms_models_infos_router
from lollms.server.endpoints.lollms_personalities_infos import router as lollms_personalities_infos_router
from lollms.server.endpoints.lollms_extensions_infos import router as lollms_extensions_infos_router
from lollms.server.endpoints.lollms_generator import router as lollms_generator_router
from lollms.server.endpoints.lollms_configuration_infos import router as lollms_configuration_infos_router
from endpoints.lollms_discussion import router as lollms_discussion_router
from endpoints.lollms_webui_infos import router as lollms_webui_infos_router
from lollms.server.events.lollms_generation_events import add_events as lollms_generation_events_add
from events.lollms_generation_events import add_events as lollms_webui_generation_events_add
from events.lollms_discussion_events import add_events as lollms_webui_discussion_events_add
app.include_router(lollms_infos_router)
app.include_router(lollms_binding_files_server_router)
app.include_router(lollms_hardware_infos_router)
app.include_router(lollms_binding_infos_router)
app.include_router(lollms_models_infos_router)
app.include_router(lollms_personalities_infos_router)
app.include_router(lollms_extensions_infos_router)
app.include_router(lollms_webui_infos_router)
app.include_router(lollms_generator_router)
app.include_router(lollms_discussion_router)
app.include_router(lollms_configuration_infos_router)
lollms_generation_events_add(sio)
lollms_webui_generation_events_add(sio)
lollms_webui_discussion_events_add(sio)
app.mount("/", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="static")
app = ASGIApp(socketio_server=sio, other_asgi_app=app)

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
<script type="module" crossorigin src="/assets/index-26HIjSQ3.js"></script>
<script type="module" crossorigin src="/assets/index-tXzDSVtv.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-uMQcfNrh.css">
</head>
<body>

View File

@ -0,0 +1,25 @@
// Project : lollms-webui
// Author : ParisNeo
// Description :
// All websocket stuff can be found here.
// More info can be found here https://socket.io/how-to/use-with-vue
// import { createApp } from 'vue';
import io from 'socket.io-client';
// fixes issues when people not hosting this site on local network
const URL = window.location.origin;
console.log(URL);
const socket = new io(URL, {
reconnection: true, // Enable reconnection
reconnectionAttempts: 10, // Maximum reconnection attempts
reconnectionDelay: 1000, // Delay between reconnection attempts (in milliseconds)
});
// const app = createApp(/* your root component */);
// app.config.globalProperties.$socket = socket;
// app.mount(/* your root element */);
export default socket;

View File

@ -69,21 +69,16 @@ export default {
};
},
async mounted(){
this.personal_path = await axios.get("/get_personal_path")
socket.on('notification', this.notify)
let response = await axios.get("/get_personal_path")
this.personal_path = response.data
console.log(this.personal_path)
//socket.on('notification', this.notify)
},
components:{
MessageBox,
Toast
},
methods: {
folderSelected(event) {
const files = event.target.files;
for (let i = 0; i < files.length; i++) {
console.log(files[i].webkitRelativePath);
}
personal_path = files[0].webkitRelativePath
},
notify(notif){
self.isGenerating = false
this.setDiscussionLoading(this.currentDiscussion.id, this.isGenerating);
@ -118,15 +113,6 @@ export default {
this.$refs.messageBox.showMessage("Success!\nPlease close this page and open the run script from your install folder")
});
},
selectFolder() {
axios.get('/choose_path')
.then(response => {
this.personal_path = response.data.new_path;
})
.catch(error => {
console.error(error);
});
},
},
};
</script>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
web/dist/index.html vendored
View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LoLLMS WebUI - Welcome</title>
<script type="module" crossorigin src="/assets/index-be733980.js"></script>
<link rel="stylesheet" href="/assets/index-0b72f569.css">
<script type="module" crossorigin src="/assets/index-c332aeeb.js"></script>
<link rel="stylesheet" href="/assets/index-a5ef9055.css">
</head>
<body>
<div id="app"></div>

View File

@ -1684,15 +1684,15 @@
</select>
</div>
<div>
<div v-if="extensionsFiltererd.length > 0" class="mb-2">
<div v-if="extensionsFiltered.length > 0" class="mb-2">
<label for="model" class="block ml-2 mb-2 text-sm font-medium text-gray-900 dark:text-white">
{{ searchExtension ? 'Search results' : 'Personalities' }}: ({{
extensionsFiltererd.length
extensionsFiltered.length
}})
</label>
<div class="overflow-y-auto no-scrollbar p-2 pb-0 grid lg:grid-cols-3 md:grid-cols-2 gap-4"
:class="ezl_collapsed ? '' : 'max-h-96'">
<ExtensionEntry ref="extensionsZoo" v-for="(ext, index) in extensionsFiltererd"
<ExtensionEntry ref="extensionsZoo" v-for="(ext, index) in extensionsFiltered"
:key="'index-' + index + '-' + ext.name"
:extension="ext"
:select_language="true"
@ -2112,7 +2112,7 @@ export default {
// Zoo stuff
personalitiesFiltered: [],
modelsFiltered: [],
extensionsFiltererd: [],
extensionsFiltered: [],
// Accordeon stuff
collapsedArr: [],
all_collapsed: true,
@ -2420,7 +2420,7 @@ export default {
//mountedPersArr
this.modelsFiltered = []
this.extension_category = this.configFile.extension_category
this.extensionsFiltererd = this.$store.state.extensionsZoo.filter((item) => item.category === this.configFile.extension_category )
this.extensionsFiltered = this.$store.state.extensionsZoo.filter((item) => item.category === this.configFile.extension_category )
this.updateModelsZoo();
@ -3206,9 +3206,9 @@ export default {
this.extCatgArr = cats
console.log("this.$store.state.extensionsZoo",this.$store.state.extensionsZoo)
console.log("this.extension_category", this.extension_category)
this.extensionsFiltererd = this.$store.state.extensionsZoo.filter((item) => item.category === this.extension_category)
this.extensionsFiltererd.sort()
console.log("this.extensionsFiltererd", this.extensionsFiltererd)
this.extensionsFiltered = this.$store.state.extensionsZoo.filter((item) => item.category === this.extension_category)
this.extensionsFiltered.sort()
console.log("this.extensionsFiltered", this.extensionsFiltered)
})
@ -3521,7 +3521,7 @@ export default {
const catkeys = Object.keys(dictionary); // returns categories folder names
for (let j = 0; j < catkeys.length; j++) {
const catkey = catkeys[j];
const personalitiesArray = catdictionary[catkey];
const personalitiesArray = dictionary[catkey];
const modPersArr = personalitiesArray.map((item) => {
const isMounted = config.personalities.includes(catkey + '/' + item.folder)
@ -3531,7 +3531,7 @@ export default {
let newItem = {}
newItem = item
newItem.category = catkey // add new props to items
newItem.language = langkey // add new props to items
newItem.language = "" // add new props to items
newItem.full_path = catkey + '/' + item.folder // add new props to items
newItem.isMounted = isMounted // add new props to items
return newItem
@ -3552,6 +3552,48 @@ export default {
this.isLoading = false
},
async getExtensionsArr() {
this.isLoading = true
this.extensions = []
const dictionary = await this.api_get_req("get_all_extensions")
const config = this.$store.state.config
//console.log('asdas',config)
// console.log("all_extensions")
// console.log(dictionary)
const catkeys = Object.keys(dictionary); // returns categories folder names
for (let j = 0; j < catkeys.length; j++) {
const catkey = catkeys[j];
const extensionsArray = dictionary[catkey];
const modPersArr = extensionsArray.map((item) => {
const isMounted = config.extensions.includes(catkey + '/' + item.folder)
// if (isMounted) {
// console.log(item)
// }
let newItem = {}
newItem = item
newItem.category = catkey // add new props to items
newItem.language = "" // add new props to items
newItem.full_path = catkey + '/' + item.folder // add new props to items
newItem.isMounted = isMounted // add new props to items
return newItem
})
if (this.extensions.length == 0) {
this.extensions = modPersArr
} else {
this.extensions = this.extensions.concat(modPersArr)
}
}
this.extensions.sort((a, b) => a.name.localeCompare(b.name))
this.extensions = this.extensions.filter((item) => item.category === this.configFile.personality_category)
this.extensions.sort()
console.log('per filtered', this.extensionsFiltered)
this.isLoading = false
},
async filterPersonalities() {
if (!this.searchPersonality) {
this.personalitiesFiltered = this.personalities.filter((item) => item.category === this.configFile.personality_category )

@ -1 +1 @@
Subproject commit f8b842aa288c92807a31a335fe4dbdbf13a91c41
Subproject commit fa9c3d4877892ed901f1a9c7d98f140263689190