diff --git a/api/__init__.py b/api/__init__.py index 50e4d911..5002e483 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -1574,7 +1574,7 @@ class LoLLMsAPI(LollmsApplication): self.warning("Couldn't add long term memory information to the context. Please verify the vector database") # Add information about the user user_description="" if self.config.use_user_name_in_discussions: - user_description="!@>User description:\n"+self.config.user_description + user_description="!@>User description:\n"+self.config.user_description+"\n" # Tokenize the conditionning text and calculate its number of tokens @@ -1971,6 +1971,13 @@ class LoLLMsAPI(LollmsApplication): dt=1 spd = self.nb_received_tokens/dt ASCIIColors.green(f"Received {self.nb_received_tokens} tokens (speed: {spd:.2f}t/s) ",end="\r",flush=True) + antiprompt = self.personality.detect_antiprompt(self.connections[client_id]["generated_text"]) + if antiprompt: + ASCIIColors.warning(f"\nDetected hallucination with antiprompt: {antiprompt}") + self.connections[client_id]["generated_text"] = self.remove_text_from_string(self.connections[client_id]["generated_text"],antiprompt) + self.update_message(client_id, self.connections[client_id]["generated_text"], parameters, metadata, None, MSG_TYPE.MSG_TYPE_FULL) + return False + self.update_message(client_id, chunk, parameters, metadata, ui=None, msg_type=message_type) return True # Stream the generated text to the frontend @@ -1983,6 +1990,7 @@ class LoLLMsAPI(LollmsApplication): if self.personality.processor is not None: ASCIIColors.info("Running workflow") try: + self.personality.callback = callback self.personality.processor.run_workflow( prompt, full_prompt, callback) except Exception as ex: trace_exception(ex) diff --git a/app.py b/app.py index c05fc775..c273b4bc 100644 --- a/app.py +++ b/app.py @@ -1254,7 +1254,7 @@ try: ASCIIColors.green("PyTorch uninstalled successfully") reinstall_pytorch_with_cuda() ASCIIColors.yellow("Installing pytorch with cuda support") - self.config.enable_gpu=True + self.config.hardware_mode="nvidia-tensorcores" return jsonify({'status':res==0}) @@ -1992,7 +1992,7 @@ try: return jsonify({"state":True}) def start_training(self): - if self.config.enable_gpu: + if self.config.hardware_mode=="nvidia-tensorcores" or self.config.hardware_mode=="nvidia" or self.config.hardware_mode=="apple-intel" or self.config.hardware_mode=="apple-silicon": if not self.lollms_paths.gptqlora_path.exists(): # Clone the repository to the target path ASCIIColors.info("No gptqlora found in your personal space.\nCloning the gptqlora repo") @@ -2748,17 +2748,6 @@ try: if not user_avatar_path.exists(): # If the user avatar doesn't exist, copy the default avatar from the assets folder shutil.copy(default_user_avatar, user_avatar_path) - # executor = ThreadPoolExecutor(max_workers=1) - # app.config['executor'] = executor - # Check if .no_gpu file exists - no_gpu_file = Path('.no_gpu') - if no_gpu_file.exists(): - # If the file exists, change self.config.use_gpu to False - config.enable_gpu = False - config.save_config() - - # Remove the .no_gpu file - no_gpu_file.unlink() bot = LoLLMsWebUI(args, app, socketio, config, config.file_path, lollms_paths) diff --git a/configs/config.yaml b/configs/config.yaml index e3578976..fd5fc3c3 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -1,5 +1,5 @@ # =================== Lord Of Large Language Models Configuration file =========================== -version: 39 +version: 40 binding_name: null model_name: null @@ -44,8 +44,8 @@ debug: False auto_update: true auto_save: true auto_title: false -# Enables gpu usage -enable_gpu: true +# Install mode (cpu, cpu-noavx, nvidia-tensorcores, nvidia, amd-noavx, amd, apple-intel, apple-silicon) +hardware_mode: nvidia-tensorcores # Automatically open the browser auto_show_browser: true diff --git a/lollms_core b/lollms_core index c97a61a9..e77c97f2 160000 --- a/lollms_core +++ b/lollms_core @@ -1 +1 @@ -Subproject commit c97a61a9e2cd5f5107c5e4b1781fbfbec7fb129e +Subproject commit e77c97f2384e97de974cba4c580511b88ae71d2a diff --git a/lollms_webui.py b/lollms_webui.py index 8fc3a31a..5c603014 100644 --- a/lollms_webui.py +++ b/lollms_webui.py @@ -6,65 +6,36 @@ Description: Singleton class for the LoLLMS web UI. This class provides a singleton instance of the LoLLMS web UI, allowing access to its functionality and data across multiple endpoints. """ -from lollms.app import LollmsApplication +from lollms.server.elf_server import LOLLMSElfServer from lollms.main_config import LOLLMSConfig from lollms.paths import LollmsPaths -class LoLLMSWebUI(LollmsApplication): - __instance = None - - @staticmethod - def build_instance( - config: LOLLMSConfig, - lollms_paths: LollmsPaths, - load_binding=True, - load_model=True, - try_select_binding=False, - try_select_model=False, - callback=None, - socketio = None - ): - if LoLLMSWebUI.__instance is None: - LoLLMSWebUI( - config, - lollms_paths, - load_binding=load_binding, - load_model=load_model, - try_select_binding=try_select_binding, - try_select_model=try_select_model, - callback=callback, - socketio=socketio - ) - return LoLLMSWebUI.__instance - @staticmethod - def get_instance(): - return LoLLMSWebUI.__instance - +class LOLLMSWebUI(LOLLMSElfServer): def __init__( self, config: LOLLMSConfig, lollms_paths: LollmsPaths, load_binding=True, load_model=True, + load_voice_service=True, + load_sd_service=True, try_select_binding=False, try_select_model=False, callback=None, socketio=None ) -> None: super().__init__( - "LoLLMSWebUI", config, lollms_paths, load_binding=load_binding, load_model=load_model, + load_sd_service=load_sd_service, + load_voice_service=load_voice_service, try_select_binding=try_select_binding, try_select_model=try_select_model, callback=callback, socketio=socketio ) - if LoLLMSWebUI.__instance is not None: - raise Exception("This class is a singleton!") - else: - LoLLMSWebUI.__instance = self + self.app_name = "LOLLMSWebUI" # Other methods and properties of the LoLLMSWebUI singleton class diff --git a/new_app.py b/new_app.py index 1afda940..12ec9966 100644 --- a/new_app.py +++ b/new_app.py @@ -11,7 +11,7 @@ from fastapi.staticfiles import StaticFiles from lollms.app import LollmsApplication from lollms.paths import LollmsPaths from lollms.main_config import LOLLMSConfig -from lollms_webui import LoLLMSWebUI +from lollms_webui import LOLLMSWebUI from pathlib import Path from ascii_colors import ASCIIColors import socketio @@ -43,7 +43,9 @@ if __name__ == "__main__": if args.port: config.port=args.port - LoLLMSWebUI.build_instance(config=config, lollms_paths=lollms_paths, socketio=sio) - from lollms.server.endpoints.lollms_infos import * + LOLLMSWebUI.build_instance(config=config, lollms_paths=lollms_paths, socketio=sio) + + # Import all endpoints + from lollms.server.endpoints.lollms_infos import router uvicorn.run(app, host=config.host, port=config.port) \ No newline at end of file diff --git a/scripts/linux/linux_install.sh b/scripts/linux/linux_install.sh index 4331b6a2..ed819153 100644 --- a/scripts/linux/linux_install.sh +++ b/scripts/linux/linux_install.sh @@ -3,6 +3,22 @@ # This script will install miniconda and git with all dependencies for this project # This enables a user to install this project without manually installing conda and git. +echo " ___ ___ ___ ___ ___ ___ " +echo " /\__\ /\ \ /\__\ /\__\ /\__\ /\ \ " +echo " /:/ / /::\ \ /:/ / /:/ / /::| | /::\ \ " +echo " /:/ / /:/\:\ \ /:/ / /:/ / /:|:| | /:/\ \ \ " +echo " /:/ / /:/ \:\ \ /:/ / /:/ / /:/|:|__|__ _\:\~\ \ \ " +echo " /:/__/ /:/__/ \:\__\ /:/__/ /:/__/ /:/ |::::\__\ /\ \:\ \ \__\ " +echo " \:\ \ \:\ \ /:/ / \:\ \ \:\ \ \/__/~~/:/ / \:\ \:\ \/__/ " +echo " \:\ \ \:\ /:/ / \:\ \ \:\ \ /:/ / \:\ \:\__\ " +echo " \:\ \ \:\/:/ / \:\ \ \:\ \ /:/ / \:\/:/ / " +echo " \:\__\ \::/ / \:\__\ \:\__\ /:/ / \::/ / " +echo " \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ " +echo "V8.5 (alpha)" +echo "-----------------" +echo "By ParisNeo" +echo "-----------------" + cd "$(dirname "$0")" @@ -19,47 +35,12 @@ if [[ "$PWD" =~ [^#\$\%\&\(\)\*\+\] ]]; then fi - - +export PACKAGES_TO_INSTALL=python=3.11 git read -rp "Press Enter to continue..." clear -echo " ___ ___ ___ ___ ___ ___ " -echo " /\__\ /\ \ /\__\ /\__\ /\__\ /\ \ " -echo " /:/ / /::\ \ /:/ / /:/ / /::| | /::\ \ " -echo " /:/ / /:/\:\ \ /:/ / /:/ / /:|:| | /:/\ \ \ " -echo " /:/ / /:/ \:\ \ /:/ / /:/ / /:/|:|__|__ _\:\~\ \ \ " -echo " /:/__/ /:/__/ \:\__\ /:/__/ /:/__/ /:/ |::::\__\ /\ \:\ \ \__\ " -echo " \:\ \ \:\ \ /:/ / \:\ \ \:\ \ \/__/~~/:/ / \:\ \:\ \/__/ " -echo " \:\ \ \:\ /:/ / \:\ \ \:\ \ /:/ / \:\ \:\__\ " -echo " \:\ \ \:\/:/ / \:\ \ \:\ \ /:/ / \:\/:/ / " -echo " \:\__\ \::/ / \:\__\ \:\__\ /:/ / \::/ / " -echo " \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ " -echo " By ParisNeo" -echo "Please specify if you want to use a GPU or CPU." -echo "*Note* that only NVidea GPUs (cuda) or AMD GPUs (rocm) are supported." -echo "A) Enable Cuda (for nvidia GPUS)" -echo "B) Enable ROCm (for AMD GPUs)" -echo "C) Run CPU mode" -echo -read -rp "Input> " gpuchoice -gpuchoice="${gpuchoice:0:1}" - -if [[ "${gpuchoice^^}" == "A" ]]; then - PACKAGES_TO_INSTALL="python=3.10 cuda-toolkit ninja git gcc" - CHANNEL="-c nvidia/label/cuda-12.1.1 -c nvidia -c conda-forge" -elif [[ "${gpuchoice^^}" == "B" ]]; then - PACKAGES_TO_INSTALL="python=3.10 rocm-comgr rocm-smi ninja git gcc" - CHANNEL=" -c conda-forge" -elif [[ "${gpuchoice^^}" == "C" ]]; then - PACKAGES_TO_INSTALL="python=3.10 ninja git gcc" - CHANNEL="-c conda-forge" -else - echo "Invalid choice. Exiting..." - exit 1 -fi # Better isolation for virtual environment unset CONDA_SHLVL @@ -115,33 +96,28 @@ export CUDA_PATH="$INSTALL_ENV_DIR" if [ -d "lollms-webui" ]; then cd lollms-webui || exit 1 git pull + git submodule update --init --recursive + cd + cd lollms-core + pip install -e . + cd .. + cd utilities\safe_store + pip install -e . + cd ..\.. + else - git clone "$REPO_URL" + git clone --depth 1 --recurse-submodules "$REPO_URL" + git submodule update --init --recursive + cd lollms-webui\lollms_core + pip install -e . + cd .. + cd utilities\safe_store + pip install -e . + cd ..\.. + cd lollms-webui || exit 1 fi -# Initilize all submodules and set them to main branch -echo "Initializing submodules" -git submodule update --init -cd zoos/bindings_zoo -git checkout main -cd ../personalities_zoo -git checkout main -cd ../extensions_zoo -git checkout main -cd ../models_zoo -git checkout main - -cd ../.. - -cd lollms_core -git checkout main - -cd ../utilities/safe_store -git checkout main - -cd ../.. - # Loop through each "git+" requirement and uninstall it (workaround for inconsistent git package updating) while IFS= read -r requirement; do if echo "$requirement" | grep -q "git+"; then @@ -152,8 +128,6 @@ done < requirements.txt # Install the pip requirements python -m pip install -r requirements.txt --upgrade -python -m pip install -e lollms_core --upgrade -python -m pip install -e utilities/safe_store --upgrade if [[ -e "../linux_run.sh" ]]; then @@ -180,12 +154,10 @@ else cp scripts/linux/linux_update_models.sh ../ fi -if [[ "${gpuchoice^^}" == "C" ]]; then - echo "This is a .no_gpu file." > .no_gpu - echo "You have chosen to use only CPU on this system." -else - echo "You have chosen to use GPU on this system." -fi + +cd scripts/python/lollms_installer +python main.py +cd .. PrintBigMessage() { echo diff --git a/scripts/macos/macos_install.sh b/scripts/macos/macos_install.sh index 6d93c0a8..202fc6e4 100644 --- a/scripts/macos/macos_install.sh +++ b/scripts/macos/macos_install.sh @@ -3,6 +3,23 @@ # This script will install Miniconda and git with all dependencies for this project. # This enables a user to install this project without manually installing Conda and git. +echo " ___ ___ ___ ___ ___ ___ " +echo " /\__\ /\ \ /\__\ /\__\ /\__\ /\ \ " +echo " /:/ / /::\ \ /:/ / /:/ / /::| | /::\ \ " +echo " /:/ / /:/\:\ \ /:/ / /:/ / /:|:| | /:/\ \ \ " +echo " /:/ / /:/ \:\ \ /:/ / /:/ / /:/|:|__|__ _\:\~\ \ \ " +echo " /:/__/ /:/__/ \:\__\ /:/__/ /:/__/ /:/ |::::\__\ /\ \:\ \ \__\ " +echo " \:\ \ \:\ \ /:/ / \:\ \ \:\ \ \/__/~~/:/ / \:\ \:\ \/__/ " +echo " \:\ \ \:\ /:/ / \:\ \ \:\ \ /:/ / \:\ \:\__\ " +echo " \:\ \ \:\/:/ / \:\ \ \:\ \ /:/ / \:\/:/ / " +echo " \:\__\ \::/ / \:\__\ \:\__\ /:/ / \::/ / " +echo " \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ " +echo "V8.5 (alpha)" +echo "-----------------" +echo "By ParisNeo" +echo "-----------------" + + cd "$(dirname "$0")" if [[ "$PWD" == *" "* ]]; then @@ -21,37 +38,8 @@ read -rp "Press Enter to continue..." clear -echo " ___ ___ ___ ___ ___ ___ " -echo " /\__\ /\ \ /\__\ /\__\ /\__\ /\ \ " -echo " /:/ / /::\ \ /:/ / /:/ / /::| | /::\ \ " -echo " /:/ / /:/\:\ \ /:/ / /:/ / /:|:| | /:/\ \ \ " -echo " /:/ / /:/ \:\ \ /:/ / /:/ / /:/|:|__|__ _\:\~\ \ \ " -echo " /:/__/ /:/__/ \:\__\ /:/__/ /:/__/ /:/ |::::\__\ /\ \:\ \ \__\ " -echo " \:\ \ \:\ \ /:/ / \:\ \ \:\ \ \/__/~~/:/ / \:\ \:\ \/__/ " -echo " \:\ \ \:\ /:/ / \:\ \ \:\ \ /:/ / \:\ \:\__\ " -echo " \:\ \ \:\/:/ / \:\ \ \:\ \ /:/ / \:\/:/ / " -echo " \:\__\ \::/ / \:\__\ \:\__\ /:/ / \::/ / " -echo " \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ " -echo " By ParisNeo" -echo "Please specify if you want to use a GPU or CPU." -echo "*Note* that only NVidea GPUs (cuda) or AMD GPUs (rocm) are supported." -echo "A) Enable GPU" -echo "B) Run CPU mode" -echo -read -rp "Input> " gpuchoice -gpuchoice="${gpuchoice:0:1}" -uppercase_gpuchoice=$(echo "$gpuchoice" | tr '[:lower:]' '[:upper:]') -if [[ "$uppercase_gpuchoice" == "A" ]]; then - PACKAGES_TO_INSTALL="python=3.10 cuda-toolkit ninja git" - CHANNEL="-c nvidia/label/cuda-12.1.1 -c nvidia -c conda-forge" -elif [[ "$uppercase_gpuchoice" == "B" ]]; then - PACKAGES_TO_INSTALL="python=3.10 ninja git" - CHANNEL="-c conda-forge" -else - echo "Invalid choice. Exiting..." - exit 1 -fi +export PACKAGES_TO_INSTALL=python=3.11 git echo "Installing gcc..." brew install gcc @@ -67,7 +55,14 @@ export TMP="$PWD/installer_files/temp" MINICONDA_DIR="$PWD/installer_files/miniconda3" INSTALL_ENV_DIR="$PWD/installer_files/lollms_env" ENV_NAME="lollms" -MINICONDA_DOWNLOAD_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh" + +arch=$(uname -m) +if [ "$arch" == "arm64" ]; then + MINICONDA_DOWNLOAD_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh" +else + MINICONDA_DOWNLOAD_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh" +fi + REPO_URL="https://github.com/ParisNeo/lollms-webui.git" if [ ! -f "$MINICONDA_DIR/Scripts/conda" ]; then @@ -108,34 +103,28 @@ export CUDA_PATH="$INSTALL_ENV_DIR" if [ -d "lollms-webui" ]; then cd lollms-webui || exit 1 git pull + git submodule update --init --recursive + cd + cd lollms-core + pip install -e . + cd .. + cd utilities\safe_store + pip install -e . + cd ..\.. + else - git clone "$REPO_URL" + git clone --depth 1 --recurse-submodules "$REPO_URL" + git submodule update --init --recursive + cd lollms-webui\lollms_core + pip install -e . + cd .. + cd utilities\safe_store + pip install -e . + cd ..\.. + cd lollms-webui || exit 1 fi -# Initilize all submodules and set them to main branch -echo "Initializing submodules" -git submodule update --init -cd zoos/bindings_zoo -git checkout main -cd ../personalities_zoo -git checkout main -cd ../extensions_zoo -git checkout main -cd ../models_zoo -git checkout main - -cd ../.. - -cd lollms_core -git checkout main - -cd ../utilities/safe_store -git checkout main - -cd ../.. - - # Loop through each "git+" requirement and uninstall it (workaround for inconsistent git package updating) while IFS= read -r requirement; do if echo "$requirement" | grep -q "git+"; then @@ -147,10 +136,6 @@ done < requirements.txt # Install the pip requirements python -m pip install -r requirements.txt --upgrade -python -m pip install -e lollms_core --upgrade - -python -m pip install -e utilities/safe_store --upgrade - if [[ -e "../macos_run.sh" ]]; then echo "Macos run found" else @@ -163,13 +148,17 @@ else cp scripts/macos/macos_update.sh ../ fi -uppercase_gpuchoice=$(echo "$gpuchoice" | tr '[:lower:]' '[:upper:]') -if [[ "$uppercase_gpuchoice" == "B" ]]; then - echo "This is a .no_gpu file." > .no_gpu +if [[ -e "../macos_conda_session.sh" ]]; then + echo "Macos conda session found" else - echo "GPU is enabled, no .no_gpu file will be created." + cp scripts/macos/macos_conda_session.sh ../ fi + +cd scripts/python/lollms_installer +python main.py +cd .. + PrintBigMessage() { echo echo "*******************************************************************" diff --git a/scripts/python/lollms_installer/frontend/src/views/Install.vue b/scripts/python/lollms_installer/frontend/src/views/Install.vue index 7b05faa8..f40b396d 100644 --- a/scripts/python/lollms_installer/frontend/src/views/Install.vue +++ b/scripts/python/lollms_installer/frontend/src/views/Install.vue @@ -4,24 +4,40 @@

LOLLMS installation tool

Welcome to the installer of lollms. Here you can select your install profile.
- Let's start by selecting the install mode.

+ Let's start by selecting the hardware.

- + + + + +