Role checks

Kaveen Kumarasinghe 2 years ago
parent e63c6227dd
commit c7e6a447d3

@ -23,26 +23,16 @@ SUPPORT SERVER FOR BOT SETUP: https://discord.gg/WvAHXDMS7Q (You can try out the
</p>
# 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:
<center>
<img src="https://i.imgur.com/fkfnJQ0.png"/></center>
- **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 <a href="https://www.pinecone.io/">Pinecone</a> 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 <prompt>`**
- **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 <prompt>`! 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 <prompt>`
@ -105,6 +95,10 @@ These commands are grouped, so each group has a prefix but you can easily tab co
`/dalle optimize <image prompt text>` 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.

@ -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()],
)
#

@ -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,

@ -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):

@ -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

@ -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.

Loading…
Cancel
Save