From 0f5b86b2eee9e749e6a84b7db217f6fd710ffaa8 Mon Sep 17 00:00:00 2001 From: Kaveen Kumarasinghe Date: Fri, 24 Feb 2023 20:00:40 -0500 Subject: [PATCH] format --- cogs/commands.py | 25 +++++++++++++------------ cogs/index_service_cog.py | 35 +++++++++++++++++++++++++++-------- models/index_model.py | 19 +++++++++++++------ sample.env | 14 +++++++------- 4 files changed, 60 insertions(+), 33 deletions(-) diff --git a/cogs/commands.py b/cogs/commands.py index 58f42b1..6f7f647 100644 --- a/cogs/commands.py +++ b/cogs/commands.py @@ -549,9 +549,7 @@ class Commands(discord.Cog, name="Commands"): new_name: str, ): await ctx.defer() - await self.index_cog.rename_user_index_command( - ctx, user_index, new_name - ) + await self.index_cog.rename_user_index_command(ctx, user_index, new_name) @add_to_group("index") @discord.slash_command( @@ -579,9 +577,7 @@ class Commands(discord.Cog, name="Commands"): new_name: str, ): await ctx.defer() - await self.index_cog.rename_server_index_command( - ctx, server_index, new_name - ) + await self.index_cog.rename_server_index_command(ctx, server_index, new_name) @add_to_group("index") @discord.slash_command( @@ -609,9 +605,7 @@ class Commands(discord.Cog, name="Commands"): new_name: str, ): await ctx.defer() - await self.index_cog.rename_search_index_command( - ctx, search_index, new_name - ) + await self.index_cog.rename_search_index_command(ctx, search_index, new_name) @add_to_group("index") @discord.slash_command( @@ -718,9 +712,14 @@ class Commands(discord.Cog, name="Commands"): input_type=discord.SlashCommandOptionType.integer, ) async def set_discord( - self, ctx: discord.ApplicationContext, channel: discord.TextChannel, message_limit: int + self, + ctx: discord.ApplicationContext, + channel: discord.TextChannel, + message_limit: int, ): - await self.index_cog.set_discord_command(ctx, channel, message_limit=message_limit) + await self.index_cog.set_discord_command( + ctx, channel, message_limit=message_limit + ) @add_to_group("index") @discord.slash_command( @@ -780,7 +779,9 @@ class Commands(discord.Cog, name="Commands"): child_branch_factor: int, ): await ctx.defer() - await self.index_cog.query_command(ctx, query, nodes, response_mode, child_branch_factor) + await self.index_cog.query_command( + ctx, query, nodes, response_mode, child_branch_factor + ) # # DALLE commands diff --git a/cogs/index_service_cog.py b/cogs/index_service_cog.py index 967f920..0656206 100644 --- a/cogs/index_service_cog.py +++ b/cogs/index_service_cog.py @@ -32,7 +32,11 @@ class IndexService(discord.Cog, name="IndexService"): await ctx.respond("Please provide a new name for this index") return - if await self.index_handler.rename_index(ctx, f"indexes/{ctx.user.id}/{user_index}", f"indexes/{ctx.user.id}/{new_name}"): + if await self.index_handler.rename_index( + ctx, + f"indexes/{ctx.user.id}/{user_index}", + f"indexes/{ctx.user.id}/{new_name}", + ): await ctx.respond(f"Your index has been renamed to `{new_name}`") else: await ctx.respond("Something went wrong while renaming your index") @@ -44,18 +48,25 @@ class IndexService(discord.Cog, name="IndexService"): await ctx.respond("Please provide a new name for this index") return - if await self.index_handler.rename_index(ctx, f"indexes/{ctx.guild.id}/{server_index}", f"indexes/{ctx.guild.id}/{new_name}"): + if await self.index_handler.rename_index( + ctx, + f"indexes/{ctx.guild.id}/{server_index}", + f"indexes/{ctx.guild.id}/{new_name}", + ): await ctx.respond(f"Your index has been renamed to `{new_name}`") else: await ctx.respond("Something went wrong while renaming your index") async def rename_search_index_command(self, ctx, search_index, new_name): - if not new_name: await ctx.respond("Please provide a new name for this index") return - if await self.index_handler.rename_index(ctx, f"indexes/{ctx.user.id}_search/{search_index}", f"indexes/{ctx.user.id}_search/{new_name}"): + if await self.index_handler.rename_index( + ctx, + f"indexes/{ctx.user.id}_search/{search_index}", + f"indexes/{ctx.user.id}_search/{new_name}", + ): await ctx.respond(f"Your index has been renamed to `{new_name}`") else: await ctx.respond("Something went wrong while renaming your index") @@ -92,7 +103,9 @@ class IndexService(discord.Cog, name="IndexService"): ctx, link, user_api_key=user_api_key ) - async def set_discord_command(self, ctx, channel: discord.TextChannel = None, message_limit: int = 2500): + async def set_discord_command( + self, ctx, channel: discord.TextChannel = None, message_limit: int = 2500 + ): """Command handler to set a channel as your personal index""" await ctx.defer() @@ -130,7 +143,9 @@ class IndexService(discord.Cog, name="IndexService"): ) if not user_api_key: return - await self.index_handler.backup_discord(ctx, user_api_key=user_api_key, message_limit=message_limit) + await self.index_handler.backup_discord( + ctx, user_api_key=user_api_key, message_limit=message_limit + ) async def load_index_command(self, ctx, user_index, server_index, search_index): """Command handler to load indexes""" @@ -173,7 +188,9 @@ class IndexService(discord.Cog, name="IndexService"): return await self.index_handler.load_index(ctx, index, server, search, user_api_key) - async def query_command(self, ctx, query, nodes, response_mode, child_branch_factor): + async def query_command( + self, ctx, query, nodes, response_mode, child_branch_factor + ): """Command handler to query your index""" user_api_key = None @@ -189,7 +206,9 @@ class IndexService(discord.Cog, name="IndexService"): if await Moderation.simple_moderate_and_respond(query, ctx): return - await self.index_handler.query(ctx, query, response_mode, nodes, user_api_key, child_branch_factor) + await self.index_handler.query( + ctx, query, response_mode, nodes, user_api_key, child_branch_factor + ) async def compose_command(self, ctx, name): """Command handler to compose from your index""" diff --git a/models/index_model.py b/models/index_model.py index 390eb15..087daa0 100644 --- a/models/index_model.py +++ b/models/index_model.py @@ -48,7 +48,14 @@ SHORT_TO_LONG_CACHE = {} def get_and_query( - user_id, index_storage, query, response_mode, nodes, llm_predictor, embed_model, child_branch_factor + user_id, + index_storage, + query, + response_mode, + nodes, + llm_predictor, + embed_model, + child_branch_factor, ): index: [GPTSimpleVectorIndex, ComposableGraph] = index_storage[ user_id @@ -147,9 +154,7 @@ class Index_handler: async def rename_index(self, ctx, original_path, rename_path): """Command handler to rename a user index""" - index_file = EnvService.find_shared_file( - original_path - ) + index_file = EnvService.find_shared_file(original_path) if not index_file: return False @@ -595,7 +600,9 @@ class Index_handler: simple_index.save_to_disk(f"indexes/{user_id}/{name}.json") self.index_storage[user_id].queryable_index = simple_index - async def backup_discord(self, ctx: discord.ApplicationContext, user_api_key, message_limit): + async def backup_discord( + self, ctx: discord.ApplicationContext, user_api_key, message_limit + ): if not user_api_key: os.environ["OPENAI_API_KEY"] = self.openai_key else: @@ -659,7 +666,7 @@ class Index_handler: nodes, llm_predictor, embedding_model, - child_branch_factor + child_branch_factor, ), ) print("The last token usage was ", llm_predictor.last_token_usage) diff --git a/sample.env b/sample.env index 97a208e..0b21bfa 100644 --- a/sample.env +++ b/sample.env @@ -2,11 +2,11 @@ OPENAI_TOKEN = "" DISCORD_TOKEN = "" -#PINECONE_TOKEN = "" # pinecone token if you have it enabled. See readme -#PINECONE_REGION = "" # add your region here if it's not us-west1-gcp -#GOOGLE_SEARCH_API_KEY: "" -#GOOGLE_SEARCH_ENGINE_ID: "" -#DEEPL_TOKEN: "" +# PINECONE_TOKEN = "" # pinecone token if you have it enabled. See readme +# PINECONE_REGION = "" # add your region here if it's not us-west1-gcp +# GOOGLE_SEARCH_API_KEY: "" +# GOOGLE_SEARCH_ENGINE_ID: "" +# DEEPL_TOKEN: "" DEBUG_GUILD = "974519864045756446" # discord_server_id DEBUG_CHANNEL = "977697652147892304" # discord_chanel_id @@ -29,7 +29,7 @@ SEARCH_ROLES: "Admin,Owner" CUSTOM_BOT_NAME: "GPT3Discord" # If True, users must use their own API keys for OpenAI. If False, the bot will use the API key in the .env file. -USER_INPUT_API_KEYS="False" +USER_INPUT_API_KEYS = "False" # Moderations Service alert channel, this is where moderation alerts will be sent as a default if enabled MODERATIONS_ALERT_CHANNEL = "977697652147892304" @@ -44,4 +44,4 @@ PRE_MODERATE = "False" FORCE_ENGLISH = "False" # The welcome message to send it the welcome setting is set to true -WELCOME_MESSAGE = "Hi There! Welcome to our Discord server. We hope you'll enjoy our server and we look forward to engaging with you!" # This is a fallback message if gpt3 fails to generate a welcome message. \ No newline at end of file +WELCOME_MESSAGE = "Hi There! Welcome to our Discord server. We hope you'll enjoy our server and we look forward to engaging with you!" # This is a fallback message if gpt3 fails to generate a welcome message.