From 1accdb2f273e4a80b9310648d03faa01aee86cf3 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Sun, 26 Nov 2023 02:32:24 +0100 Subject: [PATCH] Enhanced --- lollms/configs/config.yaml | 3 ++- lollms/personality.py | 13 ++++++++++++- lollms/utilities.py | 22 +++++++++++++++++++++- requirements.txt | 2 ++ requirements_dev.txt | 4 +++- setup.py | 2 +- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lollms/configs/config.yaml b/lollms/configs/config.yaml index ca8d5ad..c164e41 100644 --- a/lollms/configs/config.yaml +++ b/lollms/configs/config.yaml @@ -1,5 +1,5 @@ # =================== Lord Of Large Language Models Configuration file =========================== -version: 27 +version: 28 binding_name: null model_name: null @@ -43,6 +43,7 @@ db_path: database.db debug: False auto_update: true auto_save: true +auto_title: false # Enables gpu usage enable_gpu: true # Automatically open the browser diff --git a/lollms/personality.py b/lollms/personality.py index d0c4bb4..ce8b093 100644 --- a/lollms/personality.py +++ b/lollms/personality.py @@ -12,7 +12,7 @@ from lollms.config import InstallOption, TypedConfig, BaseConfig from lollms.main_config import LOLLMSConfig from lollms.paths import LollmsPaths from lollms.binding import LLMBinding -from lollms.utilities import PromptReshaper +from lollms.utilities import PromptReshaper, PackageManager import pkg_resources from pathlib import Path from PIL import Image @@ -1576,6 +1576,17 @@ class APScript(StateMachine): if callback: callback(full_text, MSG_TYPE.MSG_TYPE_FULL_INVISIBLE_TO_USER) + def build_python_code(self, prompt, max_title_length=4096): + if not PackageManager.check_package_installed("autopep8"): + PackageManager.install_package("autopep8") + import autopep8 + global_prompt = f"{prompt}\n##>Code Builder:```python\n" + code = self.fast_gen(global_prompt,max_title_length) + code = code.rstrip("`") # Remove trailing backticks + formatted_code = autopep8.fix_code(code) # Fix indentation errors + return formatted_code + + def make_title(self, prompt, max_title_length: int = 50): """ Generates a title for a given prompt. diff --git a/lollms/utilities.py b/lollms/utilities.py index 3a41b85..fd4b244 100644 --- a/lollms/utilities.py +++ b/lollms/utilities.py @@ -23,7 +23,7 @@ from PIL import Image import requests from io import BytesIO import base64 - +import importlib def load_image(image_file): s_image_file = str(image_file) @@ -350,6 +350,26 @@ class PackageManager: import subprocess import sys subprocess.check_call([sys.executable, "-m", "pip", "install", package_name]) + + @staticmethod + def check_package_installed(package_name): + try: + importlib.import_module(package_name) + return True + except ImportError: + return False + + @staticmethod + def safe_import(module_name, library_name=None): + if not PackageManager.check_package_installed(module_name): + print(f"{module_name} module not found. Installing...") + if library_name: + PackageManager.install_package(library_name) + else: + PackageManager.install_package(module_name) + globals()[module_name] = importlib.import_module(module_name) + print(f"{module_name} module imported successfully.") + class GitManager: @staticmethod diff --git a/requirements.txt b/requirements.txt index 363e084..b7e7534 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,3 +18,5 @@ scikit-learn ascii_colors safe_store ascii_colors>=0.1.3 + +autopep8 diff --git a/requirements_dev.txt b/requirements_dev.txt index 2809c04..7b2d033 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -8,4 +8,6 @@ simple-websocket wget setuptools requests -safe_store \ No newline at end of file +safe_store + +autopep8 \ No newline at end of file diff --git a/setup.py b/setup.py index 095e899..d96e668 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def get_all_files(path): setuptools.setup( name="lollms", - version="6.4.2", + version="6.5.0", author="Saifeddine ALOUI", author_email="aloui.saifeddine@gmail.com", description="A python library for AI personality definition",