Kaveen Kumarasinghe 1 year ago
parent 9487a475fa
commit 0f5b86b2ee

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

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

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

@ -2,11 +2,11 @@
OPENAI_TOKEN = "<openai_api_token>"
DISCORD_TOKEN = "<discord_bot_token>"
#PINECONE_TOKEN = "<pinecone_token>" # pinecone token if you have it enabled. See readme
#PINECONE_REGION = "<pinecone_region>" # add your region here if it's not us-west1-gcp
#GOOGLE_SEARCH_API_KEY: "<google_api_key>"
#GOOGLE_SEARCH_ENGINE_ID: "<google_engine_id>"
#DEEPL_TOKEN: "<deepl_token>"
# PINECONE_TOKEN = "<pinecone_token>" # pinecone token if you have it enabled. See readme
# PINECONE_REGION = "<pinecone_region>" # add your region here if it's not us-west1-gcp
# GOOGLE_SEARCH_API_KEY: "<google_api_key>"
# GOOGLE_SEARCH_ENGINE_ID: "<google_engine_id>"
# DEEPL_TOKEN: "<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.
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.

Loading…
Cancel
Save