diff --git a/api/__init__.py b/api/__init__.py index e6c1511c..37fb84cd 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -484,9 +484,12 @@ class LoLLMsAPPI(): self._message_id = 0 self.db_path = config["db_path"] - - # Create database object - self.db = DiscussionsDB(self.db_path) + if Path(self.db_path).is_absolute(): + # Create database object + self.db = DiscussionsDB(self.db_path) + else: + # Create database object + self.db = DiscussionsDB(self.lollms_paths.personal_path/"databases"/self.db_path) # If the database is empty, populate it with tables self.db.populate() diff --git a/api/db.py b/api/db.py index bfe99e53..3fef443a 100644 --- a/api/db.py +++ b/api/db.py @@ -1,6 +1,6 @@ import sqlite3 - +from pathlib import Path __author__ = "parisneo" __github__ = "https://github.com/ParisNeo/lollms-webui" __copyright__ = "Copyright 2023, " @@ -13,7 +13,8 @@ class DiscussionsDB: MSG_TYPE_CONDITIONNING = 1 def __init__(self, db_path="database.db"): - self.db_path = db_path + self.db_path = Path(db_path) + self.db_path .parent.mkdir(exist_ok=True, parents= True) def populate(self): """ diff --git a/app.py b/app.py index db610c36..8e564f25 100644 --- a/app.py +++ b/app.py @@ -25,7 +25,7 @@ from tqdm import tqdm import subprocess import signal from lollms.personality import AIPersonality, MSG_TYPE -from lollms.helpers import ASCIIColors +from lollms.helpers import ASCIIColors, BaseConfig from lollms.paths import LollmsPaths from api.db import DiscussionsDB, Discussion from api.helpers import compare_lists @@ -87,6 +87,12 @@ class LoLLMsWebUI(LoLLMsAPPI): # ========================================================================================= # Endpoints # ========================================================================================= + + + + + self.add_endpoint("/switch_personal_path", "switch_personal_path", self.switch_personal_path, methods=["POST"]) + self.add_endpoint("/add_reference_to_local_model", "add_reference_to_local_model", self.add_reference_to_local_model, methods=["POST"]) self.add_endpoint("/send_file", "send_file", self.send_file, methods=["POST"]) @@ -689,6 +695,22 @@ class LoLLMsWebUI(LoLLMsAPPI): self.process.cancel_generation() return jsonify({"status": True}) + + def switch_personal_path(self): + data = request.get_json() + path = data["path"] + global_paths_cfg = Path("./global_paths_cfg.yaml") + if global_paths_cfg.exists(): + try: + cfg = BaseConfig() + cfg.load_config(global_paths_cfg) + cfg.lollms_personal_path = path + cfg.save_config(global_paths_cfg) + return jsonify({"status": True}) + except Exception as ex: + print(ex) + return jsonify({"status": False, 'error':f"Couldn't switch path: {ex}"}) + def add_reference_to_local_model(self): data = request.get_json() path = data["path"] @@ -1087,6 +1109,8 @@ def sync_cfg(default_config, config): if __name__ == "__main__": lollms_paths = LollmsPaths.find_paths(force_local=True) + db_folder = lollms_paths.personal_path/"databases" + db_folder.mkdir(parents=True, exist_ok=True) parser = argparse.ArgumentParser(description="Start the chatbot Flask app.") parser.add_argument( "-c", "--config", type=str, default="local_config", help="Sets the configuration file to be used." diff --git a/configs/config.yaml b/configs/config.yaml index 663650d5..6b4fe33e 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -28,4 +28,4 @@ user_name: user # UI parameters debug: False -db_path: databases/database.db \ No newline at end of file +db_path: database.db \ No newline at end of file