From c1b94f42151a612e6abec1cfa900174037c13fd1 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 30 Oct 2023 10:45:21 +0100 Subject: [PATCH] discord bot is ready --- .../.gitignore | 0 .../{discord_server => discord_bot}/README.md | 0 .../__init__.py | 65 ++++++++++--------- lollms/apps/settings/__init__.py | 4 +- setup.py | 3 +- 5 files changed, 40 insertions(+), 32 deletions(-) rename lollms/apps/{discord_server => discord_bot}/.gitignore (100%) rename lollms/apps/{discord_server => discord_bot}/README.md (100%) rename lollms/apps/{discord_server => discord_bot}/__init__.py (80%) diff --git a/lollms/apps/discord_server/.gitignore b/lollms/apps/discord_bot/.gitignore similarity index 100% rename from lollms/apps/discord_server/.gitignore rename to lollms/apps/discord_bot/.gitignore diff --git a/lollms/apps/discord_server/README.md b/lollms/apps/discord_bot/README.md similarity index 100% rename from lollms/apps/discord_server/README.md rename to lollms/apps/discord_bot/README.md diff --git a/lollms/apps/discord_server/__init__.py b/lollms/apps/discord_bot/__init__.py similarity index 80% rename from lollms/apps/discord_server/__init__.py rename to lollms/apps/discord_bot/__init__.py index 365ce1c..4d56367 100644 --- a/lollms/apps/discord_server/__init__.py +++ b/lollms/apps/discord_bot/__init__.py @@ -8,30 +8,7 @@ from pathlib import Path from ascii_colors import ASCIIColors from safe_store import TextVectorizer, GenericDataLoader, VisualizationMethod, VectorizationMethod -current_path = Path(__file__).resolve().parent -config_path = current_path / 'discord_config.yaml' -data_folder = current_path / "data" -data_folder.mkdir(parents=True, exist_ok=True) -text_vectorzer = TextVectorizer( - database_path=data_folder / "db.json", - vectorization_method=VectorizationMethod.TFIDF_VECTORIZER, - save_db=True -) -files = [f for f in data_folder.iterdir() if f.suffix in [".txt", ".md", ".pdf"]] -for f in files: - txt = GenericDataLoader.read_file(f) - text_vectorzer.add_document(f, txt, 512, 128, False) -text_vectorzer.index() - -if not config_path.exists(): - bot_token = input("Please enter your bot token: ") - config = {'bot_token': bot_token} - with open(config_path, 'w') as config_file: - yaml.safe_dump(config, config_file) -else: - with open(config_path, 'r') as config_file: - config = yaml.safe_load(config_file) - bot_token = config['bot_token'] +contexts={} client = commands.Bot(command_prefix='!', intents=discord.Intents.all()) @@ -39,6 +16,34 @@ lollms_paths = LollmsPaths.find_paths(force_local=False, tool_prefix="lollms_dis config = LOLLMSConfig.autoload(lollms_paths) lollms_app = LollmsApplication("lollms_bot", config=config, lollms_paths=lollms_paths) +current_path = Path(__file__).resolve().parent +root_config_path = lollms_app.lollms_paths.personal_configuration_path / "discord_bot" +root_config_path.mkdir(parents=True, exist_ok=True) + +root_data_path = lollms_app.lollms_paths.personal_data_path / "discord_bot" +root_data_path.mkdir(parents=True, exist_ok=True) + +config_path = root_config_path / 'config.yaml' +text_vectorzer = TextVectorizer( + database_path=root_data_path / "db.json", + vectorization_method=VectorizationMethod.TFIDF_VECTORIZER, + save_db=True +) +files = [f for f in root_data_path.iterdir() if f.suffix in [".txt", ".md", ".pdf"]] +for f in files: + txt = GenericDataLoader.read_file(f) + text_vectorzer.add_document(f, txt, 512, 128, False) +text_vectorzer.index() + +if not config_path.exists(): + bot_token = input("Please enter your bot token: ") + config = {'bot_token': bot_token, "summoning_word":"!lollms"} + with open(config_path, 'w') as config_file: + yaml.safe_dump(config, config_file) +else: + with open(config_path, 'r') as config_file: + config = yaml.safe_load(config_file) + bot_token = config['bot_token'] @client.event async def on_ready(): @@ -55,17 +60,19 @@ async def on_member_join(member): async def on_message(message): if message.author == client.user: return - if message.content.startswith('!lollms'): - prompt = message.content[6:] + if message.content.startswith(config["summoning_word"]): + prompt = message.content[len(config["summoning_word"]):] print("Chatting") - docs, _ = text_vectorzer.recover_text(prompt,3) - docs = '\n'.join(docs) + try: + docs, _ = text_vectorzer.recover_text(prompt,3) + docs = "!#>Documentation:\n"+'\n'.join(docs) + except: + docs="" context = f"""!#>instruction: {lollms_app.personality.personality_conditioning} !#>Informations: Current model:{lollms_app.config.model_name} Current personality:{lollms_app.personality.name} -!#>Documentation: {docs} !#>{message.author.id}: {prompt} !#>{lollms_app.personality.ai_message_prefix}: """ diff --git a/lollms/apps/settings/__init__.py b/lollms/apps/settings/__init__.py index a2f4d4d..45377ce 100644 --- a/lollms/apps/settings/__init__.py +++ b/lollms/apps/settings/__init__.py @@ -158,7 +158,7 @@ Participating personalities: def main(): # Create the argument parser - parser = argparse.ArgumentParser(description='App Description') + parser = argparse.ArgumentParser(description='The lollms-settings app is used to configure multiple aspects of the lollms project. Lollms is a multi bindings LLM service that serves multiple LLM models that can generate text out of a prompt.') # Add the configuration path argument parser.add_argument('--configuration_path', default=None, @@ -170,7 +170,7 @@ def main(): parser.add_argument('--default_cfg_path', type=str, default=None, help='Reset all installation status') - parser.add_argument('--tool_prefix', type=str, default="lollms_server_", help='A prefix to define what tool is being used (default lollms_server)') + parser.add_argument('--tool_prefix', type=str, default="lollms_server_", help='A prefix to define what tool is being used (default lollms_server_)\nlollms applications prefixes:\n lollms server: lollms_server_\nlollms-elf: lollms_elf_\nlollms-webui: ""\nlollms-discord-bot: lollms_discord_') parser.add_argument('--set_personal_folder_path', type=str, default=None, help='Forces installing and selecting a specific binding') parser.add_argument('--install_binding', type=str, default=None, help='Forces installing and selecting a specific binding') parser.add_argument('--install_model', type=str, default=None, help='Forces installing and selecting a specific model') diff --git a/setup.py b/setup.py index f87a4c5..be086d7 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def get_all_files(path): setuptools.setup( name="lollms", - version="5.9.5", + version="6.0.0", author="Saifeddine ALOUI", author_email="aloui.saifeddine@gmail.com", description="A python library for AI personality definition", @@ -42,6 +42,7 @@ setuptools.setup( 'lollms-server = lollms.apps.server:main', 'lollms-console = lollms.apps.console:main', 'lollms-settings = lollms.apps.settings:main', + 'lollms-discord = lollms.apps.discord_bot:main', 'lollms-playground = lollms.apps.playground:main' ], },