diff --git a/README.md b/README.md index 8054d5c..35c802c 100644 --- a/README.md +++ b/README.md @@ -23,26 +23,16 @@ SUPPORT SERVER FOR BOT SETUP: https://discord.gg/WvAHXDMS7Q (You can try out the

# Recent Notable Updates -- **Translations with DeepL** - DeepL integration for translations. `/translate` - - -- **Context menu commands** - Allow people to prompt GPT and DALL-E directly by right clicking a message: -
-
- - -- **AI-BASED SERVER MODERATION** - GPT3Discord now has a built-in AI-based moderation system that can automatically detect and remove toxic messages from your server. This is a great way to keep your server safe and clean, and it's completely automatic and **free**! Check out the commands section to learn how to enable it! - - -- **Permanent memory with embeddings and Pinecone finished!** - An initial alpha version of permanent memory is now done! This allows you to chat with GPT3 infinitely and accurately, and save tokens, by using embeddings. *Please read the Permanent Memory section for more information!* - +- **CUSTOM INDEXES** - This is a huge update. You can now upload files to your server and use them as custom context when asking GPT3 questions. You can also use links to use webpages as context, and you can even use discord channels, or your entire discord server's messages as context! Read more in the 'Custom Indexes' section below. # Features - **Directly prompt GPT3 with `/gpt ask `** - **Have long term, permanent conversations with the bot, just like chatgpt, with `/gpt converse`** - Conversations happen in threads that get automatically cleaned up! +- **Custom Indexes** - Use your own files, pdfs, txt files, websites, discord channel content as context when asking GPT3 questions! + - **DALL-E Image Generation** - Generate DALL-E AI images right in discord with `/dalle draw `! It even supports multiple image qualities, multiple images, creating image variants, retrying, and saving images. - **DALL-E Image Prompt Optimization** - Given some text that you're trying to generate an image for, the bot will automatically optimize the text to be more DALL-E friendly! `/dalle optimize ` @@ -105,6 +95,10 @@ These commands are grouped, so each group has a prefix but you can easily tab co `/dalle optimize ` Optimize a given prompt text for DALL-E image generation. +### Custom Indexes Commands + +TODO + ### System and Settings `/system settings` - Display settings for the model (temperature, top_p, etc) @@ -121,6 +115,10 @@ These commands are grouped, so each group has a prefix but you can easily tab co `/system clear-local` - Clear all the local dalleimages. +### Custom Indexes + +TODO + ### Automatic AI Moderation `/mod set status:on` - Turn on automatic chat moderations. diff --git a/cogs/commands.py b/cogs/commands.py index 0b00dd0..6650b6b 100644 --- a/cogs/commands.py +++ b/cogs/commands.py @@ -71,9 +71,9 @@ class Commands(discord.Cog, name="Commands"): ) index = discord.SlashCommandGroup( name="index", - description="gpt-index commands", + description="Custom index commands for the bot", guild_ids=ALLOWED_GUILDS, - checks=[Check.check_gpt_roles()], + checks=[Check.check_index_roles()], ) # diff --git a/gpt3discord.py b/gpt3discord.py index 38034a8..41e99d5 100644 --- a/gpt3discord.py +++ b/gpt3discord.py @@ -69,7 +69,7 @@ if PINECONE_TOKEN: and EnvService.get_google_search_engine_id() ): if PINECONE_INDEX_SEARCH not in pinecone.list_indexes(): - print("Creating pinecone index for seraches. Please wait...") + print("Creating pinecone index for searches. Please wait...") pinecone.create_index( PINECONE_INDEX_SEARCH, dimension=1536, diff --git a/models/check_model.py b/models/check_model.py index b7ebd77..de63e3e 100644 --- a/models/check_model.py +++ b/models/check_model.py @@ -6,6 +6,7 @@ from typing import Callable ADMIN_ROLES = EnvService.get_admin_roles() DALLE_ROLES = EnvService.get_dalle_roles() GPT_ROLES = EnvService.get_gpt_roles() +INDEX_ROLES = EnvService.get_index_roles() TRANSLATOR_ROLES = EnvService.get_translator_roles() ALLOWED_GUILDS = EnvService.get_allowed_guilds() @@ -63,6 +64,23 @@ class Check: return inner + @staticmethod + def check_index_roles() -> Callable: + async def inner(ctx: discord.ApplicationContext): + if INDEX_ROLES == [None]: + return True + if not any(role.name.lower() in INDEX_ROLES for role in ctx.user.roles): + await ctx.defer(ephemeral=True) + await ctx.respond( + f"You don't have permission, list of roles is {INDEX_ROLES}", + ephemeral=True, + delete_after=10, + ) + return False + return True + + return inner + @staticmethod def check_translator_roles() -> Callable: async def inner(ctx: discord.ApplicationContext): diff --git a/models/index_model.py b/models/index_model.py index 8c3880e..0f5bae0 100644 --- a/models/index_model.py +++ b/models/index_model.py @@ -48,8 +48,7 @@ class Index_handler: documents = BeautifulSoupWebReader(website_extractor=DEFAULT_WEBSITE_EXTRACTOR).load_data(urls=[url]) index = GPTSimpleVectorIndex(documents) return index - - + async def set_file_index(self, ctx: discord.ApplicationContext, file: discord.Attachment, user_api_key): if not user_api_key: os.environ["OPENAI_API_KEY"] = self.openai_key diff --git a/services/environment_service.py b/services/environment_service.py index ad098fd..e60a315 100644 --- a/services/environment_service.py +++ b/services/environment_service.py @@ -191,6 +191,32 @@ class EnvService: ) return gpt_roles + @staticmethod + def get_index_roles(): + # GPT_ROLES is a comma separated list of string roles + # It can also just be one role + # Read these allowed roles and return as a list of strings + try: + index_roles = os.getenv("INDEX_ROLES") + except Exception: + index_roles = None + + if index_roles is None: + print( + "INDEX_ROLES is not defined properly in the environment file!" + "Please copy your server's role and put it into INDEX_ROLES in the .env file." + 'For example a line should look like: `INDEX_ROLES="Gpt"`' + ) + print("Defaulting to allowing all users to use Index commands...") + return [None] + + index_roles = ( + index_roles.lower().strip().split(",") + if "," in index_roles + else [index_roles.lower()] + ) + return index_roles + @staticmethod def get_welcome_message(): # WELCOME_MESSAGE is a default string used to welcome new members to the server if GPT3 is not available.